Skip to content

Commit 92fe6f0

Browse files
TMHSDigitalclaude
andcommitted
fix(scan): accept IDN -exclude patterns and match them in punycode (#152)
Targets are converted to punycode, but -exclude patterns were validated as typed, so 'mail.bücher.de' was rejected and users had to hand-write the xn-- form. Normalize patterns with the same punycode conversion before validating and matching; a "*." prefix passes through unchanged. Fixes #152 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LpkeXSPwrzd7ZCuX3no7gD
1 parent a776076 commit 92fe6f0

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

‎internal/scan/scope.go‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,15 @@ type scope struct {
1515
suffixes []string // "*.x" patterns, stored as "x"
1616
}
1717

18+
// normalizePattern puts a pattern in the form targets are scanned in:
19+
// lowercase, no trailing dot, IDNs in punycode (#152). A pattern that cannot
20+
// be converted is left as is, so ValidateExcludes rejects it.
1821
func normalizePattern(p string) string {
19-
return strings.ToLower(strings.TrimSuffix(strings.TrimSpace(p), "."))
22+
n := strings.ToLower(strings.TrimSuffix(strings.TrimSpace(p), "."))
23+
if ascii, err := validate.ToASCII(n); err == nil {
24+
return ascii
25+
}
26+
return n
2027
}
2128

2229
// ValidateExcludes checks that every pattern is a domain or *.domain.

‎internal/scan/scope_test.go‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,25 @@ func TestScopeMatching(t *testing.T) {
3434
}
3535
}
3636

37+
// TestScopeIDNPatterns covers #152: IDN patterns are accepted and matched in
38+
// punycode, as targets are scanned.
39+
func TestScopeIDNPatterns(t *testing.T) {
40+
patterns := []string{"mail.bücher.de", "*.dev.Bücher.de"}
41+
if err := ValidateExcludes(patterns); err != nil {
42+
t.Fatalf("ValidateExcludes rejected IDN patterns: %v", err)
43+
}
44+
sc := newScope(patterns)
45+
for name, want := range map[string]bool{
46+
"mail.xn--bcher-kva.de": true,
47+
"api.dev.xn--bcher-kva.de": true,
48+
"www.xn--bcher-kva.de": false,
49+
} {
50+
if got := sc.excluded(name); got != want {
51+
t.Errorf("excluded(%q) = %v, want %v", name, got, want)
52+
}
53+
}
54+
}
55+
3756
// TestRunExcludeSendsNoQueriesInBranch is #87's done-when: a recursive scan
3857
// with -exclude '*.dev.example.com' never queries under that branch, wildcard
3958
// probes included, and accounts for the excluded candidates.

‎internal/validate/punycode.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ const (
1717
pcInitialN = 128
1818
)
1919

20+
// ToASCII converts a lowercased name to its punycode form, as NormalizeDomain
21+
// does for targets; ASCII labels, including a "*" wildcard, pass through.
22+
func ToASCII(name string) (string, error) { return toASCII(name) }
23+
2024
// toASCII converts a lowercased domain to its ASCII (A-label) form: every
2125
// label with non-ASCII characters becomes "xn--" plus its Punycode encoding.
2226
// It implements only the RFC 3492 encoder, not full UTS #46 mapping, which

0 commit comments

Comments
 (0)