feat: add Homoglyph and KeyboardAdjacent checks#8
Open
andrew wants to merge 1 commit into
Open
Conversation
Adds two checks for documented typosquatting attack vectors: - Homoglyph: visually similar character substitution (1↔l, 0↔o, rn↔m, vv↔w, etc). Catches attacks like 1odash→lodash and r3quests→requests. - KeyboardAdjacent: single-character replacement with physically adjacent QWERTY keys. Catches attacks like requezts→requests. Both ship with default lookup tables and accept custom tables via new(). Both use char_indices()/len_utf8() so they are safe on non-ASCII package names. Closes rustfoundation#7
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.
Adds two checks for typosquatting vectors that have shown up in real attacks across npm and PyPI.
Homoglyphsubstitutes visually similar characters. Covers single-character confusables (1↔l,0↔o,5↔s) and multi-character sequences that render like a single glyph (rn↔m,vv↔w,cl↔d). Catches1odash→lodash,r3quests→requests.KeyboardAdjacentreplaces single characters with physically adjacent QWERTY keys. Distinct fromTyposin that it's systematic rather than a curated misspelling list. Catchesrequezts/requeats→requests.Both ship with default tables via
Defaultand accept custom tables vianew()(e.g. for non-QWERTY layouts). Both iterate withchar_indices()andlen_utf8()so they don't add to the UTF-8 concerns in #4.I haven't added them to the default
Harness::builder()set since that would change behaviour for existing users, though neither needs ecosystem-specific config so they'd qualify. Happy to add if preferred.Closes #7