Skip to content

feat(toolbar): Use the CSRF token in headers and cookies when using the sentry API#106286

Merged
ryan953 merged 6 commits intomasterfrom
ryan953/toolbar-POST-with-csrf-cookie
Jan 21, 2026
Merged

feat(toolbar): Use the CSRF token in headers and cookies when using the sentry API#106286
ryan953 merged 6 commits intomasterfrom
ryan953/toolbar-POST-with-csrf-cookie

Conversation

@ryan953
Copy link
Member

@ryan953 ryan953 commented Jan 14, 2026

Followup to #106059

Before we only sent it in the headers, but the API is still returning "CSRF Failed: CSRF cookie not set." so we need it in both places it seems.

This splits up the name & value parts, so we can set everything very clearly. To cleanup we dont need the cookie names again, we will just set all cookies to have a value of the emptystring.

This change sits within the boundaries we had before; no values are leaving the scope of our dns/domains. As before we're augmenting requests (adding cookies and other headers) as we proxy messages through the page, checking all the same allowlists before we even render the page. These diagrams are still relevant, but show only the cookie argument which is now both session and csfr tokens.

…he sentry API

Before we only sent it in the headers, but the API is still returning "CSRF Failed: CSRF cookie not set." so we need it in both places it seems.

This splits up the name & value parts, so we can set everything very clearly. To cleanup we dont need the cookie names again, we will just set all cookies to have a value of the emptystring
@ryan953 ryan953 requested review from a team as code owners January 14, 2026 18:56
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jan 14, 2026
Copy link
Member

@billyvg billyvg left a comment

Choose a reason for hiding this comment

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

codewise LGTM - good idea to have security sign off on it.

document.cookie.split(';').forEach(cookie => {
const name = cookie.split('=')[0].trim();
document.cookie = makeCookieValue(name, '', window.location.hostname, 0);
document.cookie = makeCookieValue(name, '', regionUrl, 0);
Copy link
Member

Choose a reason for hiding this comment

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

What is regionUrl?

Copy link
Member Author

Choose a reason for hiding this comment

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

have to set stuff against sentry.io, and us.sentry.io.
through the login flow sometimes we redirect between the two, and for api requests we use the regionUrl as the base.

@ryan953 ryan953 merged commit 1b18238 into master Jan 21, 2026
73 of 76 checks passed
@ryan953 ryan953 deleted the ryan953/toolbar-POST-with-csrf-cookie branch January 21, 2026 21:11
@github-actions github-actions bot locked and limited conversation to collaborators Feb 6, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants