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

Support comma-delimited list of origin patterns in @CrossOrigin #27606

Closed
wants to merge 41 commits into from

Conversation

funky-eyes
Copy link
Contributor

@funky-eyes funky-eyes commented Oct 25, 2021

example

@CrossOrigin(originPatterns = "${originPatterns:http://a.b.c:[8088,8089],http://d.e.f}", methods = {POST, OPTIONS})

I found that when using the above example configuration, it is not possible to configure multiple source addresses through properties, hope to support this function, thank you very much

fixed #24982

@pivotal-cla
Copy link

@a364176773 Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 25, 2021
@pivotal-cla
Copy link

@a364176773 Thank you for signing the Contributor License Agreement!

@funky-eyes
Copy link
Contributor Author

I’m not sure if it’s better to deal with RequestMappingHandlerMapping#initCorsConfiguration, or CorsConfiguration is more appropriate, but I think CorsConfiguration is more low-level, and the implementation details should be shielded at the bottom.

@sbrannen sbrannen changed the title supports multiple origin pattern injection under @crossorigin annotation Support multiple origin pattern injection in @CrossOrigin Oct 25, 2021
@sbrannen
Copy link
Member

@sbrannen sbrannen added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Oct 25, 2021
@funky-eyes
Copy link
Contributor Author

Closely related to:

hello, I have paid attention to this issue, but the comma has been used by the configured port. For simple distinction, I will use a semicolon

In addition, the configuration of #{'${origin}'.split(',')} will directly call toString for the array. This is not elegant. I think it can be supported in the resolveCorsAnnotationValue method. What do you think?

@funky-eyes
Copy link
Contributor Author

@rstoyanchev PTAL

Copy link
Contributor

@rstoyanchev rstoyanchev left a comment

Choose a reason for hiding this comment

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

Sorry for the slow reply.

I think that CorsConfiguration should remain simple, and should not surprise in cases where input is collected in other ways, that could lead to a potential surprise. So, at the risk of some duplication (between spring-webmvc and spring-webflux), I think the support for splitting should be done in RequestMappingHandlerMapping, at the point of collection, and be documented as a feature on the respective @CrossOrigin attributes. Currently the annotation does not have any mention of the capbaility but it's where the feature needs to apply and be advertised as such.

Second, for the implementation, I think we should stick to using "," i.e. the common way of separating, but obviously the parsing will need to be smarter to iterate over the full string and ignore any port-related commas, i.e. within square brackets.

@funky-eyes
Copy link
Contributor Author

Sorry for the slow reply.

I think that CorsConfiguration should remain simple, and should not surprise in cases where input is collected in other ways, that could lead to a potential surprise. So, at the risk of some duplication (between spring-webmvc and spring-webflux), I think the support for splitting should be done in RequestMappingHandlerMapping, at the point of collection, and be documented as a feature on the respective @CrossOrigin attributes. Currently the annotation does not have any mention of the capbaility but it's where the feature needs to apply and be advertised as such.

Second, for the implementation, I think we should stick to using "," i.e. the common way of separating, but obviously the parsing will need to be smarter to iterate over the full string and ignore any port-related commas, i.e. within square brackets.

thx, I'm going to improve that logic

@funky-eyes
Copy link
Contributor Author

@sbrannen @rstoyanchev There is a timeout error in concourse- CI, I do not know what the specific error is, please help me to check

@sbrannen
Copy link
Member

There is a timeout error in concourse- CI, I do not know what the specific error is, please help me to check

A timeout on the CI server typically means that the CI server was under too much load at that point in time.

It's more important that you have successful local builds on your machine before pushing commits to your PR.

For example, I see that you are using org.junit.jupiter.api.Assertions which is forbidden in Spring Framework's Checkstyle rules. For assertions in tests, we use AssertJ exclusively.

Please make sure you get a passing build using ./gradlew build locally before pushing commits, and please push a commit that fixes any current issues breaking the build locally for you.

@funky-eyes
Copy link
Contributor Author

There is a timeout error in concourse- CI, I do not know what the specific error is, please help me to check

A timeout on the CI server typically means that the CI server was under too much load at that point in time.

It's more important that you have successful local builds on your machine before pushing commits to your PR.

For example, I see that you are using org.junit.jupiter.api.Assertions which is forbidden in Spring Framework's Checkstyle rules. For assertions in tests, we use AssertJ exclusively.

Please make sure you get a passing build using ./gradlew build locally before pushing commits, and please push a commit that fixes any current issues breaking the build locally for you.

ok, thank you

@funky-eyes
Copy link
Contributor Author

@sbrannen
image
I've compiled successfully, but concourse-ci is still hanging

@sbrannen
Copy link
Member

I've compiled successfully,

Great!

but concourse-ci is still hanging

Yeah, our CI server is timing out a lot lately. We'll have to see what we can do about that.

Copy link
Contributor

@rstoyanchev rstoyanchev left a comment

Choose a reason for hiding this comment

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

As this is purely a web concern, there should be no changes in spring-beans, nor in spring-context. The parsing of an origin can be simplified a little and re-used differently (without involving spring-context).

I'm also not sure we should support expressions that split into an array. It should be sufficient to support coma-separated origin values.

@rstoyanchev rstoyanchev self-assigned this Sep 26, 2022
@rstoyanchev rstoyanchev added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on status: feedback-provided Feedback has been provided labels Sep 26, 2022
@rstoyanchev rstoyanchev added this to the 6.0.0-RC1 milestone Sep 26, 2022
@rstoyanchev
Copy link
Contributor

I've gone for a slightly different implementation. Thanks for the PR in any case!

@rstoyanchev rstoyanchev changed the title Support multiple origin pattern injection in @CrossOrigin Support coma delimited list of origin patterns in @CrossOrigin Sep 27, 2022
@sbrannen sbrannen changed the title Support coma delimited list of origin patterns in @CrossOrigin Support comma-delimited list of origin patterns in @CrossOrigin Oct 10, 2022
@funky-eyes
Copy link
Contributor Author

@rstoyanchev Sorry I'm just now seeing your message, thanks, and hopefully I'll have the opportunity to contribute again in the future

@funky-eyes
Copy link
Contributor Author

badba7c
This commit doesn't seem to carry support for SpEL expressions
@rstoyanchev

@rstoyanchev
Copy link
Contributor

The reporter tried using SpEL and suggested support for it, but my read of the issue is that the main goal was to inject an array through an external property. So we've added support for a coma-delimited value, which takes care of that goal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot use SpEL expression to inject an array into @CrossOrigin's value attribute
5 participants