Skip to content

policy: normalize HTTP schemes, host casing, and default ports - #4068

Open
crazy-max wants to merge 4 commits into
docker:masterfrom
crazy-max:policy-http-host-default-ports
Open

policy: normalize HTTP schemes, host casing, and default ports#4068
crazy-max wants to merge 4 commits into
docker:masterfrom
crazy-max:policy-http-host-default-ports

Conversation

@crazy-max

@crazy-max crazy-max commented Sep 9, 2026

Copy link
Copy Markdown
Member

fixes #4061
closes #4065

Normalize HTTP policy input so hostname allowlists match requests regardless of scheme casing, host casing, or explicit default ports, including curl requests through the exec proxy. Strip :80 for HTTP and :443 for HTTPS, including zero-padded forms, while preserving non-default ports, IPv6 brackets and zone casing, and the original URL. Existing policies matching explicit default ports or mixed-case hostnames must use the normalized host instead.

This supersedes #4065, retaining its original commit and adding simplified normalization, case handling, and regression coverage through source conversion and policy evaluation.

@crazy-max crazy-max added this to the v0.38.0 milestone Sep 9, 2026
@crazy-max
crazy-max force-pushed the policy-http-host-default-ports branch from c672b54 to a84a5a3 Compare September 9, 2026 09:51
@crazy-max
crazy-max requested a review from tonistiigi September 9, 2026 09:52
@crazy-max
crazy-max marked this pull request as ready for review September 9, 2026 10:02

@thaJeztah thaJeztah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably squash the commits; if you amend the original commit, it still keeps the author (if we think it's worth preserving), so that's fine.

I left some suggestions for things we're currently missing.

Comment thread policy/validate.go Outdated
Comment thread policy/validate.go
g := &Git{
Schema: u.Scheme,
Remote: u.Remote,
Host: u.Host,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably need to normalize Git URLs as well? i.e.; https://github.com:443/docker/buildx.git or https://github.com:000443/docker/buildx.git would also need normalising.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes agreed that Git over HTTP(S) should use the same normalization. I'd prefer to handle that in a follow-up, covering both remote URL paths and ensuring SSH/SCP remotes retain their existing behavior.

Comment thread policy/validate_test.go
Comment thread policy/validate_test.go
Comment thread policy/validate_test.go
locker95 and others added 3 commits September 10, 2026 14:41
curl and similar tools include :443/:80 on the request URL. Policy then
sees input.http.host as example.com:443, so an allow-list of example.com
misses it. Drop those well-known ports; leave any other port in place.

Signed-off-by: Dean Chen <862469039@qq.com>
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
@crazy-max
crazy-max force-pushed the policy-http-host-default-ports branch from a84a5a3 to f4567ef Compare September 10, 2026 12:59
@crazy-max crazy-max changed the title policy: normalize default ports in HTTP policy hosts policy: normalize HTTP schemes, host casing, and default ports Sep 10, 2026
Comment thread policy/validate.go Outdated
Comment thread policy/validate.go Outdated
Comment thread policy/validate_test.go
{"https", "[2001:db8::1]", "[2001:db8::1]"},
{"https", "[2001:DB8::ABCD]:443", "[2001:db8::abcd]"},
{"https", "[FE80::ABCD%Eth0]:000443", "[fe80::abcd%Eth0]"},
{"https", "[FE80::ABCD%Eth0]:8443", "[fe80::abcd%Eth0]:8443"},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my other comment; this is an invalid address, and would be rejected.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test constructs url.URL{Host: ...} directly, so the decoded %Eth0 is intentional. The https-ipv6-zone-case-preserved source-conversion test separately parses a URL containing %25Eth0 and verifies the decoded host.

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OPA policies should normalize input.http.host for well-known ports

3 participants