Skip to content

Commit

Permalink
fix: linting
Browse files Browse the repository at this point in the history
Signed-off-by: Bryce Thuilot <[email protected]>
  • Loading branch information
bthuilot committed Oct 30, 2024
1 parent 7de87f4 commit ca9c9fa
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions guarddog/analyzer/metadata/go/typosquatting.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import json
import os
from datetime import datetime, timedelta
from typing import Optional

from guarddog.analyzer.metadata.typosquatting import TyposquatDetector
from guarddog.utils.config import TOP_PACKAGES_CACHE_LOCATION
# import requests


class GoTyposquatDetector(TyposquatDetector):
"""Detector for typosquatting attacks for go modules. Checks for distance one Levenshtein, one-off character swaps, permutations
around hyphens, and substrings.
"""Detector for typosquatting attacks for go modules. Checks for distance one Levenshtein,
one-off character swaps, permutations around hyphens, and substrings.
Attributes:
popular_packages (set): set of top 500 most popular Go packages,
Expand All @@ -20,7 +18,7 @@ class GoTyposquatDetector(TyposquatDetector):
def _get_top_packages(self) -> set:

# popular_packages_url = (
# "" #TODO
# ""
# )

top_packages_filename = "top_go_packages.json"
Expand Down Expand Up @@ -48,6 +46,10 @@ def _get_top_packages(self) -> set:
# with open(top_packages_path, "w+") as f:
# json.dump(top_packages_information, f, ensure_ascii=False, indent=4)

if top_packages_information is None:
raise Exception(
f"Could not retrieve top Go packages from {top_packages_path}")

return set(top_packages_information)

def detect(
Expand Down Expand Up @@ -95,15 +97,15 @@ def _get_confused_forms(self, package_name) -> list:
confused_forms = []

if package_name.startswith("github.com/"):
confused_forms.append(package_name.replace("github.com/", "gitlab.com/", 1))
replaced = package_name.replace("github.com/", "gitlab.com/", 1)
confused_forms.append(replaced)
elif package_name.startswith("gitlab.com/"):
confused_forms.append(package_name.replace("gitlab.com/", "github.com/", 1))


replaced = package_name.replace("gitlab.com/", "github.com/", 1)
confused_forms.append(replaced)

terms = package_name.split("-")

# Detect swaps like python-package -> py-package
# Detect swaps like golang-package -> go-package
for i in range(len(terms)):
confused_term = None

Expand Down

0 comments on commit ca9c9fa

Please sign in to comment.