Skip to content

Commit ae06dc0

Browse files
committed
fix(scripts): match the uuid sentinels exactly rather than by shape
Accepting any id built from at most two distinct hex digits let something through that was never on the approved list. A generated id essentially never has that shape, so the practical risk was small — but this check had just stopped being a shape test and become a list, and a structural exception is the one thing that undoes that. The two ids it exists for are the nil and max sentinels, and both are matched by value now.
1 parent 7e83144 commit ae06dc0

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

scripts/check-spec-example-ids.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const UUID_PATTERN = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{1
3333
/**
3434
* Every example UUID the specs are allowed to publish, with what it stands for.
3535
*
36-
* Sentinels are covered structurally by {@link isSentinel} and are not listed here.
36+
* The nil and max UUIDs are covered by {@link SENTINELS} and are not listed here.
3737
*/
3838
const APPROVED: Record<string, string> = {
3939
'0f7c1a2e-9b3d-4c58-8a21-6d4e5f7a9b01': 'run id in the RUN_ID_CONFLICT error example',
@@ -56,18 +56,17 @@ const APPROVED: Record<string, string> = {
5656
}
5757

5858
/**
59-
* All-zero and all-f sentinels read as synthetic on sight.
59+
* The two UUIDs RFC 9562 reserves as sentinels: nil and max.
6060
*
61-
* Unlike a texture score this admits no real id even in principle: fewer than three distinct hex
62-
* digits across all 32 positions has probability on the order of 1e-27, so the family can be
63-
* covered by shape rather than enumerated one nil-UUID variant at a time.
64-
*
65-
* Takes an already-lowercased id: hex is case-insensitive, so counting `A` and `a` as two digits
66-
* would inflate the distinct count and admit ids this is meant to reject.
61+
* Matched exactly rather than by shape. An earlier version accepted any id built from at most
62+
* two distinct hex digits, which is astronomically unlikely for a generated id but is still a
63+
* bypass of the approved list — and this check exists to be a list, not a shape test. Both
64+
* values are used by the resources spec today.
6765
*/
68-
function isSentinel(uuid: string): boolean {
69-
return new Set(uuid.replace(/-/g, '')).size <= 2
70-
}
66+
const SENTINELS = new Set([
67+
'00000000-0000-0000-0000-000000000000',
68+
'ffffffff-ffff-ffff-ffff-ffffffffffff',
69+
])
7170

7271
const specFiles = readdirSync(SPEC_DIR)
7372
.filter((file) => file.startsWith('openapi') && file.endsWith('.json'))
@@ -80,7 +79,7 @@ for (const file of specFiles) {
8079
const seen = new Set(contents.match(UUID_PATTERN) ?? [])
8180
for (const uuid of [...seen].sort()) {
8281
const normalized = uuid.toLowerCase()
83-
if (normalized in APPROVED || isSentinel(normalized)) continue
82+
if (normalized in APPROVED || SENTINELS.has(normalized)) continue
8483
findings.push(` - ${file}: ${uuid}`)
8584
}
8685
}

0 commit comments

Comments
 (0)