question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CorsConfiguration based on pattern matching

See original GitHub issue

Affects: Spring Web 5.2.4.RELEASE


Initial issue opened in Spring Cloud Gateway: https://github.com/spring-cloud/spring-cloud-gateway/issues/1607

Application APIs can be called by multiple origins. For applications that represent some kind of platform within a company it often makes sense to accept all request from orings coming from company domain, basically accept all request with origin matching a pattern *.company.com. Currently default spring CorsConfiguration supports only list of origins, I think this might not be flexible enough, as it will require configuration change every time new application within a company wants to call that REST api (especially in case of an API Gateway).

Proposal: add support for CORS configuration based on a pattern matching. One option would’be, I guess, to extend existing CorsConfiguration class with additional fields allowedOriginPatterns and modify checkOrigin to use this property. Or have separate CorsConfiguration implementation that is using pattern matching.

While current solution is extendible and this approach can be implemented within the application itself, I think this should be a part of framework because it’s a widely used functionality and is supported by other frameworks that are used for API implementation.

For example vert.x CorsHandler suipports that: https://github.com/vert-x3/vertx-web/blob/5cd7ecaa6bead1b246b5327537ee9b82c22187bc/vertx-web/src/main/java/io/vertx/ext/web/handler/CorsHandler.java#L42 Also, Kong supports pattern based origins as well.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
korekturcommented, May 21, 2020

@rstoyanchev @sdeleuze can you review the merge request please? https://github.com/spring-projects/spring-framework/pull/25016 It’s been open for almost a month now without any comments, unfortunatelly.

0reactions
rstoyanchevcommented, Jul 6, 2020

Superseded by #25016.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Class UrlBasedCorsConfigurationSource - Spring
CorsConfigurationSource that uses URL path patterns to select the CorsConfiguration for a request. Pattern matching can be done with a PathMatcher or with ......
Read more >
Regex in @CrossOrigin SpringBoot - Stack Overflow
One solution would be extending the spring cors configuration, there is a method called ... CorsRegistration can add origin as a pattern.
Read more >
UrlBasedCorsConfigurationSource (spring-web 5.0.14 ...
Set CORS configuration based on URL patterns. ... Set the PathMatcher implementation to use for matching URL paths against registered URL patterns.
Read more >
Match CORS 'allowedOrigins' with regular expression in ...
Pattern (Java Platform SE 7 ). A regular expression value must match the entire value of the Origin header in the HTTP request...
Read more >
CORS configuration - Amazon Simple Storage Service
Each header name in the Access-Control-Request-Headers header must match a corresponding entry in the rule. Amazon S3 will send only the allowed headers...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found