Files
ARTEX/intercept/target_idn_test.go
BaaRai f67f7ef4be fix: close fuzzy fullwidth dot bypass and reject URL chars in intercept 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.
2026-12-02 14:27:13 +01:00

55 lines
2.0 KiB
Go

package intercept
import (
"testing"
"github.com/Autumn-27/artex/db"
)
// The target side (NormalizeTarget) and the rule side
// (db.CanonicalInterceptDomain) canonicalize a name the same way, including the
// ASCII names the IDNA profile refuses and leaves lower-cased as written.
func TestTargetAndRuleCanonicalizationMatch(t *testing.T) {
names := []string{
"example.com", "Example.COM", "bücher.example", "BÜCHER.example",
"xn--bcher-kva.example", "XN--BCHER-KVA.example", "example.com",
"faß.de", "例え.テスト", "_dmarc.example.com", "my_host.internal",
"_bücher.example.com", "xn--_bcher-4ya.example.com", "xn--zz.example.com",
"-a.example.com", "ab--c.example.com", "a\u200bb.com",
}
for _, n := range names {
tg, ok := NormalizeTarget("https://" + n + "/")
if !ok || tg.Kind != TargetDomain {
t.Errorf("NormalizeTarget(%q) = %+v, %v; want a domain", n, tg, ok)
continue
}
if want := db.CanonicalInterceptDomain(n); tg.Host != want {
t.Errorf("%q: target host %q, rule canonical %q", n, tg.Host, want)
}
}
}
// A rule stored in any spelling of a valid name blocks the target written in
// any other spelling of it.
func TestRuleAndTargetSpellingsMeet(t *testing.T) {
groups := [][]string{
{"example.com", "EXAMPLE.com.", "example.com"},
{"bücher.example", "BÜCHER.example", "xn--bcher-kva.example", "XN--BCHER-KVA.EXAMPLE."},
{"_dmarc.example.com", "_DMARC.Example.com."},
}
for _, g := range groups {
for _, ruleSpelling := range g {
rules := []db.AssetInterceptRule{{Enabled: true, Kind: "exact_domain", Pattern: db.CanonicalInterceptDomain(ruleSpelling)}}
for _, targetSpelling := range g {
tg, ok := NormalizeTarget("https://" + targetSpelling + "/")
if !ok || tg.Kind != TargetDomain {
t.Fatalf("NormalizeTarget(%q) = %+v, %v", targetSpelling, tg, ok)
}
if _, hit := blockRule(rules, &checkedTarget{Target: tg}); !hit {
t.Errorf("rule %q (stored %q) misses target %q (normalised %q)", ruleSpelling, rules[0].Pattern, targetSpelling, tg.Host)
}
}
}
}
}