Skip to content

Commit

Permalink
Merge pull request #305 from DataDog/emilehugo.spir/shady-link-false-…
Browse files Browse the repository at this point in the history
…positive

Address some false positives with shady-links
  • Loading branch information
Taiki-San authored Feb 14, 2024
2 parents e44c6ad + b322b98 commit d464501
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 7 additions & 0 deletions guarddog/analyzer/sourcecode/shady-links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@ rules:
patterns:
# Semgrep not robust enough to ignore comments in lists
- pattern-not-regex: \# .*
# Exclude local IPv4 sometimes used in tests
- pattern-not-regex: (http[s]?:\/\/[^/?#]*(?:192\.168|10\.\d{1,3}|172\.(?:1[6-9]|2\d|3[0-1])|127\.\d{1,3})\.\d{1,3}\.\d{1,3})
# TODO: make a rule for long comments
- pattern-either:
- pattern-regex: (http[s]?:\/\/bit\.ly.*)$
- pattern-regex: (http[s]?:\/\/.*\.(link|xyz|tk|ml|ga|cf|gq|pw|top|club|mw|bd|ke|am|sbs|date|quest|cd|bid|cd|ws|icu|cam|uno|email|stream))$
- pattern-regex: (http[s]?:\/\/.*\.(link|xyz|tk|ml|ga|cf|gq|pw|top|club|mw|bd|ke|am|sbs|date|quest|cd|bid|cd|ws|icu|cam|uno|email|stream)\/)
- pattern-regex: (http[s]?:\/\/[^/?#]*(?:\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}))
- pattern-regex: (http[s]?://[^\[/?#]*(?:\[(([A-Fa-f0-9]{1,4}:){0,7}|:):?[A-Fa-f0-9]{1,4}(:[A-Fa-f0-9]{1,4}){0,7})\])
paths:
exclude:
- "*/test/*"
- "*/tests/*"
- "*/test_*"
languages:
- python
- javascript
Expand Down
8 changes: 5 additions & 3 deletions tests/analyzer/sourcecode/shady-links.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
goodlink2 = "https://id.atlassian.com/login?continue=https%3A%2F%2Fstart.atlassian.com%2F&application=start"

# ok: shady-links
goodlink1 = "http://xn--n3h.net//"
goodlink3 = "http://xn--n3h.net//"

# ok: shady-links
goodlink4 = "http://192.168.1.1/"

""" OK: urls with free domain extensions in other parts of link
"""
Expand Down Expand Up @@ -68,7 +70,7 @@
"""

# ruleid: shady-links
req = urllib3.Request("https://127.0.0.1/foo.exe", headers={"User-Agent": os})
req = urllib3.Request("https://128.0.0.1/foo.exe", headers={"User-Agent": os})

# ruleid: shady-links
req = urllib3.Request("https://[email protected]", headers={"User-Agent": os})
Expand All @@ -80,7 +82,7 @@
req = urllib3.Request("https://[email protected]", headers={"User-Agent": os})

# ruleid: shady-links
req = urllib3.Request("https://root:pw@127.0.0.1", headers={"User-Agent": os})
req = urllib3.Request("https://root:pw@128.0.0.1", headers={"User-Agent": os})

""" RULEID: IPv6
"""
Expand Down

0 comments on commit d464501

Please sign in to comment.