Repository navigation
Conversation
exact_domain and domain_suffix patterns are now checked before they are stored: whitespace or control characters, empty labels (including more than one trailing dot), a single label, an IP literal or all-digit last label, and a non-ASCII or xn-- label the IDNA profile refuses are answered 400 on the global and task rule APIs. fuzzy_domain refuses whitespace, control characters and a doubled dot. Valid domains keep the canonical form they had, and CanonicalInterceptDomain stays lenient for matching. intercept/target.go now uses idna.Lookup, the profile the rules use. The previous profile had the same options in x/net v0.62.0; its comment said it accepted underscore labels, which it did not.
…pt domains A fuzzy_domain pattern written with ideographic or fullwidth dots became a doubled dot only after canonicalisation, so "a。。example.com" was stored as "a..example.com" and "example.com.." as "example.com..". Check the canonical form as well. ValidInterceptDomain now rejects "*", "/" and ":" too: exact_domain accepted "https://example.com" and "*.example.com", which were stored and never matched. Replace the tautological IDN test, which compared hostProfile with itself, with a NormalizeTarget versus db.CanonicalInterceptDomain comparison, and cover task rule create and update in the PostgreSQL API test.
BaaRai
marked this pull request as ready for review
December 2, 2026 13:52
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.
Follow-up to #782 on the validation of domain patterns in asset interception rules, and on the IDN profile shared by the rule side and the target side.
What and why
db.CanonicalInterceptDomainis the comparison form of both a stored rule and a target. It never refuses a name, which is right for matching (a malformed target must still meet the rules: the built-in fuzzy.gov.cnmust still hitx..gov.cn), but the rule APIs also used it as their only check before storing a pattern. So malformed patterns were stored in a form no target ever has, and the rule silently matched nothing:exact_domainexample.com..example.com.exact_domaina..example.coma..example.comexact_domaina b.example.com,a\tb...,a\x00b...exact_domaincom/domain_suffix*.comcomexact_domain192.0.2.1,2001:db8::1,127.1exact_ip/cidr)exact_domain_bücher.example.com_bücher.example.com(Unicode)exact_domainhttps://example.com,*.example.com,example.com:443fuzzy_domaina..b,.gov .cnfuzzy_domaina。。example.com,example.com..a..example.com,example.com..The check is a new function,
db.ValidInterceptDomain, called at storage time byvalidateAssetInterceptRuleReq(anddb.ValidDomainSuffixPattern/db.ValidFuzzyDomainPattern).CanonicalInterceptDomainitself is unchanged and stays lenient for matching. For an accepted pattern, the stored value is always exactly whatCanonicalInterceptDomainreturned before (the tests assert it).For
exact_domainanddomain_suffix(after the*./.prefix of a suffix is dropped), it refuses:127.1, which the intercept layer reads as an address in a URL host);*,/,:):exact_domainused to accepthttps://example.com,*.example.comandexample.com:443, all of which matched no target;xn--label, that the IDNA profile refuses.fuzzy_domainis a substring, so leading/trailing dots and single labels stay valid (.gov,.gov.cn,example, the built-in rules); it refuses whitespace, control characters and a doubled dot, including the ideographic and fullwidth dots once canonicalisation turns them into..Decisions
Trailing dots: refuse, not normalize. One trailing dot is the DNS root and stays accepted (
Example.COM.is still stored asexample.com). A second one is an empty label, not a spelling of the same name; resolvers refuse it, andintercept.normalizeHostdrops only one dot. Normalizing every trailing dot would hide a typo and add a spelling rule that the target side does not have; refusing keeps one rule ("no empty label") for the leading, inner and trailing cases.TLD-wide suffix rules: refused. A single label is meaningless as an
exact_domain, and as adomain_suffixit covers a whole TLD. Both are refused, so adomain_suffixrule names an organisation or a site, not a public suffix.fuzzy_domainremains the substring escape hatch, with its false positives documented.URL and wildcard characters: refused.
exact_domainanddomain_suffixtake a host name. Acceptinghttps://example.comorexample.com:443stored a rule that could never match, and hid a copy-paste mistake behind a silent no-op.IDN profile: aligned on
idna.Lookup, and the underscore limit documented.intercept/target.gousedidna.New(idna.MapForLookup(), idna.BidiRule()), with a comment saying it avoided the strict rules that refuse an underscore label. In the pinnedgolang.org/x/net v0.62.0,MapForLookup()setsStrictDomainName(true)(STD3) andValidateLabels(true), so that profile has the same options asidna.Lookup(transitionalLookupisfalse). A probe over 37 names (underscore, uppercase, fullwidth, Unicode, punycode, invalid punycode, hyphen rules, ZWJ, bidi, IPs, wildcards) gave the same output and the same refusals for both profiles.target.gonow usesidna.Lookup, the profile the rule side,db/company_scope.goandegress/egress.goalready use, so they cannot drift if x/net changes one of them; the wrong comment is fixed, and the comments on both sides now say how underscores are handled.Behaviour that follows, unchanged by this PR except where noted:
_. An ASCII name is then compared lower-cased as written on both sides (_DMARC.Example.comand_dmarc.example.commeet). Lower-casing is all the profile does to ASCII, so this is not ambiguous, and such patterns stay accepted. The same goes for the hyphen-rule refusals (ab--c,-a).EXAMPLE.com->example.com), same as before.bücher.example->xn--bcher-kva.example), same as before. Changed: a non-ASCII name that the profile refuses (for example_bücher.example.com) was stored as Unicode, while the same target written in punycode stays punycode, so the rule missed it. It has no single canonical spelling and is now refused.xn--label is kept, as before. Changed: anxn--label that the profile refuses (invalid punycode, or the punycode of an underscore label) is now refused, for the same reason.Callers checked
db/asset_intercept_match.go:matchOne(exact_domain,domain_suffixviaDomainSuffixPattern,fuzzy_domain) callsCanonicalInterceptDomainon both sides. Unchanged, still lenient.server/asset_intercept.govalidateAssetInterceptRuleReq: the only write-side caller. It is used byPOST/PUT /api/asset-intercept/rules, byserver/task_intercept.go(validateTaskInterceptRuleReq:POST/PUT /api/tasks/{id}/intercept-rules, andbuildTaskInterceptRulesfor task creation inserver/server.goand task templates inserver/task_templates.go). All of them answer 400 before any database write.intercept/target.go(normalizeHost) andintercept/target_gate.go(blockRule, URL rules): target side, matching only. The block-only target gate is not touched.agent/tools_insert.go: reads and matches rules (ListAssetInterceptRules,TaskInterceptRulesSplit), never writes them. No agent tool creates asset interception rules.server/orchestration.go: a spawned child task copies the stored block rules of the calling task as they are. They are not checked again, so an old malformed row is copied rather than dropped (dropping a block rule would fail open).server/sandbox.go: reads storedexact_domain/domain_suffixallow rules as scope domains. A single-labeldomain_suffixallow rule (com) can no longer be created.Tests
Table-driven:
db/asset_intercept_domain_valid_test.go: refusals (32 cases, includinghttps://example.com,example.com:443,foo*.example.com,a。。example.com,example.com..), a regression table of 24 valid domains whose output must equalCanonicalInterceptDomain(subdomains, uppercase, single trailing dot, Unicode, punycode, fullwidth, underscore, hyphen-rule names),domain_suffixandfuzzy_domaintables.db/asset_intercept_canonical_test.go:CanonicalInterceptDomainoutput unchanged, and it is still lenient for malformed targets.server/asset_intercept_validate_test.go: refusals on the API validator for the three kinds, valid domains unchanged, task rules (block and allow) andbuildTaskInterceptRules.server/asset_intercept_domain_pg_test.go(PostgreSQL):POST /api/asset-intercept/rulesanswers 400 for malformed patterns and stores nothing, a valid one is stored canonical, a malformedPUTis refused and leaves the row. The same file now also covers task rules on a real task:POST /api/tasks/{id}/intercept-ruleswith a valid domain returns 200 and stores the canonical form, a malformedPUTreturns 400 and leaves the row, and a validPUTreturns 200 and canonicalises.intercept/target_idn_test.go:TestTargetAndRuleCanonicalizationMatchcomparesNormalizeTargetwithdb.CanonicalInterceptDomainon 17 names (Unicode, fullwidth, punycode valid and invalid, underscores, hyphen rules, ZWSP);TestRuleAndTargetSpellingsMeetchecks that a rule stored in any spelling of a valid name blocks the target written in any other spelling of it.RED on the base, with the new tests that compile there (
8f91643, the main tip when the branch was cut; the branch was then rebased one38f58d, which changes no file this diff touches except one CHANGELOG line next to the new entry):The db validator tests do not build on the base (
undefined: ValidInterceptDomain). Guards that already pass on the base and must keep passing:TestValidateAssetInterceptRuleKeepsValidDomains,TestCanonicalInterceptDomainUnchanged,TestRuleAndTargetSpellingsMeet, and the existingTestValidateAssetInterceptRuleCanonicalizes.GREEN on the branch, on PostgreSQL 16 in CI and in the audit environment, with go1.26.11:
The
*AsRoottests need real root and skip in a non-root environment; the diff touches no file or symbol related toexecpriv, isolation, rundir or spill. No test was skipped in the suites above, and the PG test ran.Not verified / limits
0x1(0x7f.0x1) is not recognized as an IPv4 form. Out of scope here.