Skip to content

Commit d558554

Browse files
Reject extra session token segments (#18)
1 parent aa7eb32 commit d558554

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

apps/logicsrc-web/contract/logicsrc-web.contract.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,8 @@ describe("session signing", () => {
376376
process.env.LOGICSRC_SESSION_SECRET = "session_secret_for_tests";
377377
const token = signSession({ provider: "coinpay", sub: "merchant-123" });
378378
expect(verifySession(token)).toMatchObject({ provider: "coinpay", sub: "merchant-123" });
379-
expect(verifySession(`${token}tampered`)).toBeNull();
379+
expect(verifySession(`tampered`)).toBeNull();
380+
expect(verifySession(`.extra`)).toBeNull();
380381
});
381382
});
382383

apps/logicsrc-web/src/lib/coinpay.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ export function signSession(payload: Record<string, unknown>): string {
160160
}
161161

162162
export function verifySession(value: string): Record<string, unknown> | null {
163-
const [encoded, signature] = value.split(".");
163+
const parts = value.split(".");
164+
if (parts.length !== 2) return null;
165+
const [encoded, signature] = parts;
164166
if (!encoded || !signature) return null;
165167

166168
const expected = createHmac("sha256", getSessionSecret()).update(encoded).digest("base64url");

0 commit comments

Comments
 (0)