Skip to content

Commit 32930c2

Browse files
committed
fix(sandbox,podman): reject empty port after bracketed IPv6 proxy host
http://[fd00::1]: passed the explicit-port check because the bracketed branch only tested for a colon after the bracket, then fell back to port 80 — violating the fail-closed http://host:port contract and potentially sending configured Basic credentials to an unintended service. Require a non-empty suffix after ]:, matching the unbracketed branch, and cover the case in the shared parser tests. Signed-off-by: Philippe Martin <[email protected]>
1 parent 5617bcf commit 32930c2

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

‎crates/openshell-core/src/driver_utils.rs‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,13 @@ fn authority_has_explicit_port(raw: &str) -> bool {
223223
.rsplit_once(':')
224224
.is_some_and(|(_, port)| !port.is_empty())
225225
},
226-
// Bracketed IPv6 literal: a port can only follow the bracket.
227-
|end| host_port[end + 1..].starts_with(':'),
226+
// Bracketed IPv6 literal: a port can only follow the bracket, and a
227+
// bare trailing `]:` is no more explicit than no port at all.
228+
|end| {
229+
host_port[end + 1..]
230+
.strip_prefix(':')
231+
.is_some_and(|port| !port.is_empty())
232+
},
228233
)
229234
}
230235

@@ -404,6 +409,7 @@ mod tests {
404409
"http://proxy.corp.com/",
405410
"http://proxy.corp.com:",
406411
"http://[fd00::1]",
412+
"http://[fd00::1]:",
407413
] {
408414
assert_eq!(
409415
parse_upstream_proxy_url(url),

0 commit comments

Comments
 (0)