fix: prevent cookie header value corruption when saving authenticated pages#219
Merged
Conversation
… pages Cookie values were being re-encoded before being sent, corrupting tokens that contain characters like =, +, /, or %. Cookie handling is now consolidated into a small utility that preserves values verbatim, gathers cookies for the page URL itself in addition to its resources, and fixes domain matching for the primary-domain-only case.
There was a problem hiding this comment.
Pull request overview
Fixes authenticated asset capture by ensuring cookie values are sent verbatim (no re-encoding) and by centralizing cookie domain-matching logic into a shared utility.
Changes:
- Added
buildCookieHeader(verbatim serialization) andfilterCookiesByOriginDomain(hostname-based matching) in a new cookies utility. - Updated asset submission to use the new cookie header builder and removed the
cookienpm dependency. - Updated cookie gathering to include the page URL itself (in addition to resource URLs) and to apply corrected primary-domain filtering, with unit tests added.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/test/spec/utils/test-cookies.tsx | Adds unit tests for verbatim cookie header serialization and domain/host-only matching. |
| src/assets/ts/utils/cookies.ts | Introduces centralized cookie header building and origin-domain filtering utilities. |
| src/assets/ts/features/asset/thunks/submit-asset.ts | Switches to buildCookieHeader to avoid value corruption; removes cookie usage. |
| src/assets/ts/features/asset/thunks/prepare-to-add-to-screenly.ts | Collects cookies for pageUrl plus resources and applies hostname-based domain filtering via the new utility. |
| package.json | Removes the direct cookie dependency. |
| package-lock.json | Removes the locked cookie package entry. |
Comments suppressed due to low confidence (1)
src/assets/ts/features/asset/thunks/prepare-to-add-to-screenly.ts:83
- The cookie de-duplication key only uses
[cookie.domain, cookie.name], which will collapse distinct cookies that share a name/domain but differ bypath(and potentiallyhostOnly). That can drop cookies that would normally be sent together for a URL and can change which value is preserved now thatpageUrlis included ahead of resource URLs.
let cookieJar = Array.from(
new Map(
results
.flat(1)
.map((cookie: Cookie) => [
JSON.stringify([cookie.domain, cookie.name]),
cookie,
]),
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
vpetersson
approved these changes
Jul 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Cookieheader, corrupting tokens containing characters like=,+,/, or%src/assets/ts/utils/cookies.ts) that preserves values verbatim and centralizes domain-matching logiccookienpm dependencyTest plan
src/test/spec/utils/test-cookies.tsx)npm testpasses (29 specs, 0 failures)npm run lint:checkandnpm run format:checkpassnpm run buildcompiles cleanly