-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
7.17.1 attaching baggage header to third-party requests breaking CORS policies #6077
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
Comments
Hi, @redbugz. Thanks for writing in! Yes, you're right about the PR. We broke one larger change into two PRs (that one and one which has yet to merge) and I didn't appreciate that the way they depend on each other means they really needed to be released together. Apologies! I'll get that merged and we can do another release tomorrow. |
In the process of working on #5285, we missed the fact that the first two PRs (#6039 and #6041) were interdependent, in that the former accidentally introduced a bug (#6077) which the latter then inadvertently fixed. This would have been fine, except that we published a release after merging the bug-creating PR but before merging the bug-fixing PR. Whoops. This patch pulls just the bug-fixing part out of the second PR. It also adds tests to cover the buggy cases, using `it.each` to cover all of the different combinations of outcomes for `shouldCreateSpanForRequest` and `shouldAttachHeaders`. Finally, since I was already in the test file, I reorganized it a little: - `it('does not create span if shouldCreateSpan returns false')` -> absorbed into the `it.each()` - `it('does not create span if there is no fetch data in handler data')` -> added header check, became `it('adds neither fetch request spans nor fetch request headers if there is no fetch data in handler data')` - `it('does not add fetch request spans if tracing is disabled')` and `it('does not add fetch request headers if tracing is disabled` -> combined into `it('adds neither fetch request spans nor fetch request headers if tracing is disabled')` - `it('adds sentry-trace header to fetch requests')` -> absorbed into the `it.each()` - Similar changes made to XHR tests Co-authored-by: Tim Fish <[email protected]>
Hi @redbugz, we just released version 7.17.2 with a fix for this bug. |
Hi, unfortunately I'm still experiencing this issue. I'm on version 7.19.0 for both |
Hi @DaanSterk, would you mind sharing your |
Sure!
|
I looked at this comment from the linked issue above and I might have an idea what's going on (assuming your URL requests look similar to the one mentioned in the comment). I see that |
"localhost" is not part of my query params. In fact, no query params are present at all. FYI, no issues on localhost, but I get the CORS errors when running the application in the production environment. Could my nginx configuration be the source of this issue? |
So while looking at this, I found a bug that could still explain why some headers were attached even if Because of how we internally check if we should attach these headers, in case of no match for However, based on information, I'm not entirely sure if this is the same cause. Can you confirm that if you test the URL against your |
Hi @Archi4400 just stressing this again: Please be aware that the entire URL, including query params, is currently matched against whatever you define in On a related note, there still was a bug in our internal |
vue 3 |
@Archi4400, As I stated above, your
Which is why our SDK attaches headers to this outgoing request. |
Well I have already tried clearing tracePropagationTargets or putting a false value which is definitely not in the request, well it didn't work for me, also changing tracesSampleRate to 0. |
@Lms24 Thanks for help.....my backend is hosted on a different domain so configured backend CORS to allow the sentry-trace and baggage headers. |
FWIW the default |
@yue4u can you elaborate on that please? How does |
I made a reproduction here: https://github.com/lab-yue/sentry-header-reproduction |
@yue4u thanks for creating a reproduction! I tried it out and basically this is expected behaviour. You can resolve the error you're getting in two ways:
Sentry.init({
dsn: "https://[email protected]/0",
integrations: [new Sentry.BrowserTracing()],
// We recommend adjusting this value in production, or using tracesSampler
// for finer control
tracesSampleRate: 1.0,
tracePropagationTargets: []
});
res.header(
"Access-Control-Allow-Headers",
"Accept, Authorization, Content-Type, X-Requested-With, Range, baggage, sentry-trace"
) I also opened a PR to your repro with both options. Both resolve the error for me. Lmk if this resolved the issue for you. |
@Lms24 Thanks for reviewing the reproduction! Actually I've already figured this out before commenting. Just wanted to leave the comment for someone else searching. While it can be fixed both ways, I'm still thinking about if it is possible to avoid changing server headers without disabling tracing at all.
|
Here, trying to integrate sentry with next js 12. It happens to me that when installing sentry it generates this error: Access to XMLHttpRequest at 'http://localhost:1337/api/auth/local' from origin 'http://localhost:3000' has been blocked by CORS policy: Request header field baggage is not allowed by Access-Control-Allow-Headers in preflight response.
now when I add BrowserTracing, it works correctly for me only when logging in but the rest of the endpoints again get the same error cors
|
fixed, the following additional headers should be added in backend: 'baggage', 'sentry-trace'... |
Just want to let you know that I just experienced the same issue with the @sentry/vue package, and google brought me here. |
We got this error even with
To prevent |
Isn't the normal operation supposed to be to track calls? |
I thought the same until I read the type declarations: /**
* Flag to disable patching all together for fetch requests.
*
* Default: true
*/
traceFetch: boolean; |
@lopsum-me can you elaborate why you had to use |
Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which package are you using?
@sentry/react
SDK Version
7.17.1
Framework Version
React 16.x
Link to Sentry event
No response
Steps to Reproduce
Our app was running fine using sentry/tracing 7.16.0
We deployed new code with sentry/tracing 7.17.1
A bunch of third party requests started failing with CORS errors: blocked by CORS policy: Request header field baggage is not allowed by Access-Control-Allow-Headers in preflight response.
We roll back to previous version, errors go away
in our test environment, with Sentry enabled and sentry/tracing at 7.17.1, CORS errors on third party requests to services on other domains that we don't control
with Sentry disabled, everything is fine
with Sentry/tracing on 7.16.0 and enabled, everything is fine
Expected Result
No CORS errors on third-party requests, no baggage header attached to third party requests
Actual Result
request has been blocked by CORS policy: Request header field baggage is not allowed by Access-Control-Allow-Headers in preflight response.
I have to assume this was caused by #6039
We use default tracing config
Which according to the docs:
https://docs.sentry.io/platforms/javascript/performance/instrumentation/automatic-instrumentation/#tracingorigins
should only impact calls to localhost and the same domain/origin as the page, but this does not seem to be happening
The text was updated successfully, but these errors were encountered: