Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[2.7][WebProfilerBundle] Fix CORS ajax security issues#18413

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@romainneutron
Copy link
Contributor

QA
Branch?2.7
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed ticketsN/A
LicenseMIT
Doc PRN/A

The WebProfiler toolbar monitors ajax requests. However, when using cross domain ajax requests, it triggers a security issuesRefused to get unsafe header "X-Debug-Token"Refused to get unsafe header "X-Debug-Token-Link" because if the other app is not a Symfony App configured to expose these headers in CORS.

image

This fixes the issue. It adds a new configuration node to explicitly activate it on purpose.

->end()
->end()
->booleanNode('intercept_redirects')->defaultFalse()->end()
->booleanNode('enable_cors')->defaultFalse()->end()
Copy link
Member

Choose a reason for hiding this comment

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

Any downside to always enable it?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

No downside, even if you're doing cross domain calls without exposing the related headers. However, you'll have security logs in your console.

This should be enabled if you're doing cross domain calls on Symfony apps that enabled cors and have been configured to expose these headers through CORS. Moreover, even if you do that, I'm not sure you would be able to display profiles (to be tested)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Oh, I just realized I read your comment to fast :) Of course, it's better to enable it by default, I'm gonna update this

@romainneutronromainneutronforce-pushed theweb-developer-fix-cors-profiling branch fromcd33ed0 tocc11f26CompareApril 2, 2016 23:33
@romainneutron
Copy link
ContributorAuthor

PR updated, comments addressed

@kroshp
Copy link

Same issue in 2.8

rolandhemmer reacted with thumbs up emoji

@xabbuh
Copy link
Member

@kroshp All fixes will be merged up to all maintained branches after being merged into the lowest affected branch.

protected$mode;
protected$position;
protected$excludedAjaxPaths;
protected$enableCors;
Copy link
Member

Choose a reason for hiding this comment

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

should be private (even if older properties are not for legacy reasons)

@stof
Copy link
Member

stof commentedApr 7, 2016

is there a way in JS to check whether a header can be accessed according to the CORS rules, to be able to fallback ? It would be great to avoid this configuration setting entirely, and just remove it from the display (or display it in a special way) when the token cannot be retrieved due to CORS restrictions

@stof
Copy link
Member

stof commentedApr 7, 2016

btw, a try/catch around the statement reading the header might be an acceptable way to implement the fallback if there is no better one.

@romainneutron
Copy link
ContributorAuthor

I just tried to detect if we had access to these headers in CORS usingAccess-Control-Expose-Headers, but a security warning is still issued when accessing this header.

Please note that these are not exception but Browser security warnings. You can try/catch these warnings but they still appear in the console.

I'm not in favor of adding a new configuration, so this PR is stalled while we found something better :/

@romainneutron
Copy link
ContributorAuthor

I'm a bit stuck with this here...
If anybody's got an idea on how to solve this problem without a config option, help is welcome :)

@stof
Copy link
Member

@romainneutron have to tried to ask on SO to get some help from the JS community ?

fabpot added a commit that referenced this pull requestApr 21, 2016
…equest occured from another domain (romainneutron)This PR was merged into the 2.7 branch.Discussion----------[2.7][WebProfilerBunde] Give an absolute url in case the request occured from another domain| Q             | A| ------------- | ---| Branch?       | 2.7| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | n/a| License       | MIT| Doc PR        | n/aThis is related to#18413:Using two symfony application ProjectA and MicroServiceB, if ProjectA issues XHR to MicroServiceB and both have the WebProfilerBundle enabled, then Ajax requests will be monitored in ProjectA. But - at the moment - it will try to look for profiles under ProjectA domain whereas data are stored on MicroServiceB domain.This PR fixes this issueCommits-------1a5d4ad [WebProfilerBunde] Give an absolute url in case the request occured from another domain
@weaverryan
Copy link
Member

Could why just avoid checking the headers entirely (and therefore showing the profiler link) when the AJAX request is for another domain? As nice as it is to show a profiler link that's coming from another Symfony app on some other domain, I'm not sure it's necessary - I'd expect the profiler link only for AJAX requests that are coming fromthis application.

@romainneutron
Copy link
ContributorAuthor

I like@weaverryan 's idea, WDYT?

@xabbuh
Copy link
Member

@weaverryan But that would mean that AJAX requests to the same application but with another domain also wouldn't be displayed, right? If so this is a BC break to me as someone might already rely on it (you could serve your internal API with a different domain for whatever reason for example).

@stof
Copy link
Member

@weaverryan this would not be very convenient if you have an app hitting your API hosted on a different domain.
This is why we should first try to get input from the community of JS devs/browsers to know whether there is a way to know that we are allowed (or not allowed) to read a header. But@romainneutron has not replied to my question above

@stof
Copy link
Member

@romainneutron can you try usinggetAllResponseHeaders() which will give you all headers ? AFAIU, this should always be allowed by CORS (but giving you only the headers you are allowed to see). You could then check in this object whether there is the profiler header

@stof
Copy link
Member

@romainneutron I confirm you thatxhr.getAllResponseHeaders() does not trigger a security warning in chromium

romainneutron reacted with hooray emoji

@stof
Copy link
Member

though it returns a string representation of HTTP headers, so you will need to extract the header from it.

@stof
Copy link
Member

or simpler: use the regex only to know whether the Symfony headers are exposed, and then usegetResponseHeader to get their value when exposed (avoiding to parse headers manually)

@romainneutron
Copy link
ContributorAuthor

@stof thanks for the hint! I'll try this asap

@romainneutronromainneutronforce-pushed theweb-developer-fix-cors-profiling branch 2 times, most recently from7b83000 to20a26eeCompareMay 16, 2016 14:53
@romainneutron
Copy link
ContributorAuthor

PR has been updated, ready for review

if (ret=allHeaders.match(/^x-debug-token-link:\s+(.*)$/im)) {
stackElement.profilerUrl= ret[1];
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

missing comma

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

good catch, fixed

@romainneutronromainneutronforce-pushed theweb-developer-fix-cors-profiling branch from20a26ee tocccc420CompareMay 16, 2016 15:16
@romainneutronromainneutronforce-pushed theweb-developer-fix-cors-profiling branch fromcccc420 tof8dd87dCompareMay 16, 2016 16:19
@nicolas-grekas
Copy link
Member

👍

@fabpot
Copy link
Member

Thank you@romainneutron.

@fabpotfabpot merged commitf8dd87d intosymfony:2.7May 17, 2016
fabpot added a commit that referenced this pull requestMay 17, 2016
…mainneutron)This PR was merged into the 2.7 branch.Discussion----------[2.7][WebProfilerBundle] Fix CORS ajax security issues| Q             | A| ------------- | ---| Branch?       | 2.7| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | N/A| License       | MIT| Doc PR        | N/AThe WebProfiler toolbar monitors ajax requests. However, when using cross domain ajax requests, it triggers a security issues `Refused to get unsafe header "X-Debug-Token"` `Refused to get unsafe header "X-Debug-Token-Link"` because if the other app is not a Symfony App configured to expose these headers in CORS.![image](https://cloud.githubusercontent.com/assets/137574/14225799/f462c09c-f8cf-11e5-925d-88be99945a92.png)This fixes the issue. It adds a new configuration node to explicitly activate it on purpose.Commits-------f8dd87d [WebProfilerBundle] Fix CORS ajax security issues
@romainneutronromainneutron deleted the web-developer-fix-cors-profiling branchMay 17, 2016 21:30
@linnaealinnaea mentioned this pull requestMay 26, 2016
fabpot added a commit that referenced this pull requestMay 26, 2016
This PR was merged into the 2.7 branch.Discussion----------Fix js comment in profiler| Q             | A| ------------- | ---| Branch?       | 2.7| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets || License       | MIT| Doc PR        |Single line comment introduced in#18413 causes the toolbar to fail to load with a syntax error.Commits-------91a2f5d Fix js comment in profiler
@fabpotfabpot mentioned this pull requestMay 26, 2016
This was referencedJun 6, 2016
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

9 participants

@romainneutron@kroshp@xabbuh@stof@weaverryan@nicolas-grekas@fabpot@aitboudad@javiereguiluz

[8]ページ先頭

©2009-2025 Movatter.jp