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 Include scheme and port of origin and host in deciding whether to classify a request as CORS or not #8166

Merged
merged 4 commits into from Jan 5, 2024

Conversation

tjquinno
Copy link
Member

@tjquinno tjquinno commented Dec 19, 2023

Description

Resolves #8088
Resolves #8093

Proper implementation of the CORS algorithm requires considering the scheme, node, and port of the origin (conveyed by the Origin header) and the host that was requested by the client (conveyed by the Host header or the Forwarded header or the X-Forwarded-* family of headers). A normal request in the CORS context is one that is not cross-origin--that is, for which the origin and the host share the same scheme, node, and port.

The 4.x logic regressed from 3.x in not considering the scheme and port properly.

This PR does several things:

  1. Adds an isSecure method to an adapter interface for requests.

    The adapter insulates the CORS logic from differences in and dependence on the SE and MP request implementations. The PR also includes the enhancements to the SE and MP adapters to implement this new method.

  2. Corrects the CORS logic which checks to see if the incoming request is a normal request (that is, non-CORS).

    The CORS code first checks for whether the request is normal and, if so, skips the CORS processing. This normal check failed to account properly for the scheme and port of the origin and host and therefore incorrectly identified requests that needed CORS processing as normal (non-CORS) requests.

  3. Adds numerous tests.

The CORS code does considerable logging (when turned on) to help users understand the decisions the code makes. This PR also introduces a new private record which represents the result of the "is the request normal" check, containing not only the true/false result but also the effective origin and host locations (full scheme, node, and port) that the is-normal check computed to decide the true/false result. The logging code now uses these intermediate results rather than having to recompute them for logging.

Documentation

This is a bug fix. No doc impact.

@tjquinno tjquinno self-assigned this Dec 19, 2023
@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Dec 19, 2023
@tjquinno tjquinno marked this pull request as draft December 19, 2023 12:47
@tjquinno tjquinno marked this pull request as ready for review December 19, 2023 12:57
ljnelson
ljnelson previously approved these changes Jan 5, 2024
Copy link
Member

@ljnelson ljnelson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of questions but basically LGTM

ljnelson
ljnelson previously approved these changes Jan 5, 2024
Copy link
Member

@ljnelson ljnelson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of comments

cors/src/main/java/io/helidon/cors/CorsSupportHelper.java Outdated Show resolved Hide resolved
cors/src/main/java/io/helidon/cors/LogHelper.java Outdated Show resolved Hide resolved
@tjquinno tjquinno merged commit db10837 into helidon-io:main Jan 5, 2024
12 checks passed
@tjquinno tjquinno deleted the 4.x-cors-host branch January 5, 2024 23:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
2 participants