Repository navigation
Pyjoyment.Plugin.CORS: Cross-Origin Resource Sharing - #640
Merged
Merged
Conversation
The plugin answers a preflight request before the routes and adds the headers of CORS to the responses of the actions and the static files, for the origins, the methods, the headers and the paths of its options, with Vary: Origin for origins of their own, and never * with credentials. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Docker Smoke Test
|
Contributor
Tests
|
4 of 5 tasks
7 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #634, its fifth step, stacked on #639.
Changes
Pyjoyment.Plugin.CORS, with no counterpart in Mojolicious:before_dispatchit answers a preflight request (OPTIONSwithAccess-Control-Request-Method) with204, before the routes, so a preflight never reaches an action, also on ananyroute. A preflight from an origin that is not allowed gets204without the CORS headers. AnOPTIONSrequest that is not a preflight still reaches the routes.after_dispatchit addsAccess-Control-Allow-Origin(withAccess-Control-Allow-CredentialsandAccess-Control-Expose-Headerswhen configured) to the responses of actions, static files and error pages, for a request whoseOriginis allowed. A header that the action has set is kept.origins:*by default; a list of origins (case-insensitive) or of regular expressions, or a function, as inAllowedHostsmethods:GET,HEAD,POST,PUT,PATCHandDELETEby defaultheaders: by default the headers that the preflight asks for are allowedexpose,credentials,max_agepaths: path prefixes or regular expressions, so CORS can be limited to an APIcredentials=Truewith*raises when the plugin is registered: browsers reject it, and reflecting any origin with credentials would let any site read the user's data.Vary: Originis on every response, withinpaths, when the origins are not*, andVary: Access-Control-Request-Headersis on a preflight answer when it echoes the requested headers.AllowedHosts, the CORS origins must also be among theAllowedHostsorigins. This is a deviation from Security headers: HSTS, CSP with nonce and reports, Permissions-Policy, CORS #634, which proposed taking the defaults fromAllowedHosts: that plugin does not expose its configuration, so the origins are given explicitly.Pyjoyment.Pluginsand in the guide's index, has an API page, and is on pyright's strict list.Validation
t/Pyjoyment/cors_lite_app.py:*on the response of an action, a static file and a 404anyroute), and on an unknown path gets204OPTIONSrequest that is not a preflight reaches the actionVary: Originwithout duplicatespaths, including that/apixis not under/apiAllowedHostst/docs/Pyjoyment_Plugin_CORS.py: the examples of the documentationPYTHONDEVMODE=1 python -m Pyjo.Prove -l -j 4 -r ton asyncio and onPyjo.Reactor.Poll: all tests passsphinx-build -Wpassestrunk check: no issues🤖 Generated with Claude Code