Packages / fast-uri / Security
fast-uri vulnerable to URI scheme spoofing via percent-encoded scheme decoding
Affected releases · fast-uri
- 4.x4.0.0 – 4.2.2Fixed in 4.2.3
- 3.x3.0.0 – 3.1.8Fixed in 3.1.9
- 2.x2.0.0 – 2.4.7Fixed in 2.4.8
- 1.x and older0.0.1 – 1.0.1No fix, no longer updated
On 4.x, the newest line:
npm install fast-uri@4.2.3Every release on a timeline
Affected
4.0.0 – 4.2.2
11 releases
Fixed
4.2.3
1 release, latest
Affected
3.0.0 – 3.1.8
16 releases
Fixed
3.1.9
1 release
Affected
2.0.0 – 2.4.7
13 releases
Fixed
2.4.8
1 release
Affected
1.0.0 – 1.0.1
2 releases
Affected
0.0.1 – 0.0.2
2 releases
What happens
Impact
fast-uri percent-decodes the scheme component with the legacy global unescape() before validating it, so an input whose decoded scheme is a valid but dangerous token is emitted as a live scheme. RFC 3986 section 3.1 does not allow percent-encoding in a scheme, so no RFC or WHATWG parser treats such input as having that scheme, but fast-uri does.
For example, normalize('%6Aavascript:alert(1)') returns javascript:alert(1), resolve('https://a.example/', '%6Aavascript:alert(1)') returns javascript:alert(1), and parse('%6Aavascript:alert(1)').scheme returns javascript. The %uXXXX form (%u006Aavascript:) produces the same result, and equal('%68ttp://a/', 'http://a/') returns true.
An application that screens dangerous schemes on the raw input and then stores or renders normalize(input) or resolve(base, input) turns an inert string into an executable javascript:, data:, or vbscript: URL, a stored or reflected cross-site scripting vector in the consuming application. equal() also treats an encoded and a plain scheme as the same, which can bypass equality-based allowlists.
Patches
Upgrade to fast-uri 2.4.8, 3.1.9, or 4.2.3.
Workarounds
Reject input whose scheme part (before the first :, and before any /, ?, or #) contains %. Alternatively, check parse(x).scheme against an allowlist after normalization and use that same parsed result rather than the raw string.
A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.