Peng.ly Security

Server-side request forgery high 7.5

fast-uri vulnerable to server-side request forgery via repeated hostname percent-decoding

A hostname that's percent-encoded twice gets decoded twice, so a URL that looks harmless can still send the request to localhost or a cloud metadata address.

fast-uri
Affected >= 2.4.1, < 2.4.5 Patched 2.4.5
fast-uri
Affected >= 3.1.2, < 3.1.6 Patched 3.1.6
fast-uri
Affected >= 4.0.0, < 4.1.3 Patched 4.1.3

Published · 2 min read

Summary

parse() decodes the host at index.js:375 and re-escapes only / : ? # @. recomposeAuthority() decodes it again at lib/utils.js:552, so other double-encoded bytes become live characters in the authority, . and \ being the ones that matter. normalize(), serialize(), equal() and resolve() can then return an authority the input never named.

It's an incomplete fix of CVE-2026-6322, whose fix covered the five delimiters rather than the second decode itself. Happy for this to land on that advisory instead if you'd rather.

Proof of concept

const uri = require('fast-uri') // 4.1.2

uri.resolve('https://allowed.com/api/v1/', '//169%252E254%252E169%252E254/latest/meta-data/')
// 'https://169.254.169.254/latest/meta-data/'

resolve() is the awkward one: it returns a plain string, never throws, and has no error field to check.

It also shows up without involving a second parser, just fast-uri disagreeing with itself:

const out = uri.normalize('http://allowed.com%255Cevil.com/')
// 'http://allowed.com\evil.com/'

uri.parse(out).error
// 'URI authority must not contain a literal backslash.'

A literal backslash there is what you fixed in 4.1.1 for CVE-2026-16221.

Caveat

On http/https/ws/wss, parse() does set .error on that first input, because the % makes the internal new URL() throw, so anything checking that flag is fine on that path. The gap is that normalize(), serialize() and equal() don't check it (index.js:425 and :438 only bail on malformedAuthorityOrPort), and resolve() has nowhere to report it.

Impact

ajv resolves every $ref against the schema's $id. With ajv 8.20.0 and a $ref of //169%252E254%252E169%252E254/latest/meta-data/, which contains no literal IP, loadSchema() was asked to fetch https://169.254.169.254/latest/meta-data/. That's ajv doing as it's told with the resolver's output rather than a bug in ajv.

Two others in the same file, probably unrelated

Canonicalisation (index.js:356-367) runs before the decode (index.js:369-377), so normalize() isn't idempotent on the authority: http://0177.0.0%0D.1/ becomes http://0177.0.0\r.1/, then http://127.0.0.1/. A raw \r is caught, just not the encoded form.

getIPV6's final flush (lib/utils.js:137-145) pushes stringArrayToHexStripped(buffer) without checking it, and that returns '' on failure, where consumeHextets at :80-92 does check. So parse('http://[::1zz]/').host is :: with no error set, and equal('http://[::1zz]/', 'http://[::]/') is true. [::1zz] isn't a valid IP-literal under RFC 3986.

Reproduced on 2.4.4, 3.1.5 and every 4.x up to 4.1.2. Happy to test a patch.

Patches

Fixed in fast-uri 2.4.5, 3.1.6, and 4.1.3.

Workarounds

Reject untrusted URIs whose host component contains an encoded percent sign (%25) before passing them to normalize() or resolve().