Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion vtex/utils/cookies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,22 @@ function parseSingleSetCookie(raw: string): Cookie | null {
value: nameValue.slice(eqIdx + 1),
};
for (const attr of attrs) {
const [k, v] = attr.split("=").map((s) => s.trim());
const eqi = attr.indexOf("=");
const k = (eqi >= 0 ? attr.slice(0, eqi) : attr).trim();
const v = eqi >= 0 ? attr.slice(eqi + 1).trim() : "";
const lower = k.toLowerCase();
if (lower === "domain") cookie.domain = v;
else if (lower === "path") cookie.path = v;
else if (lower === "secure") cookie.secure = true;
else if (lower === "httponly") cookie.httpOnly = true;
else if (lower === "samesite") cookie.sameSite = v as Cookie["sameSite"];
else if (lower === "max-age") {
const n = Number(v);
if (!Number.isNaN(n)) cookie.maxAge = n;
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot Mar 24, 2026

Choose a reason for hiding this comment

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

P1: Max-Age parsing treats an empty/missing value as 0 (Number("")), which can incorrectly expire cookies. Validate that the value is present and numeric before assigning cookie.maxAge.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At vtex/utils/cookies.ts, line 34:

<comment>`Max-Age` parsing treats an empty/missing value as `0` (`Number("")`), which can incorrectly expire cookies. Validate that the value is present and numeric before assigning `cookie.maxAge`.</comment>

<file context>
@@ -20,13 +20,22 @@ function parseSingleSetCookie(raw: string): Cookie | null {
 		else if (lower === "samesite") cookie.sameSite = v as Cookie["sameSite"];
+		else if (lower === "max-age") {
+			const n = Number(v);
+			if (!Number.isNaN(n)) cookie.maxAge = n;
+		} else if (lower === "expires") {
+			const d = new Date(v);
</file context>
Suggested change
if (!Number.isNaN(n)) cookie.maxAge = n;
if (v !== "" && Number.isInteger(n)) cookie.maxAge = n;
Fix with Cubic

} else if (lower === "expires") {
const d = new Date(v);
if (!Number.isNaN(d.getTime())) cookie.expires = d;
}
}
return cookie;
}
Expand Down
Loading