Repository navigation
ServicePrincipalAuthenticationFilter does not bypass CORS preflight (OPTIONS) requests #6162
Description
Bug Report
Describe the Bug
This is the same underlying problem as #5968: ServicePrincipalAuthenticationFilter should bypass authentication for OPTIONS requests, just like JwtValidatorFilter already does.
ServicePrincipalAuthenticationFilter requires the claims request property to be present:
Lines 67 to 72 in 5d067a5
| public void filter(ContainerRequestContext containerRequestContext) { | |
| var claims = containerRequestContext.getProperty(REQUEST_PROPERTY_CLAIMS); | |
| if (claims instanceof ClaimToken claimToken) { | |
| var subject = claimToken.getStringClaim(SUBJECT); | |
| var scope = claimToken.getStringClaim(SCOPE); |
...whereas JwtValidatorFilter already has an explicit OPTIONS bypass:
Lines 50 to 55 in 5d067a5
| @Override | |
| public void filter(ContainerRequestContext requestContext) { | |
| // OPTIONS requests don't have credentials - do not authenticate | |
| if (!OPTIONS.equalsIgnoreCase(requestContext.getMethod())) { | |
| var authHeader = requestContext.getHeaderString("Authorization"); | |
| if (authHeader == null || !authHeader.startsWith("Bearer ")) { |
Expected Behavior
OPTIONS requests should bypass authentication in AuthenticationRequestFilter, so that CORS preflight requests succeed with a 2xx response.
Observed Behavior
A CORS preflight request receives a 401, which browsers report as:
Access to fetch at '...' from origin '...' has been blocked by CORS
policy: Response to preflight request doesn't pass access control
check: It does not have HTTP ok status.
Steps to Reproduce
- Enable the Management API OAuth2 authentication extension (
edc.iam.oauth2.issuer,edc.iam.oauth2.jwks.url) together with CORS (edc.web.rest.cors.enabled=true). - Send a CORS preflight request:
curl -i 'http://localhost:8192/management/v5/participants/participant1/contractnegotiations/request' \ -X OPTIONS \ -H 'Origin: http://localhost:4201' \ -H 'Access-Control-Request-Method: POST' \ -H 'Access-Control-Request-Headers: authorization,content-type'
Response:
HTTP/1.1 401 Unauthorized
Access-Control-Allow-Origin: http://localhost:4201
Access-Control-Allow-Headers: Origin,Content-Type,Accept,Authorization,X-Api-Key
Access-Control-Allow-Methods: GET,POST,PUT,PATCH,DELETE,OPTIONS
Cache-Control: must-revalidate,no-cache,no-store
Content-Length: 0
Context Information
Used version: 1.0.0-RC4
OS: Linux
Possible Implementation
@Override
public void filter(ContainerRequestContext containerRequestContext) {
if ("OPTIONS".equalsIgnoreCase(containerRequestContext.getMethod())) {
return;
}
var claims = containerRequestContext.getProperty(REQUEST_PROPERTY_CLAIMS);
// ... rest of the existing logic unchanged
}
Activity
github-actions commentedon Oct 26, 2026
Thanks for your contribution 🔥 We will take a look asap 🚀
alaguna95 commentedon Oct 27, 2026
thanks!