From 3be994c3a383f72aae7cbec167ea43371fe15597 Mon Sep 17 00:00:00 2001 From: Vitaly Budovski Date: Wed, 1 Jan 2025 18:27:21 +1100 Subject: [PATCH] test: ReDoS vulnerability of Nano ID regex --- paseri-lib/src/schemas/string.test.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/paseri-lib/src/schemas/string.test.ts b/paseri-lib/src/schemas/string.test.ts index f5e7b46..777bd9c 100644 --- a/paseri-lib/src/schemas/string.test.ts +++ b/paseri-lib/src/schemas/string.test.ts @@ -316,6 +316,16 @@ test('Invalid Nano ID', () => { ); }); +test('Nano ID ReDoS', () => { + const diagnostics = checkSync(nanoidRegex.source, nanoidRegex.flags); + if (diagnostics.status === 'vulnerable') { + console.log(`Vulnerable pattern: ${diagnostics.attack.pattern}`); + } else if (diagnostics.status === 'unknown') { + console.log(`Error: ${diagnostics.error.kind}.`); + } + expect(diagnostics.status).toBe('safe'); +}); + test('Optional', () => { const schema = p.string().optional();