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

[4.x] CORS incorrectly disregards whether the incoming request is secure or not in deciding whether it's a CORS request #8093

Closed
tjquinno opened this issue Dec 1, 2023 · 0 comments · Fixed by #8166
Assignees
Labels
2.x Issues for 2.x version branch 3.x Issues for 3.x version branch 4.x Version 4.x bug Something isn't working cors Related to CORS support P2

Comments

@tjquinno
Copy link
Member

tjquinno commented Dec 1, 2023

Environment Details

  • Helidon Version: 4.x
  • Helidon SE or Helidon MP
  • JDK version:
  • OS:
  • Docker version (if applicable):

Problem Description

As explained here https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS (near the top):

Cross-Origin Resource Sharing (CORS) is an HTTP-header based mechanism that allows a server to indicate any origins (domain, scheme, or port) other than its own from which a browser should permit loading resources.

(emphasis added)

The incoming request determines the server's origin, including the scheme.

The Helidon CORS processing does not consider whether the request is secure or not (that is, whether its scheme is http or https) in deciding whether the origin conveyed in the request's headers is the same as the server's origin.

Steps to reproduce

Use the examples/cors example.

  1. Edit src/main/resources/logging.properties to contain these lines (uncommented):
    io.helidon.webserver.cors.level=FINER
    io.helidon.cors.level=FINER
  2. mvn clean package
  3. java -jar target/helidon-examples-cors.jar
  4. curl -i -X OPTIONS \
        -H "Access-Control-Request-Method: PUT" \
        -H "Origin: https://here.com" \
        -H "Host: here.com" \
        http://localhost:8080/greet/greeting`

The response is 404, because CORS incorrectly concluded the origin (https in the Origin header) and host (http as derived from the request in the code) shared the same location because it does not consider the scheme of the server's origin.

The logging output from the server contains this, also reflecting the error:

is not cross-host: [header ORIGIN 'https://here.com' matches header HOST 'here.com']

which is true as far as it goes, but the CORS decision-making should also consider the host and origin schemes which it does not.

@tjquinno tjquinno added bug Something isn't working cors Related to CORS support 4.x Version 4.x labels Dec 1, 2023
@tjquinno tjquinno self-assigned this Dec 1, 2023
@tjquinno tjquinno added 3.x Issues for 3.x version branch 2.x Issues for 2.x version branch labels Dec 1, 2023
@tjquinno tjquinno changed the title CORS incorrectly disregards whether the incoming request is secure or not in deciding whether it's a CORS request [4.x] CORS incorrectly disregards whether the incoming request is secure or not in deciding whether it's a CORS request Dec 1, 2023
@tjquinno tjquinno added the P2 label Dec 4, 2023
@m0mus m0mus added this to Backlog Aug 12, 2024
@m0mus m0mus moved this to Closed in Backlog Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.x Issues for 2.x version branch 3.x Issues for 3.x version branch 4.x Version 4.x bug Something isn't working cors Related to CORS support P2
Projects
Archived in project
1 participant