-
Notifications
You must be signed in to change notification settings - Fork 141
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
Regular expression or wildcard origins #54
Comments
@marcoqu at the moment, there is no way to do this. Currently, Flask-Cors only supports *, null or the exact domain. Can you explain your use case a little bit so I can better understand how to add support for this? The way I imagine this could work would be to alter the handling of the This should be straightforward to implement, with the exception of the interaction with the An alternative is to allow a user to specify a single callable as the 'origin' parameter. Some function which will be invoked within the context of the request and expected to return a string of the origin to set. I would love your feedback on this potential implementation and your thoughts. This conversation and thought process has made me realize that the current implementation actually suffers from a potential security flaw: Since origins will have an http prefix, I don't believe it can actually occur, but I will patch this nonetheless. I look forward to hearing back! |
Looks like Django-Cors has this, but does not support an always_send style option. I think it makes sense to add this and simply document the behavior in combination with always_send. I really wish there was a way to combine Django-Cors and Flask-Cors with a layer of abstraction to handle the determination of which headers to set, and or settings... I would rustle something up, but I fear it would be more work than benefit. |
Hi Cory, thanks for the feedback. Allowing regex or list of regexes in the origins parameter would allow this to work. Providing a function to determine if the current origin should be allowed or not is even more flexible, and it would allow all kind of solutions (database lookups, ip geolocation...). Thanks! |
I have decided to implement the regexp approach and released version v1.8.0 to Pypi with the new feature. Please give it a try and let me know what you think! |
Is there any way to specify origins in a regular expression, so that urls matching the pattern are allowed? Eg: all subdomains from a given domain..
r"https?://\w*\.?example\.com:?\d*/?.*"
The text was updated successfully, but these errors were encountered: