Skip to content

Commit 129da00

Browse files
committed
feat(policies): add fixed_version field to vulnerability finding schema
Add an optional fixed_version string field to PolicyVulnerabilityFinding, allowing policies to report which version fixes a given vulnerability. The field is optional and can be set via object.union in Rego policies, consistent with other optional fields like recommendation and cvss_v3_score. Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
1 parent 335fe2f commit 129da00

7 files changed

Lines changed: 85 additions & 3 deletions

File tree

app/controlplane/api/gen/frontend/attestation/v1/crafting_state.ts

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/api/gen/jsonschema/attestation.v1.PolicyVulnerabilityFinding.jsonschema.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/api/gen/jsonschema/attestation.v1.PolicyVulnerabilityFinding.schema.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/attestation/crafter/api/attestation/v1/crafting_state.pb.go

Lines changed: 13 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/attestation/crafter/api/attestation/v1/crafting_state.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,8 @@ message PolicyVulnerabilityFinding {
334334
string recommendation = 7;
335335
// Optional longer description of the vulnerability
336336
string description = 8;
337+
// Version that fixes the vulnerability (e.g., "2.0.1", "1.3.4-patch1")
338+
string fixed_version = 9;
337339
}
338340

339341
// Output schema for SAST findings from policy evaluation.

pkg/policies/engine/rego/builtins/vulnerability_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,23 @@ result := object.union(
6060
"recommendation": "upgrade to v2.0.0",
6161
},
6262
},
63+
{
64+
name: "combined with object.union for fixed_version",
65+
policy: `package test
66+
import rego.v1
67+
68+
result := object.union(
69+
chainloop.vulnerability("CVE found", "CVE-2024-5678", "pkg:npm/foo@1.0", "HIGH"),
70+
{"fixed_version": "1.0.1"},
71+
)`,
72+
expected: map[string]any{
73+
"message": "CVE found",
74+
"external_id": "CVE-2024-5678",
75+
"package_purl": "pkg:npm/foo@1.0",
76+
"severity": "HIGH",
77+
"fixed_version": "1.0.1",
78+
},
79+
},
6380
{
6481
name: "with sprintf interpolation",
6582
policy: `package test

pkg/policies/findings/registry_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,27 @@ func TestValidateFinding(t *testing.T) {
9494
assert.Equal(t, "A buffer overflow vulnerability in the parsing module allows remote code execution.", f.GetDescription())
9595
},
9696
},
97+
{
98+
name: "valid vulnerability finding with fixed_version",
99+
findingType: "VULNERABILITY",
100+
raw: map[string]any{
101+
"message": "Found CVE-2024-5678",
102+
"external_id": "CVE-2024-5678",
103+
"package_purl": "pkg:golang/example.com/lib@v1.0.0",
104+
"severity": "HIGH",
105+
"fixed_version": "1.0.1",
106+
},
107+
checkFn: func(t *testing.T, msg interface{}) {
108+
t.Helper()
109+
f, ok := msg.(*v1.PolicyVulnerabilityFinding)
110+
require.True(t, ok)
111+
assert.Equal(t, "Found CVE-2024-5678", f.GetMessage())
112+
assert.Equal(t, "CVE-2024-5678", f.GetExternalId())
113+
assert.Equal(t, "pkg:golang/example.com/lib@v1.0.0", f.GetPackagePurl())
114+
assert.Equal(t, "HIGH", f.GetSeverity())
115+
assert.Equal(t, "1.0.1", f.GetFixedVersion())
116+
},
117+
},
97118
{
98119
name: "vulnerability finding missing required field",
99120
findingType: "VULNERABILITY",

0 commit comments

Comments
 (0)