Skip to content

Commit 71725a7

Browse files
author
root
committed
fix: require at least one field for security advisory updates
Reject update_repository_security_advisory calls that only provide owner, repo, and ghsaId to avoid sending empty PATCH requests.
1 parent 2a1584f commit 71725a7

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

pkg/github/security_advisories_write.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,12 @@ func UpdateRepositorySecurityAdvisory(t translations.TranslationHelperFunc) inve
494494
requestBody.State = &state
495495
}
496496

497+
if requestBody.Summary == nil && requestBody.Description == nil && len(requestBody.Vulnerabilities) == 0 &&
498+
requestBody.CVEID == nil && len(requestBody.CWEIDs) == 0 && requestBody.Severity == nil &&
499+
requestBody.CVSSVectorString == nil && len(requestBody.Credits) == 0 && requestBody.State == nil {
500+
return utils.NewToolResultError("at least one of summary, description, vulnerabilities, cveId, cweIds, severity, cvssVectorString, credits, or state must be provided for update"), nil, nil
501+
}
502+
497503
client, err := deps.GetClient(ctx)
498504
if err != nil {
499505
return nil, nil, fmt.Errorf("failed to get GitHub client: %w", err)

pkg/github/security_advisories_write_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,19 @@ func Test_UpdateRepositorySecurityAdvisory(t *testing.T) {
218218
expectError: true,
219219
expectedErrMsg: "missing required parameter: ghsaId",
220220
},
221+
{
222+
name: "no update fields provided",
223+
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
224+
PatchReposSecurityAdvisoriesByOwnerByRepoByGhsaID: mockResponse(t, http.StatusOK, mockAdvisory),
225+
}),
226+
requestArgs: map[string]any{
227+
"owner": "octo",
228+
"repo": "hello-world",
229+
"ghsaId": "GHSA-xxxx-xxxx-xxxx",
230+
},
231+
expectError: true,
232+
expectedErrMsg: "at least one of summary, description, vulnerabilities, cveId, cweIds, severity, cvssVectorString, credits, or state must be provided for update",
233+
},
221234
{
222235
name: "API error handling",
223236
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{

0 commit comments

Comments
 (0)