Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughCookie deletion and client refresh-cookie handling were adjusted to respect the client-side secure context. Deletion now includes a secure flag when appropriate, and the client implementation removes the default secure refresh cookie after writing a domain-specific custom cookie. Changes
Sequence Diagram(s)sequenceDiagram
participant Browser
participant ClientImpl
participant CookieLib
rect rgba(200,240,200,0.3)
Note over ClientImpl,Browser: Client sets domain-specific refresh cookie
ClientImpl ->> Browser: set custom refresh cookie (domain)
end
rect rgba(200,220,240,0.25)
Note over ClientImpl: Determine secure context and cleanup default cookie
ClientImpl ->> ClientImpl: isSecureCookieContext()
alt secure context
ClientImpl ->> Browser: delete default secure refresh cookie
else insecure context
ClientImpl -->> Browser: (no default secure delete)
end
end
rect rgba(240,230,200,0.25)
Note over CookieLib: Server-side (client) cookie deletion respects secure flag
Browser ->> CookieLib: deleteCookieClientInternal(options with domain)
CookieLib ->> Browser: delete cookie with secure flag derived from context
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (2 warnings, 1 inconclusive)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile OverviewGreptile SummaryFixed cookie deletion to properly handle Confidence Score: 5/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant App as Client App
participant Cookie as Cookie Helper
participant Browser as Browser (js-cookie)
Note over App,Browser: Switching to Custom Domain Cookie
App->>App: _queueCustomRefreshCookieUpdate()
App->>App: Get trusted parent domain
App->>Cookie: setCookie(domain, refreshToken)
Cookie->>Browser: Set custom domain cookie
Note over App,Browser: Delete old default cookie
App->>Cookie: isSecureCookieContext()
Cookie->>App: Returns secure flag (HTTPS check)
App->>App: _getRefreshTokenDefaultCookieNameForSecure(isSecure)
Note right of App: Returns "__Host-stack-refresh-{id}--default"<br/>or "stack-refresh-{id}--default"
App->>Cookie: setOrDeleteCookie(defaultName, null)
Cookie->>Cookie: deleteCookieClientInternal(name)
Note right of Cookie: Now passes secure flag
Cookie->>Browser: Cookies.remove(name, {secure: true/false})
Note right of Browser: Secure flag must match<br/>the flag used when setting
Browser->>Browser: Cookie successfully deleted
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/template/src/lib/cookie.ts (1)
205-210: LGTM! Secure flag now properly included in cookie deletion.The addition of
secure: determineSecureFromClientContext()ensures cookies are deleted with the same security attributes they were set with, which is required by browser cookie APIs. This aligns with howsetCookieClientInternal(line 197) sets cookies based on the secure context.Optional: Cache the secure context value.
Since
determineSecureFromClientContext()is called twice (lines 207 and 209), consider caching the result:function deleteCookieClientInternal(name: string, options: DeleteCookieOptions = {}) { + const secure = determineSecureFromClientContext(); if (options.domain !== undefined) { - Cookies.remove(name, { domain: options.domain, secure: determineSecureFromClientContext() }); + Cookies.remove(name, { domain: options.domain, secure }); } - Cookies.remove(name, { secure: determineSecureFromClientContext() }); + Cookies.remove(name, { secure }); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/template/src/lib/cookie.ts(1 hunks)packages/template/src/lib/stack-app/apps/implementations/client-app-impl.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/template/src/lib/stack-app/apps/implementations/client-app-impl.ts (1)
packages/template/src/lib/cookie.ts (2)
isSecure(174-182)setOrDeleteCookie(221-224)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
- GitHub Check: build (22.x)
- GitHub Check: restart-dev-and-test
- GitHub Check: check_prisma_migrations (22.x)
- GitHub Check: restart-dev-and-test-with-custom-base-port
- GitHub Check: build (22.x)
- GitHub Check: setup-tests
- GitHub Check: docker
- GitHub Check: lint_and_build (latest)
- GitHub Check: build (22.x)
- GitHub Check: all-good
- GitHub Check: Vercel Agent Review
🔇 Additional comments (1)
packages/template/src/lib/stack-app/apps/implementations/client-app-impl.ts (1)
623-624: LGTM! Proper cleanup of default cookie after custom domain cookie update.After successfully setting a custom domain-based refresh cookie, this code correctly cleans up the default refresh cookie to prevent conflicts. The secure context is properly determined via
isSecureCookieContext(), and the appropriate default cookie name (with or without__Host-prefix) is used for deletion.This change ensures that only one refresh cookie mechanism is active at a time, which prevents confusion and potential race conditions.
packages/template/src/lib/stack-app/apps/implementations/client-app-impl.ts
Show resolved
Hide resolved
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/e2e/tests/js/cookies.test.ts (1)
163-170: Add explicit wait for default cookie deletion to prevent race condition.The test waits for both cookies to be present (lines 163–167), then immediately asserts the default cookie is absent (line 169). There's no guarantee the deletion triggered by the custom cookie write has completed before line 169 executes, which could cause flaky test failures.
Apply this diff to add an explicit wait for the default cookie to be deleted:
const customReady = await waitUntil(() => cookieStore.has(customCookieName), 10_000); expect(customReady).toBe(true); + const defaultDeleted = await waitUntil(() => !cookieStore.has(defaultCookieName), 2_000); + expect(defaultDeleted).toBe(true); + expect(cookieStore.has(defaultCookieName)).toBe(false); expect(cookieStore.has(customCookieName)).toBe(true);
🧹 Nitpick comments (2)
apps/e2e/tests/js/cookies.test.ts (2)
172-172: Rename variable to reflect it stores the custom cookie value.The variable
defaultValuestores the value fromcustomCookieName, which is misleading.Apply this diff:
- const defaultValue = cookieStore.get(customCookieName)!; + const customValue = cookieStore.get(customCookieName)!; - const parsedValue = JSON.parse(decodeURIComponent(defaultValue)); + const parsedValue = JSON.parse(decodeURIComponent(customValue));
185-185: Consider checking expires attribute on the specific custom cookie.The assertion checks if any refresh cookie has an expires attribute but doesn't verify it's specifically the custom cookie. Since you already extract
customAttrson line 183, consider adding a specific check there.Example:
const customAttrs = findCookieAttributes(cookieWrites, customCookieName); expect(customAttrs?.get("domain")).toBe("example.com"); + expect(customAttrs?.has("expires")).toBe(true); - expect(cookieWrites.some((entry) => entry.toLowerCase().startsWith("stack-refresh-") && entry.toLowerCase().includes("expires="))).toBe(true);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
apps/e2e/tests/js/cookies.test.ts(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
- GitHub Check: Vercel Agent Review
- GitHub Check: setup-tests
- GitHub Check: check_prisma_migrations (22.x)
- GitHub Check: build (22.x)
- GitHub Check: lint_and_build (latest)
- GitHub Check: restart-dev-and-test
- GitHub Check: restart-dev-and-test-with-custom-base-port
- GitHub Check: docker
- GitHub Check: all-good
- GitHub Check: build (22.x)
- GitHub Check: build (22.x)
Summary by CodeRabbit
Bug Fixes
Tests