class ICU::SpoofChecker

Overview

Identifier Spoofing & Confusability

ICU::SpoofChecker detects whether identifiers (usernames, domain names, source code symbols, etc.) are visually confusable with one another, or contain characters that could be used in spoofing attacks.

Two strings are confusable if a casual observer might mistake one for the other (e.g. the Cyrillic "а" vs the Latin "a"). The checker can also validate that an identifier is safe — drawn from a single script, using only recommended characters, etc.

Usage

sc = ICU::SpoofChecker.new

sc.confusable?("paypal", "рaypal") # => true  (Cyrillic "р")
sc.safe?("hello")                  # => true
sc.safe?("ℋello")                  # => false  (mixed script)

sc.skeleton("рaypal") == sc.skeleton("paypal") # => true

See also

Defined in:

icu/spoof_checker.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new #

[View source]

Class Method Detail

def self.inclusion_set : Set(Char) #

Returns the inclusion set: the set of characters that are explicitly allowed to appear in identifiers regardless of other restrictions.

The returned set is not owned by this checker.


[View source]
def self.recommended_set : Set(Char) #

Returns the recommended set: the set of characters recommended by Unicode TR#39 for use in identifiers.

The returned set is not owned by this checker.


[View source]

Instance Method Detail

def allowed_locales : String #

Returns the comma-separated list of allowed locales, or an empty string if no locale restriction is set.


[View source]
def allowed_locales=(locales : String) #

Restricts the set of allowed characters to those belonging to the given comma-separated list of locale script(s).

sc.allowed_locales = "en, fr"

[View source]
def bidi_confusable?(s1 : String, s2 : String, direction : Direction) : Bool #

Returns true if s1 and s2 are BiDi-confusable in the given direction.


[View source]
def bidi_skeleton(text : String, direction : Direction) : String #

Returns the BiDi skeleton of text for the given direction.


[View source]
def check(text : String, result : CheckResult) : Int32 #

Runs all enabled spoof checks on text, populating result with detailed information, and returns the bitmask of failed checks.

result = ICU::SpoofChecker::CheckResult.new
sc.check("hello", result)
result.restriction_level # => ICU::SpoofChecker::RestrictionLevel::Ascii

[View source]
def check(text : String) : Int32 #

Runs all enabled spoof checks on text and returns the bitmask of failed checks (0 means the text passed all checks).

sc.check("hello") # => 0
sc.check("ℋello") # => non-zero

[View source]
def checks : Int32 #

Returns the bitmask of checks currently enabled on this checker.


[View source]
def checks=(value : Int32) #

Sets the checks to perform. Pass a combination of Check flags.

sc.checks = ICU::SpoofChecker::Check::Invisible | ICU::SpoofChecker::Check::MixedNumbers

[View source]
def confusable?(s1 : String, s2 : String) : Bool #

Returns true if s1 and s2 are visually confusable with one another.

sc.confusable?("paypal", "рaypal") # => true  (Cyrillic "р")
sc.confusable?("hello", "world")   # => false

[View source]
def finalize #

[View source]
def restriction_level : RestrictionLevel #

Returns the restriction level currently configured on this checker.


[View source]
def restriction_level=(level : RestrictionLevel) #

Sets the restriction level.

sc.restriction_level = ICU::SpoofChecker::RestrictionLevel::HighlyRestrictive

[View source]
def safe?(text : String) : Bool #

Returns true if text passes all enabled spoof checks.

sc.safe?("hello") # => true
sc.safe?("ℋello") # => false

[View source]
def skeleton(text : String) : String #

Returns the skeleton of text — a canonicalized form used to detect confusable pairs. Two strings are confusable if and only if their skeletons are equal.

sc.skeleton("рaypal") == sc.skeleton("paypal") # => true

[View source]
def to_unsafe : LibICU::USpoofChecker #

[View source]