Skip to content

Commit 29ddb23

Browse files
authored
Merge pull request #399 from parthlambdatest/Dot-6319
[Dot-6319] Rectify the logic of custom cookies
2 parents a33ba23 + 58be3f9 commit 29ddb23

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/lib/processSnapshot.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ const ALLOWED_STATUSES = [200, 201];
1212
const REQUEST_TIMEOUT = 1800000;
1313
const MIN_VIEWPORT_HEIGHT = 1080;
1414

15+
const normalizeSameSite = (value) => {
16+
if (!value) return 'Lax';
17+
18+
const normalized = value.trim().toLowerCase();
19+
const mapping = {
20+
'lax': 'Lax',
21+
'strict': 'Strict',
22+
'none': 'None'
23+
};
24+
25+
return mapping[normalized] || value;
26+
};
27+
1528
export async function prepareSnapshot(snapshot: Snapshot, ctx: Context): Promise<Record<string, any>> {
1629
let processedOptions: Record<string, any> = {};
1730
processedOptions.cliEnableJavascript = ctx.config.cliEnableJavaScript;
@@ -257,11 +270,11 @@ export default async function processSnapshot(snapshot: Snapshot, ctx: Context):
257270
return false;
258271
}
259272

260-
if (cookie.sameSite && !['Strict', 'Lax', 'None'].includes(cookie.sameSite)) {
273+
const sameSiteValue = normalizeSameSite(cookie.sameSite);
274+
if (!['Strict', 'Lax', 'None'].includes(sameSiteValue)) {
261275
ctx.log.debug(`Skipping invalid custom cookie: invalid sameSite value '${cookie.sameSite}'`);
262276
return false;
263277
}
264-
265278
return true;
266279
}).map(cookie => ({
267280
name: cookie.name,
@@ -270,7 +283,7 @@ export default async function processSnapshot(snapshot: Snapshot, ctx: Context):
270283
path: cookie.path || '/',
271284
httpOnly: cookie.httpOnly || false,
272285
secure: cookie.secure || false,
273-
sameSite: cookie.sameSite || 'Lax'
286+
sameSite: normalizeSameSite(cookie.sameSite)
274287
}));
275288

276289
if (validCustomCookies.length > 0) {

0 commit comments

Comments
 (0)