Skip to content

Commit 503052a

Browse files
committed
feat: add optional description field to PolicyVulnerabilityFinding
Also fix forward compatibility by using DiscardUnknown in protojson unmarshal so older CLIs gracefully ignore fields from newer policies. Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
1 parent 7542585 commit 503052a

7 files changed

Lines changed: 89 additions & 6 deletions

File tree

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

Lines changed: 25 additions & 1 deletion
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: 4 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: 4 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: 14 additions & 4 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
@@ -332,6 +332,8 @@ message PolicyVulnerabilityFinding {
332332
repeated string cwes = 6;
333333
// Suggested fix or upgrade path
334334
string recommendation = 7;
335+
// Optional longer description of the vulnerability
336+
string description = 8;
335337
}
336338

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

pkg/policies/findings/registry.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ func ValidateFinding(findingType string, raw map[string]any) (proto.Message, err
6060
}
6161

6262
msg := factory()
63-
if err := protojson.Unmarshal(data, msg); err != nil {
63+
// DiscardUnknown allows policies to include fields added in newer proto
64+
// versions without breaking older CLIs that haven't been updated yet.
65+
if err := (protojson.UnmarshalOptions{DiscardUnknown: true}).Unmarshal(data, msg); err != nil {
6466
return nil, fmt.Errorf("finding does not match %s schema: %w", findingType, err)
6567
}
6668

pkg/policies/findings/registry_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,26 @@ func TestValidateFinding(t *testing.T) {
7474
assert.InDelta(t, 9.8, f.GetCvssV3Score(), 0.01)
7575
},
7676
},
77+
{
78+
name: "valid vulnerability finding with description",
79+
findingType: "VULNERABILITY",
80+
raw: map[string]any{
81+
"message": "Found CVE-2024-5678",
82+
"external_id": "CVE-2024-5678",
83+
"package_purl": "pkg:golang/example.com/lib@v2.0.0",
84+
"severity": "HIGH",
85+
"description": "A buffer overflow vulnerability in the parsing module allows remote code execution.",
86+
},
87+
checkFn: func(t *testing.T, msg interface{}) {
88+
t.Helper()
89+
f, ok := msg.(*v1.PolicyVulnerabilityFinding)
90+
require.True(t, ok)
91+
assert.Equal(t, "Found CVE-2024-5678", f.GetMessage())
92+
assert.Equal(t, "CVE-2024-5678", f.GetExternalId())
93+
assert.Equal(t, "HIGH", f.GetSeverity())
94+
assert.Equal(t, "A buffer overflow vulnerability in the parsing module allows remote code execution.", f.GetDescription())
95+
},
96+
},
7797
{
7898
name: "vulnerability finding missing required field",
7999
findingType: "VULNERABILITY",
@@ -142,6 +162,23 @@ func TestValidateFinding(t *testing.T) {
142162
assert.Equal(t, "GPL-3.0", f.GetLicenseId())
143163
},
144164
},
165+
{
166+
name: "vulnerability finding with unknown field is accepted",
167+
findingType: "VULNERABILITY",
168+
raw: map[string]any{
169+
"message": "Found CVE-2024-9999",
170+
"external_id": "CVE-2024-9999",
171+
"package_purl": "pkg:golang/example.com/lib@v3.0.0",
172+
"severity": "LOW",
173+
"future_field": "some value from a newer policy",
174+
},
175+
checkFn: func(t *testing.T, msg interface{}) {
176+
t.Helper()
177+
f, ok := msg.(*v1.PolicyVulnerabilityFinding)
178+
require.True(t, ok)
179+
assert.Equal(t, "CVE-2024-9999", f.GetExternalId())
180+
},
181+
},
145182
{
146183
name: "unknown finding type",
147184
findingType: "UNKNOWN",

0 commit comments

Comments
 (0)