Skip to content

ref(core): Consolidate cookie parsing into one parser - #24536

Open
s1gr1d wants to merge 3 commits into
developfrom
sig/consolidate-cookie-parsing
Open

s1gr1d wants to merge 3 commits into
developfrom
sig/consolidate-cookie-parsing

Conversation

@s1gr1d

@s1gr1d s1gr1d commented Sep 21, 2026

Copy link
Copy Markdown
Member

parseCookie (used for event cookie records) and parseCookieHeader (used for span attributes) had a different implementation for nameless segments, Set-Cookie attributes, and decoding.

parseCookieHeader is the new parser for both and returns ordered [name, value] pairs, with a set-cookie mode that ignores cookie attributes (like Max-Age).

Changes for event attributes

Case Input Before After
Set-Cookie attributes (e.g. Max-Age) filterCookies('sid=1; Max-Age=3600; Path=/', true, 'set-cookie') { sid: '[Filtered]', 'Max-Age': '3600', Path: '/' } { sid: '[Filtered]' }
Nameless cookie, =token form filterCookies('=s3cr3t; theme=dark') { '': 's3cr3t', theme: 'dark' }, so the token leaks { '': '[Filtered]', theme: 'dark' }
Nameless cookie, bare token filterCookies('s3cr3t; theme=dark') { theme: 'dark' }, the token is dropped { '': '[Filtered]', theme: 'dark' }

What stays the same

Case Input Event record Span attribute
Encoded value email=jane%40example.com { email: 'jane@example.com' } (decoded) ['email=jane%40example.com'] (raw, as sent)
Repeated name lang=en; lang=de { lang: 'en' } (first wins) ['lang=en', 'lang=de']
No cookie at all ;;; '[Filtered]' ['[Filtered]']

Fixes #24501

Added a changelog contribution entry because of this PR: #24525

@s1gr1d
s1gr1d requested a review from a team as a code owner September 21, 2026 09:18
@s1gr1d
s1gr1d requested review from Lms24 and logaretm and removed request for a team September 21, 2026 09:18
@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 29.09 kB - -
@sentry/browser - with treeshaking flags 27.35 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 27.26 kB - -
@sentry/browser (incl. Tracing) 50.56 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 50.58 kB - -
@sentry/browser (incl. Tracing, Profiling) 53.56 kB - -
@sentry/browser (incl. Tracing, Replay) 90.11 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 79.21 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 94.81 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 107.78 kB - -
@sentry/browser (incl. Feedback) 46.62 kB - -
@sentry/browser (incl. sendFeedback) 34.15 kB - -
@sentry/browser (incl. FeedbackAsync) 39.26 kB - -
@sentry/browser (incl. Metrics) 30.1 kB - -
@sentry/browser (incl. Logs) 30.35 kB - -
@sentry/browser (incl. Metrics & Logs) 31.02 kB - -
@sentry/react 30.84 kB - -
@sentry/react (incl. Tracing) 52.88 kB - -
@sentry/vue 36.34 kB - -
@sentry/vue (incl. Tracing) 52.86 kB - -
@sentry/svelte 29.11 kB - -
CDN Bundle 30.8 kB - -
CDN Bundle (incl. Tracing) 51.1 kB - -
CDN Bundle (incl. Logs, Metrics) 33.06 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 53.09 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 73.75 kB - -
CDN Bundle (incl. Tracing, Replay) 88.66 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 90.58 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 94.7 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 96.71 kB - -
CDN Bundle - uncompressed 91.16 kB - -
CDN Bundle (incl. Tracing) - uncompressed 152.53 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 97.73 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 158.49 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 227.14 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 272.1 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 278.04 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 285.81 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 291.74 kB - -
@sentry/nextjs (client) 55.21 kB - -
@sentry/sveltekit (client) 50.99 kB - -
@sentry/core/server 39.99 kB -0.03% -10 B 🔽
@sentry/core/browser 13.66 kB - -
@sentry/node 133.26 kB -0.04% -52 B 🔽
@sentry/node/import (ESM hook with diagnostics-channel injection) 82.17 kB - -
@sentry/node - without tracing 89.86 kB -0.06% -46 B 🔽
@sentry/node - without channel injection 112.08 kB -0.06% -57 B 🔽
@sentry/aws-serverless 98.13 kB -0.05% -44 B 🔽
@sentry/cloudflare (withSentry) - minified 204.63 kB -0.06% -110 B 🔽
@sentry/cloudflare (withSentry) 509.38 kB -0.01% -27 B 🔽

View base workflow run

@s1gr1d

s1gr1d commented Sep 21, 2026

Copy link
Copy Markdown
Member Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 6db8941. Configure here.

Comment on lines -262 to +268
setCookie: 'session=abc123; theme=dark',
setCookie: 'session=abc123; Path=/',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

q: were these tests just wrong before? As in, multiple cookies being set in one set-cookie header?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, that's the Cookie syntax. For Set-Cookie, those other values are just other attributes like Max-Age or Path (which we don't anymore now - just key/value).

But outcome of our offline discussion was that we might send the set-cookie attributes as well and see set-cookie as one joined string.

Comment on lines +53 to +56
.map(segment => segment.trim())
// ";;" and trailing ";" leave empty segments
.filter(segment => segment !== '')
.map(segment => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

l: should we use a good old for loop over the three loops here? This might be slightly more performant but given we're deailing with a list of cookies, it's not a lot of entries most likely. Feel free to keep as-is.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I would keep it as a cookie header only has a handful of entries (so performance does not really matter) and it gives better readability.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This might be slightly more performant

(nerd-sniped) Technically this approach is just a hair less performant, because we could do the map/filter/map in one pass over the items instead of 3. But even a huge cookie header is capped at a hard limit of 4KiB, so even if they're all single-value keys and values, that's an absolute hard max of less than 1024 items, which is several orders of magnitude less than what would matter, and so we should just optimize for readability.

This branch has not been deployed

No deployments
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.

Consolidate the two cookie parsers parseCookie and parseCookieHeader

3 participants