Skip to content

fix(db): match fuzzy_ip asset rules on canonical IP addresses - #954

Merged
BaaRai merged 1 commit into
mainfrom
fix/asset-block-ipv6-forms
Dec 3, 2026
Merged

BaaRai merged 1 commit into
mainfrom
fix/asset-block-ipv6-forms

Conversation

@BaaRai

@BaaRai BaaRai commented Dec 3, 2026

Copy link
Copy Markdown
Owner

Summary

fuzzy_ip asset rules compared the raw strings, so a block rule written ::1 did not meet 0:0:0:0:0:0:0:1 or ::0001, and an expanded rule missed the compressed form. cidr rules also missed a zone-qualified address, and a zone-qualified IPv6 URL host was classified as a domain, so exact_ip, fuzzy_ip and cidr rules never saw it.

Changes

  • fuzzy_ip now matches the address as written and its canonical form: zeros compressed, lower case, IPv4-mapped addresses unmapped, zone dropped. A pattern that is a whole address is canonicalized too; a partial pattern such as 10.0. keeps its substring meaning.
  • cidr rules canonicalize before Contains, so fe80::1%eth0 matches its network.
  • insert_assets and stored assets classify a zone-qualified IPv6 URL host (http://[fe80::1%25eth0]/) as an IP, so all three rule kinds see it.
  • Canonicalization uses net/netip and never widens a match beyond the rule as written.

Tests

  • db/asset_intercept_match_test.go: both spellings match a ::1 rule and the reverse; partial patterns keep substring matching; zone-qualified CIDR and host cases.
  • agent/insert_assets_test.go: a rule blocks the expanded and compressed spellings; the zone-qualified URL host is classified as an IP.
  • go build ./... and the db and agent tests pass.

A fuzzy_ip rule compared the raw strings, so a block rule "::1" let
insert_assets register "0:0:0:0:0:0:0:1" or "::0001", and a rule
written expanded missed the compressed address. Match each candidate
as written and in its canonical form, and canonicalize a pattern that
is a whole address; a partial pattern keeps its substring meaning.

cidr rules now also match a zone-qualified address, and a
zone-qualified IPv6 URL host is classified as an IP in insert_assets
and for stored assets, so exact_ip, fuzzy_ip and cidr rules see it.
@BaaRai
BaaRai merged commit dcffc35 into main Dec 3, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant