Skip to content

Commit ff7ae5a

Browse files
leliaclaude
andcommitted
fix(gitlab): warn when a Maven coordinate has no namespace
An ecosystem with its own URL separator cannot be addressed without both halves of the coordinate. A Maven artifact that arrives with no groupId still gets a link so the finding reports, but that link cannot resolve, and previously it was emitted silently. It now logs a warning naming the package. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent c5fcbc8 commit ff7ae5a

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

socketsecurity/core/classes.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import logging
23
from dataclasses import dataclass, field
34
from typing import Dict, List, Optional, TypedDict
45

@@ -11,6 +12,8 @@
1112
SocketScore,
1213
)
1314

15+
log = logging.getLogger("socketdev")
16+
1417
# Separator between namespace and name in a socket.dev package URL. Socket addresses
1518
# Maven artifacts as "groupId:artifactId" -- the slash form 404s, and the dashboard's
1619
# Maven handler raises "Maven package must have a colon" on it. Every other ecosystem
@@ -180,6 +183,15 @@ def socket_url(package_type, namespace: Optional[str], name: str, version: str)
180183
package_type = Package.normalize_type(package_type)
181184
namespace = (namespace or "").strip("/")
182185
separator = URL_NAMESPACE_SEPARATORS.get(package_type, "/")
186+
if separator != "/" and not namespace:
187+
# An ecosystem with its own separator cannot be addressed without the
188+
# namespace half of the coordinate. The link is emitted anyway so the
189+
# finding still reports, but it will not resolve.
190+
log.warning(
191+
f"{package_type} package {name}@{version} has no namespace, so its "
192+
f"Socket link cannot use the '{separator}' separator the dashboard "
193+
"requires and will not resolve"
194+
)
183195
package_path = f"{namespace}{separator}{name}" if namespace else name
184196
return f"https://socket.dev/{package_type}/package/{package_path}/overview/{version}"
185197

tests/core/test_package_and_alerts.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,22 @@ def test_non_maven_package_url_keeps_slash_separator(self):
157157
unscoped = Package.socket_url("nuget", None, "newtonsoft.json", "6.0.8")
158158
assert unscoped == "https://socket.dev/nuget/package/newtonsoft.json/overview/6.0.8"
159159

160+
def test_maven_package_without_namespace_warns(self, caplog):
161+
"""A Maven coordinate missing its groupId cannot produce a resolvable link"""
162+
with caplog.at_level("WARNING", logger="socketdev"):
163+
url = Package.socket_url("maven", None, "orphan-artifact", "1.0.0")
164+
165+
assert url == "https://socket.dev/maven/package/orphan-artifact/overview/1.0.0"
166+
assert "orphan-artifact@1.0.0" in caplog.text
167+
assert "no namespace" in caplog.text
168+
169+
def test_namespaced_maven_package_does_not_warn(self, caplog):
170+
"""The warning is for missing data, not for every Maven package"""
171+
with caplog.at_level("WARNING", logger="socketdev"):
172+
Package.socket_url("maven", "com.example", "artifact", "1.0.0")
173+
174+
assert caplog.text == ""
175+
160176
def test_diff_path_builds_the_same_maven_url_as_the_full_scan_path(self):
161177
"""Both package construction paths must agree, or links break on only some runs"""
162178
package = Package(

0 commit comments

Comments
 (0)