fix(otel-web): decode only the requested cookie value - #308
fix(otel-web): decode only the requested cookie value#308chenqinggang001 wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 03c6c1c The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Greptile SummaryThe PR narrows cookie decoding to the requested cookie value so malformed percent sequences in unrelated cookies no longer disrupt session lookup.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains within the eligible follow-up review scope.
|
| Filename | Overview |
|---|---|
| packages/otel-web/src/utils.ts | Updates cookie lookup to decode only the matched cookie value. |
| packages/otel-web/test/utils.test.ts | Adds focused coverage for value decoding and unrelated malformed cookies. |
| .changeset/fix-cookie-decode-uri-error.md | Records the cookie-decoding fix as an @hyperdx/otel-web patch release. |
Reviews (2): Last reviewed commit: "fix(otel-web): decode only the requested..." | Re-trigger Greptile
findCookieValue() called decodeURIComponent() on the whole document.cookie string before splitting it, so any unrelated cookie holding a bare '%' — a legal cookie value — made every lookup throw URIError: URI malformed. The throw propagated out of session tracking through HyperDX.init(), which can break host applications that initialize the SDK on their startup path. Split first and decode only the matched cookie's own value, porting the upstream fix from splunk-otel-js-web#962.
56e998c to
03c6c1c
Compare
|
@wrn14897 Mind taking a look? Small fix in
Direct port of signalfx/splunk-otel-js-web#962, plus two regression tests. |
Description
findCookieValue()callsdecodeURIComponent()on the entiredocument.cookiestring before splitting it:A cookie value may legally contain a bare
%— it is not required to bepercent-encoded. So a single unrelated cookie set by anything else on the
domain (
foo=100%, a truncated UTF-8 sequence, …) makes every lookup inthis function throw
URIError: URI malformed.Since session tracking calls this on init and again on every session refresh,
the error escapes
HyperDX.init(). Applications that initialize the SDK ontheir startup path — before mounting the app — get their bootstrap promise
rejected and never render:
We hit this in production: a blank page stuck on the loading state, and once
the SDK did start, the same
URIErrorrecurring every 60 s from the sessionrefresh timer.
Fix
Split first, then decode only the value of the cookie that was asked for.
This is a direct port of the upstream fix in splunk-otel-js-web
(#962, merged
2025-02-26), which never made it into this fork — same change, same shape,
including leaving the second
decodeURIComponentinparseCookieToSessionState()untouched.Type of change
How has this been tested?
packages/otel-web/test/utils.test.ts: one assertingthe returned value is decoded, one asserting an unrelated non-encoded cookie
no longer makes the lookup throw (the second one fails on
main). Upstreamlanded the fix without tests; these cover it.
with a control showing
decodeURIComponent(document.cookie)throwingURIErroron the same cookie jar. I could not get the full Karma suite tostart locally — its rollup TypeScript step needs
.d.tsoutput from@hyperdx/instrumentation-exception, which my workspace build did notproduce — so CI is the real check here.