Skip to content

Commit 69a33bc

Browse files
committed
feat: implement typosquatting detection for package names
Adds a new security analysis feature to detect potential typosquatting in package names. Compares the package name against a list of popular packages using the Jaro-Winkler similarity algorithm. Packages exceeding a configurable threshold are flagged. Includes a default popular package list and an option for a custom list via configuration. Signed-off-by: Amine <[email protected]>
1 parent 428d5e9 commit 69a33bc

File tree

1 file changed

+37
-37
lines changed

1 file changed

+37
-37
lines changed

src/macaron/malware_analyzer/pypi_heuristics/metadata/typosquatting_presence.py

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -27,43 +27,43 @@ def __init__(self) -> None:
2727
self.scaling = 0.15
2828
self.keyboard = 0.8
2929
self.keyboard_layout = {
30-
"1": (-1, 0),
31-
"2": (-1, 1),
32-
"3": (-1, 2),
33-
"4": (-1, 3),
34-
"5": (-1, 4),
35-
"6": (-1, 5),
36-
"7": (-1, 6),
37-
"8": (-1, 7),
38-
"9": (-1, 8),
39-
"0": (-1, 9),
40-
"-": (-1, 10),
41-
"q": (0, 0),
42-
"w": (0, 1),
43-
"e": (0, 2),
44-
"r": (0, 3),
45-
"t": (0, 4),
46-
"y": (0, 5),
47-
"u": (0, 6),
48-
"i": (0, 7),
49-
"o": (0, 8),
50-
"p": (0, 9),
51-
"a": (1, 0),
52-
"s": (1, 1),
53-
"d": (1, 2),
54-
"f": (1, 3),
55-
"g": (1, 4),
56-
"h": (1, 5),
57-
"j": (1, 6),
58-
"k": (1, 7),
59-
"l": (1, 8),
60-
"z": (2, 0),
61-
"x": (2, 1),
62-
"c": (2, 2),
63-
"v": (2, 3),
64-
"b": (2, 4),
65-
"n": (2, 5),
66-
"m": (2, 6),
30+
"1": (0, 0),
31+
"2": (0, 1),
32+
"3": (0, 2),
33+
"4": (0, 3),
34+
"5": (0, 4),
35+
"6": (0, 5),
36+
"7": (0, 6),
37+
"8": (0, 7),
38+
"9": (0, 8),
39+
"0": (0, 9),
40+
"-": (0, 10),
41+
"q": (1, 0),
42+
"w": (1, 1),
43+
"e": (1, 2),
44+
"r": (1, 3),
45+
"t": (1, 4),
46+
"y": (1, 5),
47+
"u": (1, 6),
48+
"i": (1, 7),
49+
"o": (1, 8),
50+
"p": (1, 9),
51+
"a": (2, 0),
52+
"s": (2, 1),
53+
"d": (2, 2),
54+
"f": (2, 3),
55+
"g": (2, 4),
56+
"h": (2, 5),
57+
"j": (2, 6),
58+
"k": (2, 7),
59+
"l": (2, 8),
60+
"z": (3, 0),
61+
"x": (3, 1),
62+
"c": (3, 2),
63+
"v": (3, 3),
64+
"b": (3, 4),
65+
"n": (3, 5),
66+
"m": (3, 6),
6767
}
6868

6969
if global_config.popular_packages_path is not None:

0 commit comments

Comments
 (0)