-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Tighten CORS rules #7503
Tighten CORS rules #7503
Conversation
🪼 branch checks and previews
Install Gradio from this PR pip install https://gradio-builds.s3.amazonaws.com/01a39bf774b6c215a0a29220b576bb40329c81e6/gradio-4.19.1-py3-none-any.whl Install Gradio Python Client from this PR pip install "gradio-client @ git+https://github.com/gradio-app/gradio@01a39bf774b6c215a0a29220b576bb40329c81e6#subdirectory=client/python" |
🦄 change detectedThis Pull Request includes changes to the following packages.
With the following changelog entry.
Maintainers or the PR author can modify the PR title to modify this entry.
|
This fix looks great. Thank you for the resolution. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this be served by just setting allow_origin_regex
for CORSMiddleware
?
I don't believe so, no. We want to apply CORS only if the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my testing this works great! Thanks @abidlabs!
Thank you @whitphx @akx @pngwn for the reviews, and for @PinkDraconian for reporting the original issue! |
To prevent malicious 3rd party websites from making requests to Gradio applications running locally, this PR tightens the CORS rules around Gradio applications. In particular, based on @XciD's suggestion: it checks to see if the host header is
localhost
(or one of its aliases) and if so, it requires the origin header (if present) to belocalhost
(or one of its aliases) as well.To test this, you can start running any Gradio app, e.g. this one, locally:
And then open up different websites in your browser and simulate requests from them using the Inspector console, e.g.:
If you make the request from a website on localhost, the request should go through, but if you make the request while a different webpage is loaded, it should be blocked.
I also installed this PR in this Space: https://huggingface.co/spaces/abidlabs/test-cors, and confirmed that: