Skip to content

Commit 736b56b

Browse files
committed
More restrictive VCS URL validation (HTTPS only).
Signed-off-by: ziad hany <ziadhany2016@gmail.com>
1 parent 5a893d1 commit 736b56b

2 files changed

Lines changed: 9 additions & 10 deletions

File tree

scanpipe/pipelines/scan_repo_grimoirelab.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,8 @@ def is_valid_vcs_url(url):
128128
return False
129129

130130
forbidden_chars = ["|", ";", "&", "`", "$(", ">", "<", "&&", "||"]
131-
if any(char in forbidden_chars for char in url):
131+
if any(char in url for char in forbidden_chars):
132132
return False
133133

134134
parsed = urllib.parse.urlparse(url)
135-
valid_schemes = {"https", "git", "ssh", "git+https", "git+ssh"}
136-
if parsed.scheme in valid_schemes and parsed.netloc:
137-
return True
138-
139-
return False
135+
return parsed.scheme == "https" and bool(parsed.netloc)

scanpipe/tests/pipes/test_scan_repo_grimoirelab.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ def test_is_valid_vcs_url(self):
104104
test_cases = [
105105
# Valid URLs
106106
("https://github.com/example/repo.git", True),
107-
("git://github.com/example/repo.git", True),
108-
("ssh://git@github.com/example/repo.git", True),
109-
("git+https://github.com/example/repo.git", True),
110-
("git+ssh://git@github.com/example/repo.git", True),
111107
# Invalid URLs
108+
("git://github.com/example/repo.git", False),
109+
("ssh://git@github.com/example/repo.git", False),
110+
("git+https://github.com/example/repo.git", False),
111+
("git+ssh://git@github.com/example/repo.git", False),
112112
("git@github.com:example/repo.git", False),
113113
("user@localhost:path/to/repo.git", False),
114114
("hg@bitbucket.org:owner/repo", False),
@@ -118,6 +118,9 @@ def test_is_valid_vcs_url(self):
118118
("git@github.com:repo.git\nrm -rf /", False),
119119
("https://github.com/ repo.git", False),
120120
(" https://github.com/repo.git", False),
121+
("https://", False),
122+
("https:///repo.git", False),
123+
("https://?foo=bar", False),
121124
("", False),
122125
(None, False),
123126
]

0 commit comments

Comments
 (0)