Skip to content

Commit 745183c

Browse files
UlisesGasconmcollina
authored andcommitted
test: cover first-segment colon in suffix references
Ref: GHSA-333x-w4r6-6crp
1 parent ddfc6a5 commit 745183c

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

‎test/reserved-path-normalization.test.js‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,31 @@ test('equal distinguishes escaped reserved path data from literal syntax', (t) =
107107
)
108108
t.end()
109109
})
110+
111+
// A suffix reference never emits its scheme token, so it is a scheme-less
112+
// (path-noscheme) reference: a bare ':' in its first path segment must be
113+
// escaped, or the serialized output reparses as an absolute URI with a scheme.
114+
// @see https://github.com/fastify/fast-uri/security/advisories/GHSA-333x-w4r6-6crp
115+
test('suffix reference escapes a first-segment colon instead of emitting a scheme', (t) => {
116+
const dangerous = /^(?:javascript|data|vbscript):/i
117+
const options = { reference: 'suffix', scheme: 'x' }
118+
119+
for (const input of ['javascript:alert(1)', '%6Aavascript:alert(1)', 'data:text/html,x', 'vbscript:msgbox(1)']) {
120+
t.notOk(dangerous.test(fastURI.normalize(input, options)), `${input} normalizes to an inert reference`)
121+
}
122+
123+
t.equal(
124+
fastURI.normalize('javascript:alert(1)', options),
125+
'javascript%3Aalert(1)',
126+
'escapes the leading-segment colon to %3A'
127+
)
128+
t.notOk(
129+
dangerous.test(fastURI.resolve('https://a.example/base/', '%6Aavascript:alert(1)', { reference: 'suffix' })),
130+
'resolve in suffix mode does not emit a live scheme'
131+
)
132+
133+
// legitimate suffix usage is unchanged
134+
t.equal(fastURI.normalize('path/to/file', options), 'path/to/file', 'plain path unchanged')
135+
t.equal(fastURI.normalize('a/b:c', options), 'a/b:c', 'colon in a later segment stays literal')
136+
t.end()
137+
})

0 commit comments

Comments
 (0)