#6135·hoppscotch

fix(backend): cookie value truncated when token contains "=" characters in extractCookieAsKeyValuesFromHeaders

Author: kuishou68Created Apr 14, 2026Updated Sep 26, 2026

Problem

In packages/hoppscotch-backend/src/auth/helper.ts, the function extractCookieAsKeyValuesFromHeaders uses curr.split('=') to parse cookie key-value pairs:

typescript
const [key, value] = curr.split('=');
acc[key] = value;

This is incorrect because split('=') splits on every = character. Cookie values such as JWT tokens and base64-encoded strings routinely contain = padding characters. Using array destructuring with only two slots silently discards everything after the first = in the value, so token=abc== becomes { token: "abc" } instead of { token: "abc==" }.

The correct approach is to split only on the first = (using indexOf).

Reproduction

Any request whose access_token or refresh_token cookie value contains one or more = characters will have the token truncated, causing JWT verification to fail and the user to appear unauthenticated.

Note: the sister function subscriptionContextCookieParser uses the cookie npm package which handles this correctly — the manual parser in extractCookieAsKeyValuesFromHeaders does not.

Expected

Cookie values containing = characters should be parsed in full without truncation.

Fix

Replace curr.split('=') with an indexOf-based split so only the first = is used as the delimiter:

typescript
const eqIdx = curr.indexOf('=');
const key   = eqIdx !== -1 ? curr.slice(0, eqIdx) : curr;
const value = eqIdx !== -1 ? curr.slice(eqIdx + 1) : '';
acc[key] = value;