Repository navigation
fix(db): match fuzzy_ip asset rules on canonical IP addresses - #954
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
fuzzy_ipasset rules compared the raw strings, so a block rule written::1did not meet0:0:0:0:0:0:0:1or::0001, and an expanded rule missed the compressed form.cidrrules also missed a zone-qualified address, and a zone-qualified IPv6 URL host was classified as a domain, soexact_ip,fuzzy_ipandcidrrules never saw it.Changes
fuzzy_ipnow 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 as10.0.keeps its substring meaning.cidrrules canonicalize beforeContains, sofe80::1%eth0matches its network.insert_assetsand stored assets classify a zone-qualified IPv6 URL host (http://[fe80::1%25eth0]/) as an IP, so all three rule kinds see it.net/netipand never widens a match beyond the rule as written.Tests
db/asset_intercept_match_test.go: both spellings match a::1rule 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 thedbandagenttests pass.