Skip to content

Commit 9bb0700

Browse files
leliaclaude
andcommitted
fix(gitlab): omit an absent identifier url instead of sending null
The GitLab dependency-scanning schema types an identifier's url as a string matching ^(https?|ftp)://, so a null fails validation. The socket_alert identifier emitted null whenever an alert carried no url, which invalidates that finding for every consumer that validates the report. Verified against the published schema: a report containing an alert with no url now produces zero validation errors. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 52fd1dc commit 9bb0700

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

socketsecurity/core/messages.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -648,13 +648,18 @@ def extract_identifiers_gitlab(alert: Issue) -> list:
648648
"""
649649
identifiers = []
650650

651-
# Primary identifier: Socket alert type
652-
identifiers.append({
651+
# Primary identifier: Socket alert type. The GitLab schema types identifier
652+
# url as a string matching ^(https?|ftp)://, so an absent url is omitted
653+
# rather than sent as null, which fails validation for the whole finding.
654+
socket_identifier = {
653655
"type": "socket_alert",
654656
"name": f"Socket {alert.type}",
655657
"value": alert.type,
656-
"url": alert.url if hasattr(alert, 'url') and alert.url else None
657-
})
658+
}
659+
alert_url = getattr(alert, "url", None)
660+
if alert_url:
661+
socket_identifier["url"] = alert_url
662+
identifiers.append(socket_identifier)
658663

659664
props = getattr(alert, "props", None) or {}
660665
# Alerts reach Issue.props from several sources, so both spellings of each

tests/unit/test_gitlab_format.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,25 @@ def test_location_file_is_unknown_only_when_nothing_is_known(self):
281281

282282
assert Messages.extract_location_gitlab(issue)["file"] == "unknown"
283283

284+
def test_identifier_url_is_omitted_rather_than_null(self):
285+
"""GitLab types identifier url as a string; null fails schema validation"""
286+
issue = Issue(
287+
pkg_name="nourl-pkg",
288+
pkg_version="1.0.0",
289+
type="malware",
290+
severity="critical",
291+
title="Malware",
292+
pkg_type="npm",
293+
key="test-key",
294+
purl="pkg:npm/nourl-pkg@1.0.0",
295+
)
296+
297+
identifiers = Messages.extract_identifiers_gitlab(issue)
298+
299+
# An absent key is correct; a present-but-null value is what breaks validation.
300+
assert all("url" not in i or i["url"] for i in identifiers)
301+
assert "url" not in identifiers[0]
302+
284303
def test_severity_mapping(self):
285304
"""Test all Socket severities map to GitLab severities"""
286305
severity_tests = [

0 commit comments

Comments
 (0)