Skip to content

Commit 09d1d3a

Browse files
authored
refactor: hostname matching allows subdomain bypass via ends_with (#1468)
The url_match() function uses `host.ends_with(entry.host())` to match hostnames. This allows an attacker to bypass the allowlist: if "example.com" is allowed, then "notexample.com", "evilexample.com", or "notexample.com.evil.com" would ALL match because "notexample.com".ends_with("example.com") is true. This is a critical security flaw in a runtime designed for Lambda/serverless workloads. Affected files: security.rs Signed-off-by: hieuit095 <139037144+hieuit095@users.noreply.github.com>
1 parent 5f9674c commit 09d1d3a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

modules/llrt_fetch/src/security.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ fn url_match(list: &[Uri], uri: &Uri) -> bool {
5858
let host = uri.host().unwrap_or_default();
5959
let port = uri.port_u16().unwrap_or(80);
6060
list.iter().any(|entry| {
61-
host.ends_with(entry.host().unwrap_or_default()) && entry.port_u16().unwrap_or(80) == port
61+
let entry_host = entry.host().unwrap_or_default();
62+
let port_match = entry.port_u16().unwrap_or(80) == port;
63+
let host_match = host == entry_host || host.ends_with(&format!(".{}", entry_host));
64+
port_match && host_match
6265
})
6366
}

0 commit comments

Comments
 (0)