diff --git a/changelog/unreleased/fix-space-manager-signed-url.md b/changelog/unreleased/fix-space-manager-signed-url.md new file mode 100644 index 00000000000..8eadc22097a --- /dev/null +++ b/changelog/unreleased/fix-space-manager-signed-url.md @@ -0,0 +1,15 @@ +Bugfix: Fix space management middleware removing users from spaces on download + +The space management middleware ran on every authenticated request, including +signed URL requests used for file downloads. Since signed URL auth does not +carry OIDC claims, the middleware interpreted the absence of claims as "user +should have no space access" and removed the user from all project spaces. +On the next OIDC request the user was re-added, causing an oscillating +add/remove cycle that led to intermittent download failures and transient +"space not found" errors. + +The middleware now skips reconciliation entirely when no OIDC claims are +present in the request context. + +https://github.com/owncloud/ocis/pull/12285 +https://github.com/owncloud/ocis/issues/12285 diff --git a/services/proxy/pkg/middleware/space_manager.go b/services/proxy/pkg/middleware/space_manager.go index 1f6a52a72e4..ac9cf5a2d21 100644 --- a/services/proxy/pkg/middleware/space_manager.go +++ b/services/proxy/pkg/middleware/space_manager.go @@ -68,6 +68,10 @@ func (csm claimSpaceManager) ServeHTTP(w http.ResponseWriter, req *http.Request) // no user in context, we omit this request return } + if spaceAssignments == nil { + // no OIDC claims available (e.g. signed URL auth), skip reconciliation + return + } ctx, gwc, err := csm.getCtx() if err != nil { @@ -153,9 +157,15 @@ func (csm claimSpaceManager) evaluateContext(ctx context.Context) (string, map[s return u.GetId().GetOpaqueId(), csm.getSpaceAssignments(ctx) } -// returns a map[spaceID]role +// returns a map[spaceID]role or nil if no OIDC claims are available in the context func (csm claimSpaceManager) getSpaceAssignments(ctx context.Context) map[string]string { claims := oidc.FromContext(ctx) + if claims == nil { + // No OIDC claims in context (e.g. signed URL auth). Skip reconciliation + // to avoid removing the user from all spaces. + return nil + } + values, ok := claims[csm.claimName].([]any) if !ok { csm.logger.Error().Interface("claims", claims).Str("claimname", csm.claimName).Msg("configured claims are not an array")