Skip to content

Commit 85f86ca

Browse files
authored
feature: Return underlying ruleId as sourceId CF-1812 (#165)
The sourceId will contain the ruleId returned by Trivy, Trivy standardizes to ruleId when returning SARIF for example, but it can also be called VulnerabilityID, they have the same value Trivy examples: "ruleId": "CVE-2025-22870" "ruleId": "CVE-2025-22872" "ruleId": "aws-access-key-id"
1 parent 4f665d6 commit 85f86ca

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/CycloneDX/cyclonedx-go v0.9.2
99
github.com/aquasecurity/trivy v0.59.1 // Also update .config.yml
1010
github.com/aquasecurity/trivy-db v0.0.0-20241209111357-8c398f13db0e
11-
github.com/codacy/codacy-engine-golang-seed/v6 v6.3.0
11+
github.com/codacy/codacy-engine-golang-seed/v6 v6.4.0
1212
github.com/google/go-cmp v0.7.0
1313
github.com/package-url/packageurl-go v0.1.3
1414
github.com/samber/lo v1.51.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -934,8 +934,8 @@ github.com/cncf/xds/go v0.0.0-20241223141626-cff3c89139a3 h1:boJj011Hh+874zpIySe
934934
github.com/cncf/xds/go v0.0.0-20241223141626-cff3c89139a3/go.mod h1:W+zGtBO5Y1IgJhy4+A9GOqVhqLpfZi+vwmdNXUehLA8=
935935
github.com/cockroachdb/apd/v3 v3.2.1 h1:U+8j7t0axsIgvQUqthuNm82HIrYXodOV2iWLWtEaIwg=
936936
github.com/cockroachdb/apd/v3 v3.2.1/go.mod h1:klXJcjp+FffLTHlhIG69tezTDvdP065naDsHzKhYSqc=
937-
github.com/codacy/codacy-engine-golang-seed/v6 v6.3.0 h1:kGwieci9KOXZcmfKLnUHND3aY9RiEJoS8/zMokVwnvw=
938-
github.com/codacy/codacy-engine-golang-seed/v6 v6.3.0/go.mod h1:Ir7lvmQQeEd7xF7Z+XNaY+UGq6CBXil2rEmKhNDkVRk=
937+
github.com/codacy/codacy-engine-golang-seed/v6 v6.4.0 h1:IEBZi96MMt7hXCovJFTI8GU7hFz5wnzVwVZZv9j69Ec=
938+
github.com/codacy/codacy-engine-golang-seed/v6 v6.4.0/go.mod h1:Ir7lvmQQeEd7xF7Z+XNaY+UGq6CBXil2rEmKhNDkVRk=
939939
github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb h1:EDmT6Q9Zs+SbUoc7Ik9EfrFqcylYqgPZ9ANSbTAntnE=
940940
github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb/go.mod h1:ZjrT6AXHbDs86ZSdt/osfBi5qfexBrKUdONk989Wnk4=
941941
github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be h1:J5BL2kskAlV9ckgEsNQXscjIaLiOYiZ75d4e94E6dcQ=

internal/tool/tool.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ func (t codacyTrivy) getVulnerabilities(ctx context.Context, report ptypes.Repor
209209
Line: lineNumberByPurl[purl],
210210
Message: fmt.Sprintf("Insecure dependency %s (%s: %s) %s", purlPrettyPrint(*vuln.PkgIdentifier.PURL), vuln.VulnerabilityID, vuln.Title, fixedVersionMessage),
211211
PatternID: ruleID,
212+
SourceID: vuln.VulnerabilityID,
212213
},
213214
)
214215
}
@@ -270,6 +271,7 @@ func (t codacyTrivy) runSecretScanning(toolExecution codacy.ToolExecution) []cod
270271
Message: fmt.Sprintf("Possible hardcoded secret: %s", result.Title),
271272
PatternID: ruleIDSecret,
272273
Line: result.StartLine,
274+
SourceID: result.RuleID,
273275
},
274276
)
275277
}

internal/tool/tool_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,18 +224,21 @@ func TestRun(t *testing.T) {
224224
Line: 1,
225225
PatternID: ruleIDVulnerability,
226226
Message: "Insecure dependency type/@namespace/package-1@version+incompatible (vuln id: vuln title) (update to vuln fixed)",
227+
SourceID: "vuln id",
227228
},
228229
{
229230
File: fileName,
230231
Line: 1,
231232
PatternID: ruleIDVulnerability,
232233
Message: "Insecure dependency type/@namespace/package-1@version+incompatible (vuln id no fixed version: vuln no fixed version) (no fix available)",
234+
SourceID: "vuln id no fixed version",
233235
},
234236
{
235237
File: fileName,
236238
Line: 1,
237239
PatternID: ruleIDSecret,
238240
Message: "Possible hardcoded secret: AWS Access Key ID",
241+
SourceID: "aws-access-key-id",
239242
},
240243
}
241244
issues := lo.Filter(results, func(result codacy.Result, _ int) bool {

0 commit comments

Comments
 (0)