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

BUG Fix cors breaking if referer header is present #132

Conversation

tractorcow
Copy link
Contributor

BUG Prevent un-extendable config by shifting defaults into PHP
BUG Remove dependency on Doctrine module breaking with --prefer-dist
BUG Fix tests not checking cors port
ENHANCEMENT Clean up Controller::index() method and make lovely
ENHANCEMENT Optimise all imports
Fixes #118

}

// Check referer
$referer = $request->getHeader('Referer');

Choose a reason for hiding this comment

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

I would say this should be a IE/Edge only fallback, not a "fallback because whenever"

Copy link
Contributor Author

@tractorcow tractorcow Jan 21, 2018

Choose a reason for hiding this comment

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

Why would it be? Firefox also has this issue in some conditions, and none of the other solutions I've seen around the web target IE.

E.g. juxt/yada#195

Referer isn't less trusted than Origin.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, user-agent targeting is bad practice. Read up https://webaim.org/blog/user-agent-string-history/ :D

Choose a reason for hiding this comment

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

I'm well aware user-agent targeting is bad :)

I wasn't aware that Firefox showed the same behaviour sometimes. It makes sense to fully fall back in that case. it just feels a bit like a security issue, because it opens up the whole reason the CORS header was added.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, older firefox wouldn't send origin on HTTP POST. My feeling is that if we errored on missing Origin when we had a valid Referer would be a bug on our part.

Choose a reason for hiding this comment

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

Fair enough, as the change is a "hack" that breaks a part of security anyway. It just makes me uncomfortable ;)

Choose a reason for hiding this comment

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

I stand with that it is a potential security issue, but also understand it's the only feasible solution at this moment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough, as the change is a "hack" that breaks a part of security anyway. It just makes me uncomfortable ;)

What part is broken?

Choose a reason for hiding this comment

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

Basically, the way CORS is supposed to work. I'm not saying the code itself is broken :)

Copy link
Contributor

Choose a reason for hiding this comment

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

The origin header is just harder to spoof on browsers than the referrer header, while neither are enforced when using something like curl
https://stackoverflow.com/q/21058183/695842

Two of the top answers resonate the same thing: don't rely on CORS for security

Remember: CORS is not security. Do not rely on CORS to secure your site. If you are serving protected data, use cookies or OAuth tokens or something other than the Origin header to secure that data. The Access-Control-Allow-Origin header in CORS only dictates which origins should be allowed to make cross-origin requests. Don't rely on it for anything more.

{
$response = HTTPResponse::create();
$corsConfig = Config::inst()->get(self::class, 'cors');
if ($corsConfig['Enabled']) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this changes the workflow of the CORS headers...

from the original ticket which raised this concern #66 (comment)

Also adds a check for the pre-flight OPTIONS request, and if CORS is enabled, adds the appropriate headers to the response object - both for the OPTIONS response and for the actual data response.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's the same workflow; In which situation is it different?

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, I needed to double check this :)

I overlooked the second === 'OPTIONS' that was removed above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah the original code was hard to follow, hence the refactor. :)

* @config
* @var array
*/
private static $fixed_types = [];
Copy link
Contributor

Choose a reason for hiding this comment

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

where'd this come from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh right, it was an error where it was searching for an undefined config. Probably not related to this PR and can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've reverted this part.

Copy link
Contributor

Choose a reason for hiding this comment

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

oh ok, I had a quick search for it just now, seems harmless to be in here and could've been left in :)

Damian Mooyman added 2 commits January 23, 2018 16:36
BUG Prevent un-extendable config by shifting defaults into PHP
BUG Fix tests not checking cors port
ENHANCEMENT Clean up Controller::index() method and make lovely
Fixes silverstripe#118
@tractorcow tractorcow force-pushed the pulls/1.0/fix-config-controller-imports-cors-ie-gross-code branch from dabde7e to a62dabc Compare January 23, 2018 03:37
@tractorcow
Copy link
Contributor Author

I've shifted some of the namespace cleanup into a separate commit.

@flamerohr flamerohr merged commit 5f7ac3a into silverstripe:1.0 Jan 23, 2018
@flamerohr flamerohr deleted the pulls/1.0/fix-config-controller-imports-cors-ie-gross-code branch January 23, 2018 21:39
unclecheese pushed a commit to unclecheese/silverstripe-graphql that referenced this pull request Jan 27, 2021
…s-a-wrap

Set user themes on TinyMCEConfig before overwriting with admin themes
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