Skip to content

Commit 6f1fcbf

Browse files
committed
Rust: Add IPv6 private address range (and explanatory comments).
1 parent 7c22fe2 commit 6f1fcbf

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

rust/ql/lib/codeql/rust/security/UseOfHttpExtensions.qll

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@ module UseOfHttp {
3636
class HttpStringLiteral extends StringLiteralExpr {
3737
HttpStringLiteral() {
3838
exists(string s | this.getTextValue() = s |
39-
// Match HTTP URLs that are not private/local
39+
// match HTTP URLs
4040
s.regexpMatch("(?i)\"http://.*\"") and
41-
not s.regexpMatch("(?i)\"http://(localhost|127\\.0\\.0\\.1|192\\.168\\.[0-9]+\\.[0-9]+|10\\.[0-9]+\\.[0-9]+\\.[0-9]+|172\\.(1[6-9]|2[0-9]|3[01])\\.[0-9]+|\\[::1\\]|\\[0:0:0:0:0:0:0:1\\]).*\"")
41+
// exclude private/local addresses:
42+
// - IPv4: localhost / 127.0.0.1, 192.168.x.x, 10.x.x.x, 172.16.x.x -> 172.31.x.x
43+
// - IPv6 (address inside []): ::1 (or 0:0:0:0:0:0:0:1), fc00::/7 (i.e. anything beginning `fcxx:` or `fdxx:`)
44+
not s.regexpMatch("(?i)\"http://(localhost|127\\.0\\.0\\.1|192\\.168\\.[0-9]+\\.[0-9]+|10\\.[0-9]+\\.[0-9]+\\.[0-9]+|172\\.(1[6-9]|2[0-9]|3[01])\\.[0-9]+|\\[::1\\]|\\[0:0:0:0:0:0:0:1\\]|\\[f[cd][0-9a-f]{2}:.*\\]).*\"")
4245
)
4346
}
4447
}

0 commit comments

Comments
 (0)