mirror of
https://github.com/zitadel/zitadel.git
synced 2025-06-18 09:38:44 +00:00
fix: CORS on assets api (#3659)
This commit is contained in:
parent
a5cea82670
commit
0906c2d513
@ -83,10 +83,10 @@ func NewHandler(commands *command.Commands, verifier *authz.TokenVerifier, authC
|
|||||||
|
|
||||||
verifier.RegisterServer("Assets-API", "assets", AssetsService_AuthMethods)
|
verifier.RegisterServer("Assets-API", "assets", AssetsService_AuthMethods)
|
||||||
router := mux.NewRouter()
|
router := mux.NewRouter()
|
||||||
router.Use(sentryhttp.New(sentryhttp.Options{}).Handle, http_mw.CORSInterceptor, instanceInterceptor)
|
router.Use(sentryhttp.New(sentryhttp.Options{}).Handle, instanceInterceptor)
|
||||||
RegisterRoutes(router, h)
|
RegisterRoutes(router, h)
|
||||||
router.PathPrefix("/{owner}").Methods("GET").HandlerFunc(DownloadHandleFunc(h, h.GetFile()))
|
router.PathPrefix("/{owner}").Methods("GET").HandlerFunc(DownloadHandleFunc(h, h.GetFile()))
|
||||||
return router
|
return http_util.CopyHeadersToContext(http_mw.CORSInterceptor(router))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) GetFile() Downloader {
|
func (h *Handler) GetFile() Downloader {
|
||||||
|
@ -125,7 +125,10 @@ func GetAllPermissionsFromCtx(ctx context.Context) []string {
|
|||||||
func checkOrigin(ctx context.Context, origins []string) error {
|
func checkOrigin(ctx context.Context, origins []string) error {
|
||||||
origin := grpc.GetGatewayHeader(ctx, http_util.Origin)
|
origin := grpc.GetGatewayHeader(ctx, http_util.Origin)
|
||||||
if origin == "" {
|
if origin == "" {
|
||||||
return nil
|
origin = http_util.OriginFromCtx(ctx)
|
||||||
|
if origin == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if http_util.IsOriginAllowed(origins, origin) {
|
if http_util.IsOriginAllowed(origins, origin) {
|
||||||
return nil
|
return nil
|
||||||
|
@ -40,9 +40,9 @@ const (
|
|||||||
|
|
||||||
type key int
|
type key int
|
||||||
|
|
||||||
var (
|
const (
|
||||||
httpHeaders key
|
httpHeaders key = iota
|
||||||
remoteAddr key
|
remoteAddr
|
||||||
)
|
)
|
||||||
|
|
||||||
func CopyHeadersToContext(h http.Handler) http.Handler {
|
func CopyHeadersToContext(h http.Handler) http.Handler {
|
||||||
@ -59,6 +59,14 @@ func HeadersFromCtx(ctx context.Context) (http.Header, bool) {
|
|||||||
return headers, ok
|
return headers, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func OriginFromCtx(ctx context.Context) string {
|
||||||
|
headers, ok := ctx.Value(httpHeaders).(http.Header)
|
||||||
|
if !ok {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return headers.Get(Origin)
|
||||||
|
}
|
||||||
|
|
||||||
func RemoteIPFromCtx(ctx context.Context) string {
|
func RemoteIPFromCtx(ctx context.Context) string {
|
||||||
ctxHeaders, ok := HeadersFromCtx(ctx)
|
ctxHeaders, ok := HeadersFromCtx(ctx)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user