Skip to content
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

FIX: Don't 403 error when origin is on CORS-disallowed (fixes #519) #527

Closed

Conversation

kinglozzer
Copy link
Member

@kinglozzer kinglozzer commented Mar 20, 2023

This will no longer output a 403 error if origin is invalid - CORS headers are to protect things client side, not server side, so there’s no security benefit in triggering this error.

The Access-Control-Allow-Origin is now only output if the origin is valid. For valid origins, that matches the current behaviour. For invalid origins, this is a behavioural change (it used to 403) but this new behaviour will correctly trigger preflight errors:

Access to XMLHttpRequest at 'http://my-graphql-server.test/' from origin 'http://my-origin.test' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

One other minor behavioural change here - if developer has opted to allow all origins, this will now explicitly output Access-Control-Allow-Origin: * instead of Access-Control-Allow-Origin: <current origin>

Issue

@kinglozzer kinglozzer force-pushed the 519-cors-verification branch from 110394a to fb6295b Compare March 20, 2023 13:57
$response->addHeader('Access-Control-Allow-Origin', $origin);
// If specific allowed origins are set, the response headers will vary by request origin, so use the
// Vary header to tell browsers/CDNs that
$response->addHeader('Vary', 'Origin');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kinglozzer
Copy link
Member Author

bump

@GuySartorelli
Copy link
Member

GuySartorelli commented May 1, 2023

The issue attached to this PR is in our "backlog with PRs" column and will be refined in a future backlog refinement session. We're still pretty busy getting the CMS 5 release ready so we haven't had a chance to look at this properly yet.

Copy link
Member

@emteknetnz emteknetnz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the the original issue this was to allow for use case where there is no Origin header being sent.

It seems like you can almost already do that by update the config on the private static $cors['Allow-Origin'] to include a * in there to allow this? validateOrigin() will return true if it encounters a * -- however $origin needs to be non-empty which is what prevents this now

This PR seems like it's completely disabling Origin validation though, based on the discussion in the original issue it looks like it's assumption that doing origin validation at this point is wrong? I'm not so sure it is? Seems like we're better of keeping this existing origin validation.

I think all we really need to do in this PR is instead update validateOrigin() to return true if origin is empty but there's a * in the static config

@emteknetnz
Copy link
Member

@kinglozzer Let me know if you're going to continue with this PR, otherwise I'll close this one for now

@kinglozzer
Copy link
Member Author

Not likely to have time soon 😔

@kinglozzer kinglozzer closed this Jun 30, 2023
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.

3 participants