Skip to content

Commit af0be03

Browse files
Merge pull request #451 from AikidoSec/ulid
Replace ULID identifiers in URL with `:ulid`
2 parents e4eabce + 07af728 commit af0be03

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

library/helpers/buildRouteFromURL.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,14 @@ t.test("it replaces BSON ObjectIDs", async () => {
157157
"/posts/:objectId"
158158
);
159159
});
160+
161+
t.test("it replaces ULID strings", async () => {
162+
t.same(
163+
buildRouteFromURL("/posts/01ARZ3NDEKTSV4RRFFQ69G5FAV"),
164+
"/posts/:ulid"
165+
);
166+
t.same(
167+
buildRouteFromURL("/posts/01arz3ndektsv4rrffq69g5fav"),
168+
"/posts/:ulid"
169+
);
170+
});

library/helpers/buildRouteFromURL.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { isIP } from "net";
55
const UUID =
66
/(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;
77
const OBJECT_ID = /^[0-9a-f]{24}$/i;
8+
const ULID = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
89
const NUMBER = /^\d+$/;
910
const DATE = /^\d{4}-\d{2}-\d{2}|\d{2}-\d{2}-\d{4}$/;
1011
const EMAIL =
@@ -44,6 +45,10 @@ function replaceURLSegmentWithParam(segment: string) {
4445
return ":uuid";
4546
}
4647

48+
if (segment.length === 26 && ULID.test(segment)) {
49+
return ":ulid";
50+
}
51+
4752
if (segment.length === 24 && OBJECT_ID.test(segment)) {
4853
return ":objectId";
4954
}

0 commit comments

Comments
 (0)