test(session): tamper inside the signature, not its last character
Docker Image bauen und veroeffentlichen / build-and-push (push) Successful in 2m28s
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:
1 parent
0482fd490e
commit
45ca0ea745
1 file changed
+8
-2
@@ -70,8 +70,14 @@ describe("Session-Token", () => {
|
||||
role: "KUNDE",
|
||||
sessionVersion: 0,
|
||||
});
|
||||
// Letztes Zeichen der Signatur veraendern.
|
||||
const tampered = token.slice(0, -1) + (token.endsWith("A") ? "B" : "A");
|
||||
// Ein Zeichen MITTEN in der Signatur veraendern. Das letzte Zeichen taugt
|
||||
// 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();
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user