Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORS: Restrictions for "Access-Control-Allow-Origin" header only applies to the OPTIONS request and ignored for other HTTP requests #3206

Open
ryuferev opened this issue Nov 15, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@ryuferev
Copy link

ryuferev commented Nov 15, 2024

We are trying to enforce restricted access to the server ONLY from the "trusted" websites via CORS. We apply restrictions to the origins, methods, and headers. Those restrictions only apply to the OPTIONS requests, and the server is ignoring them for all other request types.

To Reproduce

Expected behavior
The server is rejecting all requests except whitelisted in cfg.http.cors.(origins, methods, header). The server responds with HTTP 403 and includes Vary: Origin header for invalid (not whitelisted) domain.

Actual behavior:
When the browser is sending the OPTIONS request, the server provides allowed methods/headers for the origin, but still allows all requests from all origins (it means that the browser still can make GET, POST, and other requests regardless of the origin and server doesn't reject it)

Steps to reproduce the behavior:

there is a fragment of the code below where we set the allowed origins, methods, header:

    // cfg.http.cors.allowedOrigins = ["https://test.com/"]
    // cfg.http.cors.allowedMethods = ["GET","POST","PATCH","PUT","DELETE","OPTIONS","HEAD"]
    // cfg.http.cors.allowedHeaders = ["*"]
    CorsConfig(
      allowedOrigin = {
        case origin if cfg.http.cors.anyOrigin || cfg.http.cors.allowedOrigins.contains(render(origin)) =>
          Some(AccessControlAllowOrigin.Specific(origin))
        case _ => None
      }
      allowCredentials = Header.AccessControlAllowCredentials.allow(cfg.http.cors.allowCredentials),
      allowedMethods = allowedMethods,
      allowedHeaders = allowedHeaders
    )

This issue causes a violation of security compliance requirements and blocks our component's integration :(

Thank you!
Roman.

@ryuferev ryuferev added the bug Something isn't working label Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant