Skip to content

Conversation

@s1gr1d
Copy link
Member

@s1gr1d s1gr1d commented Nov 25, 2025

Parse each individual cookie header and filter sensitive cookies to at least know which keys the cookie string included.

Follow-up on #18311

@s1gr1d s1gr1d requested review from Lms24 and andreiborza November 25, 2025 13:59
}

return spanAttributes;
}

This comment was marked as outdated.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 25, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 24.8 kB - -
@sentry/browser - with treeshaking flags 23.31 kB - -
@sentry/browser (incl. Tracing) 41.54 kB - -
@sentry/browser (incl. Tracing, Profiling) 46.13 kB - -
@sentry/browser (incl. Tracing, Replay) 79.96 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 69.69 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 84.64 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 96.88 kB - -
@sentry/browser (incl. Feedback) 41.48 kB - -
@sentry/browser (incl. sendFeedback) 29.49 kB - -
@sentry/browser (incl. FeedbackAsync) 34.43 kB - -
@sentry/react 26.52 kB - -
@sentry/react (incl. Tracing) 43.74 kB - -
@sentry/vue 29.25 kB - -
@sentry/vue (incl. Tracing) 43.34 kB - -
@sentry/svelte 24.82 kB - -
CDN Bundle 27.17 kB - -
CDN Bundle (incl. Tracing) 42.16 kB - -
CDN Bundle (incl. Tracing, Replay) 78.7 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 84.16 kB - -
CDN Bundle - uncompressed 79.84 kB - -
CDN Bundle (incl. Tracing) - uncompressed 125.22 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 241.25 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 254.01 kB - -
@sentry/nextjs (client) 45.96 kB - -
@sentry/sveltekit (client) 41.9 kB - -
@sentry/node-core 51.39 kB +0.39% +198 B 🔺
@sentry/node 159.45 kB +0.14% +210 B 🔺
@sentry/node - without tracing 92.83 kB +0.01% +1 B 🔺
@sentry/aws-serverless 108.28 kB +0.19% +201 B 🔺

View base workflow run

@github-actions
Copy link
Contributor

github-actions bot commented Nov 25, 2025

node-overhead report 🧳

Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 11,412 - 8,939 +28%
GET With Sentry 1,927 17% 1,799 +7%
GET With Sentry (error only) 7,699 67% 6,135 +25%
POST Baseline 1,147 - 1,217 -6%
POST With Sentry 574 50% 614 -7%
POST With Sentry (error only) 1,010 88% 1,071 -6%
MYSQL Baseline 3,924 - 3,342 +17%
MYSQL With Sentry 512 13% 511 +0%
MYSQL With Sentry (error only) 3,209 82% 2,726 +18%

View base workflow run

'bearer',
'sso',
'saml',
'crsf',
Copy link

Choose a reason for hiding this comment

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

Bug: Typo in sensitive header snippet breaks CSRF filtering

The sensitive header snippet 'crsf' is a typo that should be 'csrf' (Cross-Site Request Forgery). This prevents proper filtering of CSRF-related headers and cookies that don't contain other sensitive keywords. For example, a header like X-CSRF or a cookie named csrf-token would not be filtered because 'x-csrf'.includes('crsf') returns false. The existing test passes only because X-CSRF-Token also contains token, which masks this bug.

Fix in Cursor Fix in Web

} else if (typeof value === 'string') {
spanAttributes[normalizedKey] = value;
spanAttributes[normalizedKey] = handleHttpHeader(lowerCasedCookieKey, cookieValue, sendDefaultPii);
}
Copy link

Choose a reason for hiding this comment

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

Bug: Set-Cookie attributes incorrectly parsed as separate cookies

The cookie parsing logic treats Cookie and Set-Cookie headers identically by splitting on '; ', but these headers have fundamentally different formats. Cookie headers contain multiple cookies (name1=value1; name2=value2), while Set-Cookie headers contain a single cookie with attributes (name=value; Path=/; HttpOnly). When processing a Set-Cookie header like session=abc; Path=/; HttpOnly, the code incorrectly creates span attributes for path and httponly as if they were cookie names rather than attributes of the session cookie.

Fix in Cursor Fix in Web

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

I think bugbot is right with the cookie/set-cookie difference, so let's double check this.

one more Q: Do we need to adjust the semantic conventions for "sub" http headers? From what I can tell the spec covers arbitrary keys afoter http.request.headers.<key> but I just want to make sure <key> could contain another . as in the cookie header attribute case.

} else if (typeof value === 'string') {
spanAttributes[normalizedKey] = value;
const lowerCasedHeaderKey = key.toLowerCase();
const isCookieHeader = lowerCasedHeaderKey === 'cookie' || lowerCasedHeaderKey === 'set-cookie';
Copy link
Member

Choose a reason for hiding this comment

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

l: probably saves us a few bytes:

Suggested change
const isCookieHeader = lowerCasedHeaderKey === 'cookie' || lowerCasedHeaderKey === 'set-cookie';
const isCookieHeader = /^(set-)cookie$?/.test(lowerCasedHeaderKey)

const lowerCasedHeaderKey = key.toLowerCase();
const isCookieHeader = lowerCasedHeaderKey === 'cookie' || lowerCasedHeaderKey === 'set-cookie';

if (isCookieHeader && typeof value === 'string' && value !== '') {
Copy link
Member

Choose a reason for hiding this comment

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

q: do we handle arrays of cookie headers? (or is this not relevant for cookie/set-cookie?)

});

it('attaches and filters sensitive a set-cookie header', () => {
const headers1 = { 'Set-Cookie': 'user_session=def456' };
Copy link
Member

Choose a reason for hiding this comment

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

l: let's add or adjust a test here for a set-cookie header with additional properties (e.g. like max-age)

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