-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
url.startswith("https://prefix") -> url.startswith("https://prefix/")
- Loading branch information
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
assets/semgrep_rules/services/starts-with-partial-host-py.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# ruleid: starts-with-partial-host-py | ||
my_urI[0].startswith("https://x.y") | ||
|
||
# ruleid: starts-with-partial-host-py | ||
request.url.startswith('https://example.com') | ||
|
||
# ruleid: starts-with-partial-host-py | ||
url.startswith('http://127.0.0.1:') | ||
|
||
# ok: starts-with-partial-host-py | ||
url.startswith("https://ba.na/x") | ||
|
||
# ok: starts-with-partial-host-py | ||
url.startswith("https://") | ||
|
||
# ok: starts-with-partial-host-py | ||
url.startswith("xyz://abc/https://def") |
20 changes: 20 additions & 0 deletions
20
assets/semgrep_rules/services/starts-with-partial-host-py.yaml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
rules: | ||
- id: starts-with-partial-host-py | ||
metadata: | ||
author: Ben Caller | ||
confidence: LOW | ||
source: https://github.com/brave/security-action/blob/main/assets/semgrep_rules/services/starts-with-partial-host-py.yaml | ||
patterns: | ||
- pattern: $URL.startswith("$PREFIX") | ||
- metavariable-regex: | ||
metavariable: $PREFIX | ||
regex: (?i)^https?://[^/]+$ | ||
- metavariable-regex: | ||
# Avoid false positives where we actually have an origin or hostname | ||
metavariable: $URL | ||
regex: (?i).*ur[li].* | ||
message: | | ||
Add a forward-slash at the end to prevent matching `$PREFIX.e.vil` or `$PREFIX@e.vil`. | ||
Even better, properly parse the URL and match a list of origins/hosts. | ||
languages: [python] | ||
severity: WARNING |