Skip to content

Commit

Permalink
test: ReDoS vulnerability of UUID regex
Browse files Browse the repository at this point in the history
  • Loading branch information
vbudovski committed Jan 1, 2025
1 parent d2460ce commit bfd84ad
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions paseri-lib/src/schemas/string.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ test('Emoji ReDoS', () => {
expect(diagnostics.status).toBe('safe');
});

test('Valid uuid', () => {
test('Valid UUID', () => {
const schema = p.string().uuid();

fc.assert(
Expand All @@ -252,7 +252,7 @@ test('Valid uuid', () => {
);
});

test('Invalid uuid', () => {
test('Invalid UUID', () => {
const schema = p.string().uuid();

fc.assert(
Expand All @@ -270,6 +270,16 @@ test('Invalid uuid', () => {
);
});

test('UUID ReDoS', () => {
const diagnostics = checkSync(uuidRegex.source, uuidRegex.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('Valid Nano ID', () => {
const schema = p.string().nanoid();
// FIXME: fast-check doesn't like case-insensitive regexes.
Expand Down

0 comments on commit bfd84ad

Please sign in to comment.