test(session): tamper inside the signature, not its last character
Docker Image bauen und veroeffentlichen / build-and-push (push) Successful in 2m28s

The last base64url character of a 32-byte HMAC signature partly carries
padding bits that decoders ignore, so the tampered token was sometimes
still valid and the test failed at random. Changing a character in the
middle of the signature always alters the signature bytes.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
Nick SzaunigandClaude Opus 5.5 committed 2026-09-27 05:39:09 +02:00
1 parent 0482fd490e
commit 45ca0ea745
1 file changed
+8 -2
+8 -2
View File
@@ -70,8 +70,14 @@ describe("Session-Token", () => {
role: "KUNDE", role: "KUNDE",
sessionVersion: 0, sessionVersion: 0,
}); });
// Letztes Zeichen der Signatur veraendern. // Ein Zeichen MITTEN in der Signatur veraendern. Das letzte Zeichen taugt
const tampered = token.slice(0, -1) + (token.endsWith("A") ? "B" : "A"); // nicht: bei 32 Signaturbytes traegt es in Base64url teils nur Fuellbits,
// die der Decoder ignoriert — der Test schlug dann zufaellig fehl, obwohl
// die Signatur korrekt geprueft wurde.
const signatureStart = token.lastIndexOf(".") + 1;
const position = signatureStart + 10;
const replacement = token[position] === "A" ? "B" : "A";
const tampered = token.slice(0, position) + replacement + token.slice(position + 1);
await expect(verifySessionToken(tampered)).resolves.toBeNull(); await expect(verifySessionToken(tampered)).resolves.toBeNull();
}); });