8000 [CORS] Allow Access-Control-Allow-Headers customization by dteleguin · Pull Request #36473 · keycloak/keycloak · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[CORS] Allow Access-Control-Allow-Headers customization #36473

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

Conversation

dteleguin
Copy link
Contributor
@dteleguin dteleguin commented Jan 15, 2025

This PR allows simple customization of HTTP headers that should be allowed in cross-origin requests, in addition to the built-in list. A new CLI option is introduced:

--http-cors-headers <headers>
                     The comma-separated list of custom HTTP headers that should be allowed in
                       cross-origin (CORS) requests.

Corresponding environment variable:

KC_HTTP_CORS_HEADERS

This is a global (server-level) setting. The main use case is supporting headers that are added by various tracing systems and web frameworks.

Closes: #12682

Closes: keycloak#12682

Signed-off-by: Dmitry Telegin <dmitryt@backbase.com>
@dteleguin dteleguin force-pushed the feature/#12682-CORS-custom-headers-take2 branch from 70df3cf to 7a29e65 Compare January 15, 2025 09:05
Copy link
Contributor
@mabartos mabartos left a comment

Choose a reason for hiding this comment

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

@dteleguin Thanks for the PR! I think the enhancement is valid, but it should be also reviewed by @keycloak/core team.

Review:

  • I've added a small comment for String vs. Set
  • Please add some basic tests for CORS
  • In order to pass the HelpCommandDistTest, execute:
KEYCLOAK_REPLACE_EXPECTED=true mvn clean install -Dtest=HelpCommandDistTest -f quarkus/tests/integration/pom.xml

8000
private Set<String> exposedHeaders;

private boolean preflight;
private boolean auth;

DefaultCors(KeycloakSession session) {
DefaultCors(KeycloakSession session, String defaultAllowHeaders) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
DefaultCors(KeycloakSession session, String defaultAllowHeaders) {
DefaultCors(KeycloakSession session, Set<String> defaultAllowHeaders) {

Is it possible to accept a Set of headers? In order to execute String.format("%s, %s", only at one place -> DefaultCors. The manageability would be better.

@mabartos mabartos requested a review from a team January 15, 2025 10:17
@mposolda mposolda self-assigned this Jan 15, 2025
Copy link
Contributor
@stianst stianst left a comment

Choose a reason for hiding this comment

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

This should not be a top-level server config option, but rather if we want to do this just an SPI provider option on the default cors provider.

The option should probably also be additional headers, rather than headers; as otherwise you'd have to include all headers KC needs already.

@dteleguin
Copy link
Contributor Author

@stianst there is an SPI provider option already, namely kc.spi-cors-default-headers / KC_SPI_CORS_DEFAULT_HEADERS.

I have introduced an abbreviated version (KC_HTTP_CORS_HEADERS) to keep aligned with Quarkus's equivalent, QUARKUS_HTTP_CORS_HEADERS. That should simplify migration from Quarkus CORS (which used to work with Keycloak, but is not working anymore).

So, you are suggesting that we remove --http-cors-headers / KC_HTTP_CORS_HEADERS and stick with something like kc.spi-cors-default-extra-headers?

@dteleguin
Copy link
Contributor Author

@mabartos ,

I've added a small comment for String vs. Set

I was thinking of the same - using sets will also allow to sort / deduplicate header names, which would not be possible with preformatted strings.

Please add some basic tests for CORS

Could you please suggest particular tests for this PR?

In order to pass the HelpCommandDistTest, execute:

Thanks for the hint. The top-level config option is currently being discussed with Stian.

Copy link
Contributor
@jonkoops jonkoops left a comment

Choose a reason for hiding this comment

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

I like the extension to the CORS SPI to set the headers, it is an obvious boon for extension developers that should be controllable. I don't think we should be adding any options to overwrite these options through configuration at this point in time (see #12682 (comment)).

@dteleguin
Copy link
Contributor Author

Okay, so there seems to be a consensus that we should not be exposing this as a top-level user-visible config option (at least for now). I will close this PR and create another one covering just the API part.

The user-visible config option will be implemented as a 3rd-party extension.

@dteleguin
Copy link
Contributor Author

Superseded by #40011

@dteleguin dteleguin closed this May 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CORS] Allow Access-Control-Allow-Headers customization
5 participants
0