Class: GemGuard::TyposquatChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/gem_guard/typosquat_checker.rb

Constant Summary collapse

3600
SIMILARITY_THRESHOLD =
0.8
1_000_000

Instance Method Summary collapse

Constructor Details

#initializeTyposquatChecker

Returns a new instance of TyposquatChecker.



11
12
13
14
# File 'lib/gem_guard/typosquat_checker.rb', line 11

def initialize
  @popular_gems_cache = nil
  @cache_timestamp = nil
end

Instance Method Details

#check_dependencies(dependencies) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/gem_guard/typosquat_checker.rb', line 16

def check_dependencies(dependencies)
  suspicious_gems = []
  popular_gems = fetch_popular_gems

  dependencies.each do |dependency|
    suspicious_match = find_suspicious_match(dependency.name, popular_gems)
    if suspicious_match
      suspicious_gems << {
        gem_name: dependency.name,
        version: dependency.version,
        suspected_target: suspicious_match[:name],
        similarity_score: suspicious_match[:similarity],
        target_downloads: suspicious_match[:downloads],
        risk_level: calculate_risk_level(suspicious_match[:similarity])
      }
    end
  end

  suspicious_gems
end