homographic_spoofing 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -1
- data/lib/homographic_spoofing/detector/idn.rb +29 -20
- data/lib/homographic_spoofing/detector/rule/idn/context.rb +0 -3
- data/lib/homographic_spoofing/detector/rule/idn/invisible_characters.rb +13 -7
- data/lib/homographic_spoofing/detector/rule/idn/script_confusable.rb +3 -3
- data/lib/homographic_spoofing/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b77c0ab0cf0c9038f582094e8ed8ebff8b36ca3b8284e585feadaf2c85c75e74
|
|
4
|
+
data.tar.gz: f0197f1aef78bb508a33273ecf17d95b8f89b679885e6a7b653d1f3370970741
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: aa87401952a3e3852042903e487b7fd609bc802c622a87605482dcb9f37d1f3c04d927ba23274a0150a36adebcb4fba89813011918a9b96ec00946f6f77000a8
|
|
7
|
+
data.tar.gz: 9d4b87e917910eaed057d5bc16be329d5e79fdf2f4df43854732aa10e729a57634418bed8e4dc4f3bffb748d9dbe80a1a6793f2e98842e75b7afa75028399612
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.2.1] - 2026-11-26
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- Check the label directly under a wildcard public suffix, such as `раураӏ` in `раураӏ.mm` or `раураӏ.sch.uk`, and every label below it. These names were skipped entirely.
|
|
15
|
+
- Treat U+04AF (`ү`, Cyrillic straight u) as a Latin `y` look-alike, so whole-Cyrillic labels such as `үеѕ` are flagged like `уеѕ`.
|
|
16
|
+
- Stop allowing whole-Cyrillic look-alike labels under `pyc`, which is not a TLD.
|
|
17
|
+
- Flag a nonspacing mark that appears twice in one run of marks once the label is decomposed, such as `é` followed by U+0301, and flag a run of more than 30 marks.
|
|
18
|
+
- Ignore private public-suffix entries when splitting a domain, so names such as `раураӏ.compute.amazonaws.com` are checked like any other name.
|
|
19
|
+
|
|
10
20
|
## [0.2.0] - 2026-10-20
|
|
11
21
|
|
|
12
22
|
### Changed
|
|
@@ -49,7 +59,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
49
59
|
- Initial release: detect and sanitize homographic spoofing attacks in URLs and
|
|
50
60
|
email addresses.
|
|
51
61
|
|
|
52
|
-
[Unreleased]: https://github.com/basecamp/homographic_spoofing/compare/v0.2.
|
|
62
|
+
[Unreleased]: https://github.com/basecamp/homographic_spoofing/compare/v0.2.1...HEAD
|
|
63
|
+
[0.2.1]: https://github.com/basecamp/homographic_spoofing/compare/v0.2.0...v0.2.1
|
|
53
64
|
[0.2.0]: https://github.com/basecamp/homographic_spoofing/compare/v0.1.2...v0.2.0
|
|
54
65
|
[0.1.2]: https://github.com/basecamp/homographic_spoofing/compare/v0.1.1...v0.1.2
|
|
55
66
|
[0.1.1]: https://github.com/basecamp/homographic_spoofing/compare/v0.1.0...v0.1.1
|
|
@@ -83,45 +83,54 @@ class HomographicSpoofing::Detector::Idn
|
|
|
83
83
|
end
|
|
84
84
|
|
|
85
85
|
def contexts
|
|
86
|
-
|
|
86
|
+
tld_allowances = {}
|
|
87
87
|
labels.map do |label, occurrence|
|
|
88
|
-
HomographicSpoofing::Detector::Rule::Idn::Context.new(label:, tld
|
|
88
|
+
HomographicSpoofing::Detector::Rule::Idn::Context.new(label:, tld: registry_suffix, occurrence:, tld_allowances:)
|
|
89
89
|
end
|
|
90
90
|
end
|
|
91
91
|
|
|
92
|
-
#
|
|
93
|
-
#
|
|
94
|
-
#
|
|
95
|
-
#
|
|
96
|
-
#
|
|
97
|
-
#
|
|
92
|
+
# Every label left of the registry suffix, split on the same dot the
|
|
93
|
+
# renderer draws so each rule sees one real label rather than a chain. The
|
|
94
|
+
# mixed-script, confusable and digit rules are per-label: a combined chain
|
|
95
|
+
# both hides attacks (a benign sibling dilutes an all-look-alike label out of
|
|
96
|
+
# detection) and invents them (two single-script sibling labels look "mixed"
|
|
97
|
+
# together though each is safe on its own).
|
|
98
98
|
#
|
|
99
99
|
# Labels are kept in left-to-right domain order and paired with the index of
|
|
100
100
|
# their occurrence among identical labels, so a repeated label recovers the
|
|
101
101
|
# casing of its own position (see #original_case).
|
|
102
102
|
def labels
|
|
103
|
-
ordered = [ *public_suffix.trd&.split("."), public_suffix.sld ].compact.reject(&:empty?)
|
|
104
103
|
seen = Hash.new(0)
|
|
105
|
-
|
|
104
|
+
split_domain.last.reject(&:empty?).map do |label|
|
|
106
105
|
occurrence = seen[label]
|
|
107
106
|
seen[label] += 1
|
|
108
107
|
[ label, occurrence ]
|
|
109
108
|
end
|
|
110
109
|
end
|
|
111
110
|
|
|
112
|
-
def
|
|
113
|
-
|
|
111
|
+
def registry_suffix
|
|
112
|
+
split_domain.first
|
|
114
113
|
end
|
|
115
114
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
115
|
+
# Splits the domain into the suffix its registry controls and the labels to
|
|
116
|
+
# its left. Unlike PublicSuffix.parse:
|
|
117
|
+
# - The label a wildcard entry matches (раураӏ in раураӏ.mm, under *.mm) is
|
|
118
|
+
# not fixed by the registry, so it is checked like any other label, and
|
|
119
|
+
# the registry suffix is only the part the entry spells out (mm).
|
|
120
|
+
# - A domain that is itself a public suffix (co.uk, mm) has no label to
|
|
121
|
+
# check, and is not an error.
|
|
122
|
+
# - Private entries (github.io, *.compute.amazonaws.com) are ignored, so
|
|
123
|
+
# names under them are checked like any other name.
|
|
124
|
+
def split_domain
|
|
125
|
+
@split_domain ||= begin
|
|
126
|
+
name = PublicSuffix.normalize(domain)
|
|
127
|
+
raise name if name.is_a?(PublicSuffix::DomainInvalid)
|
|
119
128
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
PublicSuffix
|
|
123
|
-
|
|
124
|
-
|
|
129
|
+
rule = PublicSuffix::List.default.find(name, default: nil, ignore_private: true)
|
|
130
|
+
# Unknown TLD: the default rule applies, and a single label is invalid.
|
|
131
|
+
registry_suffix = rule ? rule.parts.join(".") : PublicSuffix.parse(name, ignore_private: true).tld
|
|
132
|
+
left = name.delete_suffix(registry_suffix).delete_suffix(".")
|
|
133
|
+
[ registry_suffix, left.split(".", -1) ]
|
|
125
134
|
end
|
|
126
135
|
end
|
|
127
136
|
end
|
|
@@ -3,9 +3,6 @@ class HomographicSpoofing::Detector::Rule::Idn::Context < HomographicSpoofing::D
|
|
|
3
3
|
|
|
4
4
|
# `tld_allowances` is shared by every label of one domain, so a decision that
|
|
5
5
|
# depends only on the TLD is made once per domain rather than once per label.
|
|
6
|
-
# Under a wildcard suffix such as "*.mm" the TLD carries a label the sender
|
|
7
|
-
# chose, and scanning it again for every label would cost the label count
|
|
8
|
-
# times its length.
|
|
9
6
|
def initialize(label:, tld:, occurrence: 0, tld_allowances: {})
|
|
10
7
|
@tld = tld
|
|
11
8
|
@tld_allowances = tld_allowances
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
# 7. of Google Chrome IDN policy
|
|
2
2
|
class HomographicSpoofing::Detector::Rule::Idn::InvisibleCharacters < HomographicSpoofing::Detector::Rule::Idn::Base
|
|
3
3
|
def attack_detected?
|
|
4
|
-
|
|
4
|
+
COMBINING_MARK_AT_START.match?(label) || LONG_MARK_RUN.match?(label) || repeated_nonspacing_mark?
|
|
5
5
|
end
|
|
6
6
|
|
|
7
7
|
private
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
COMBINING_MARK_AT_START = /\A\p{M}/
|
|
9
|
+
|
|
10
|
+
# More marks in a row than UAX #15's Stream-Safe Text Format allows (30).
|
|
11
|
+
# Checked before decomposing, which on some Rubies takes time quadratic in
|
|
12
|
+
# the length of a run of marks.
|
|
13
|
+
LONG_MARK_RUN = /\p{M}{31,}/
|
|
14
|
+
|
|
15
|
+
# Decomposed first, so a precomposed letter followed by its own mark, such
|
|
16
|
+
# as "é" + U+0301, counts as the mark repeated.
|
|
17
|
+
def repeated_nonspacing_mark?
|
|
18
|
+
!label.ascii_only? && label.unicode_normalize(:nfd).scan(/\p{Mn}+/).any? { |marks| marks.chars.uniq.size < marks.size }
|
|
19
|
+
end
|
|
14
20
|
end
|
|
@@ -15,7 +15,7 @@ class HomographicSpoofing::Detector::Rule::Idn::ScriptConfusable < HomographicSp
|
|
|
15
15
|
# Armenian
|
|
16
16
|
[ /\p{armn}/, /[ագզէլհյոսւօՙ]/, /am/ ],
|
|
17
17
|
# Cyrillic
|
|
18
|
-
[ /\p{cyrl}/, /[
|
|
18
|
+
[ /\p{cyrl}/, /[аысԁеԍһіюјӏорԗԛѕԝхуүъьҽпгѵѡ]/, /bg|by|kz|ru|su|ua|uz/ ],
|
|
19
19
|
# # Ethiopic (Ge'ez).
|
|
20
20
|
[ /\p{ethi}/, /[ሀሠሰስበነተከዐዕዘጠፐꬅ]/, /er|et/ ],
|
|
21
21
|
# # Georgian
|
|
@@ -43,7 +43,7 @@ class HomographicSpoofing::Detector::Rule::Idn::ScriptConfusable < HomographicSp
|
|
|
43
43
|
# # Telugu
|
|
44
44
|
[ /\p{Telu}/, /[౦౧]/, nil ],
|
|
45
45
|
# # Myanmar
|
|
46
|
-
[ /\p{Mymr}/, /[ခဂငထပဝ၀၂ၔၜ\u1090\u1091\u1095\u1096\u1097]/, /
|
|
46
|
+
[ /\p{Mymr}/, /[ခဂငထပဝ၀၂ၔၜ\u1090\u1091\u1095\u1096\u1097]/, /mm/ ],
|
|
47
47
|
# # Thai
|
|
48
48
|
[ /\p{Thai}/, /[ทนบพรหเแ๐ดลปฟม]/, /th/ ]
|
|
49
49
|
]
|
|
@@ -52,7 +52,7 @@ class HomographicSpoofing::Detector::Rule::Idn::ScriptConfusable < HomographicSp
|
|
|
52
52
|
# `/su/` matched `.surf`, `/by/` matched `.baby`/`.rugby`, etc., silently
|
|
53
53
|
# disabling single-script confusable detection on those TLDs. The
|
|
54
54
|
# `(?:\A|\.)…\z` boundary keeps multi-label public suffixes working —
|
|
55
|
-
# `co.th` still matches `/th/`, `com.mm` still matches `/
|
|
55
|
+
# `co.th` still matches `/th/`, `com.mm` still matches `/mm/`.
|
|
56
56
|
.map do |script, latin_lookalike, allowed_tlds|
|
|
57
57
|
anchored_tlds = allowed_tlds && /(?:\A|\.)(?:#{allowed_tlds.source})\z/
|
|
58
58
|
Confusable.new script, latin_lookalike, anchored_tlds
|