Skip to content

Commit 0133703

Browse files
chrisbbreuerclaude
andcommitted
test(router): stop a 3-char needle finding itself in ciphertext
`set() writes an encrypted envelope` proves the secret does not survive encryption by searching the serialized envelope for it. The secret was `'shh'`, and the envelope is base64, so the assertion fails whenever those three characters turn up in the ciphertext by chance. CI found one: Expected to not contain: "shh" Received: "{\"_enc\":true,...\"data\":\"...BeQ2BD2anBrrdtGevHshhdI...\"}" `vHshhdI`. The envelope was encrypted correctly and the test that proves it encrypted failed anyway. Roughly 1 run in 1300 for a three-character needle across ~200 base64 characters, which is frequent enough to keep costing someone an afternoon and rare enough to be dismissed as "just re-run it" every time. The secret is now long and distinctive, which makes a chance collision impossible rather than unlikely. The assertion is otherwise unchanged. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 18d0716 commit 0133703

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

storage/framework/core/router/tests/encrypted-session-store.test.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,22 @@ describe('EncryptedSessionStore (stacksjs/stacks#1878 Se-4)', () => {
5555
})
5656

5757
test('set() writes an encrypted envelope; raw store does NOT have plaintext', async () => {
58-
await store.set('sid-1', { id: 'sid-1', userId: 42, secret: 'shh' } as any)
58+
/*
59+
* A long, distinctive secret on purpose. This was `'shh'`, and the
60+
* assertion below is a substring search over base64 ciphertext - where a
61+
* three-character needle turns up by chance roughly once in a thousand
62+
* runs. CI found one: `...BeQ2BD2anBrrdtGevHshhdI...` contains `shh`, so a
63+
* correctly encrypted envelope failed the test that proves it encrypted.
64+
*/
65+
const secret = 'plaintext-that-must-never-survive-encryption'
66+
await store.set('sid-1', { id: 'sid-1', userId: 42, secret } as any)
5967

6068
const raw = inner.store.get('sid-1') as Record<string, unknown>
6169
expect(raw._enc).toBe(true)
6270
expect(typeof raw.data).toBe('string')
63-
// The plaintext "shh" must not appear anywhere in the envelope
71+
// The plaintext must not appear anywhere in the envelope
6472
// (a quick "did we forget to encrypt something" check).
65-
expect(JSON.stringify(raw)).not.toContain('shh')
73+
expect(JSON.stringify(raw)).not.toContain(secret)
6674
})
6775

6876
test('get() decrypts back to the original payload', async () => {

0 commit comments

Comments
 (0)