mirror of
https://github.com/github/codeql.git
synced 2026-08-03 08:52:55 +02:00
Add javascript/ssrf-ipv6-transition-incomplete-guard, an experimental @kind problem query that flags hand-rolled SSRF host guards which reject private/loopback IPv4 ranges but never unwrap IPv6-transition forms (IPv4-mapped ::ffff:, NAT64 64:ff9b::, 6to4 2002::). Such guards can be bypassed by wrapping an internal IPv4 address in a transition literal. Includes a .qhelp with good/bad examples, a change note, and a test pack with two true-positive fixtures (private-ip package guard and a hand-written RFC 1918 denylist) and two negative-control fixtures (ipaddr.js range classifier and an explicit ::ffff: unwrap). Signed-off-by: tonghuaroot <23011166+tonghuaroot@users.noreply.github.com>
14 lines
446 B
JavaScript
14 lines
446 B
JavaScript
const isPrivate = require('private-ip');
|
|
const fetch = require('node-fetch');
|
|
|
|
// BAD: `private-ip` classifies the textual IPv4 form only. It returns false for
|
|
// `::ffff:169.254.169.254`, so a transition-wrapped internal address slips past.
|
|
async function validateUrlHost(host) { // NOT OK
|
|
if (isPrivate(host)) {
|
|
throw new Error('blocked private host');
|
|
}
|
|
return fetch('http://' + host + '/');
|
|
}
|
|
|
|
module.exports = { validateUrlHost };
|