Skip to content

Commit ca0e80b

Browse files
committed
Stop guessing the SCM host from the Socket diff URL
get_manifest_file_url fell back to substring-matching diff.diff_url for "github"/"gitlab"/"bitbucket" when config had no scm. CliConfig always sets scm, and without a config there is no repository_url to use, so the guess never affected a link. diff_url also points at Socket rather than the SCM. Remove the branch so only config picks the SCM, which clears the CodeQL incomplete-URL-substring-sanitization alert.
1 parent 866a462 commit ca0e80b

2 files changed

Lines changed: 20 additions & 10 deletions

File tree

‎socketsecurity/core/messages.py‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,10 @@ def get_manifest_file_url(diff: Diff, manifest_path: str, config=None) -> str:
7878
# Remove leading slashes
7979
clean_path = clean_path.lstrip('/')
8080

81-
# Determine SCM type from config or diff_url
82-
scm_type = "api" # Default to API
81+
# diff.diff_url points at Socket, not the SCM, so only config decides.
82+
scm_type = "api"
8383
if config and hasattr(config, 'scm'):
8484
scm_type = config.scm.lower()
85-
elif hasattr(diff, 'diff_url') and diff.diff_url:
86-
diff_url = diff.diff_url.lower()
87-
if 'github.com' in diff_url or 'github' in diff_url:
88-
scm_type = "github"
89-
elif 'gitlab' in diff_url:
90-
scm_type = "gitlab"
91-
elif 'bitbucket' in diff_url:
92-
scm_type = "bitbucket"
9385

9486
# Generate URL based on SCM type using config information
9587
# NEVER use diff.diff_url for SCM URLs - those are Socket URLs for "View report" links

‎tests/unit/test_messages.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,21 @@ def test_manifest_link_falls_back_to_the_report_without_a_repository_url():
102102
url = Messages.get_manifest_file_url(diff, "app/package.json", config)
103103

104104
assert url == "https://socket.dev/report/123?tab=files&file=app%2Fpackage.json"
105+
106+
107+
108+
def test_manifest_link_does_not_guess_the_scm_from_the_diff_url():
109+
"""Without an explicit scm, a GitHub-looking diff_url falls back to the report."""
110+
111+
class _NoScmConfig:
112+
branch = "main"
113+
repository_url = "https://github.com/acme/widgets"
114+
115+
diff = Diff(
116+
diff_url="https://github.com/acme/widgets/pull/1",
117+
report_url="https://socket.dev/report/123",
118+
)
119+
120+
url = Messages.get_manifest_file_url(diff, "app/package.json", _NoScmConfig())
121+
122+
assert url == "https://socket.dev/report/123?tab=files&file=app%2Fpackage.json"

0 commit comments

Comments
 (0)