Skip to content

Add support for regex in allowed origins for the CORS filter.#13778

Open
alexdupre wants to merge 1 commit intoplayframework:mainfrom
alexdupre:cors-regex
Open

Add support for regex in allowed origins for the CORS filter.#13778
alexdupre wants to merge 1 commit intoplayframework:mainfrom
alexdupre:cors-regex

Conversation

@alexdupre
Copy link
Contributor

Pull Request Checklist

Helpful things

Purpose

This PR adds the ability to use regular expressions when defining the allowed origins for the CORS filter.

Background Context

Sometimes explicitely declaring all allowed origins is not possible, for example when dynamic hostnames under the same domain are used. Currently the only option is to allow any origin, but this is sub-optimal. I've evaluated two different approaches to solve the issue:

  1. add support for wildcards (simpler, but still limited)
  2. add support for regular expressions (more complex, but more flexible)

Considering that other common web frameworks (like Node Express) already support regular expressions, I've opted for the second solution.

The change has been done in a full backward compatible way, so the CORS behavior is unchanged unless the new allowedOriginsAsRegex config parameter is set to true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant