Preview: GCM-Tag-Laenge fest, Inhalt validiert

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Sonnet 5.5 committed 2026-09-30 21:53:41 +00:00
1 parent 20ca1de694
commit def490ceca
2 files changed
+31 -3

No files matched your search

+22
View File
@@ -79,3 +79,25 @@ test('maskLog', () => {
assert.equal(maskLog('', env), '')
assert.equal(maskLog('text', {}), 'text')
})
test('gekuerzter Tag, falsche IV-Laenge, manipulierter Ciphertext => Fehler', () => {
const p = encryptEnv({ A: 'geheim' }, key).split(':')
const b = (i) => Buffer.from(p[i], 'base64')
const join = (x) => x.join(':')
const short = [...p]; short[2] = b(2).subarray(0, 8).toString('base64')
assert.throws(() => decryptEnv(join(short), key))
const iv = [...p]; iv[1] = b(1).subarray(0, 8).toString('base64')
assert.throws(() => decryptEnv(join(iv), key))
const ct = [...p]; const c = b(3); c[0] ^= 1; ct[3] = c.toString('base64')
assert.throws(() => decryptEnv(join(ct), key))
})
test('entschluesselter Inhalt muss Objekt mit String-Werten sein', () => {
for (const bad of [['x'], 'text', { A: 1 }, null]) {
const iv = crypto.randomBytes(12)
const c = crypto.createCipheriv('aes-256-gcm', key, iv, { authTagLength: 16 })
const ct = Buffer.concat([c.update(JSON.stringify(bad), 'utf8'), c.final()])
const s = ['v1', iv, c.getAuthTag(), ct].map((x) => (typeof x === 'string' ? x : x.toString('base64'))).join(':')
assert.throws(() => decryptEnv(s, key))
}
})