Skip to content

Commit 895cff9

Browse files
Array Fleetcursoragent
andcommitted
fix: reject empty cweIds/credits on advisory update
Empty slices are omitted from PATCH JSON due to omitempty, so update calls with only cweIds: [] or credits: [] silently sent {} and appeared to succeed validation. Reject explicitly with a clear error message. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 6f477b4 commit 895cff9

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

pkg/github/security_advisories_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,34 @@ func Test_UpdateRepositorySecurityAdvisory(t *testing.T) {
10661066
expectError: true,
10671067
expectedErrMsg: "invalid cweIds: value must not be null",
10681068
},
1069+
{
1070+
name: "reject empty cweIds only",
1071+
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
1072+
PatchReposSecurityAdvisoriesByOwnerByRepoByGhsaID: mockResponse(t, http.StatusOK, mockAdvisory),
1073+
}),
1074+
requestArgs: map[string]any{
1075+
"owner": "octo",
1076+
"repo": "hello-world",
1077+
"ghsaId": "GHSA-xxxx-xxxx-xxxx",
1078+
"cweIds": []any{},
1079+
},
1080+
expectError: true,
1081+
expectedErrMsg: "invalid cweIds: at least one CWE ID must be provided when cweIds is specified",
1082+
},
1083+
{
1084+
name: "reject empty credits only",
1085+
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
1086+
PatchReposSecurityAdvisoriesByOwnerByRepoByGhsaID: mockResponse(t, http.StatusOK, mockAdvisory),
1087+
}),
1088+
requestArgs: map[string]any{
1089+
"owner": "octo",
1090+
"repo": "hello-world",
1091+
"ghsaId": "GHSA-xxxx-xxxx-xxxx",
1092+
"credits": []any{},
1093+
},
1094+
expectError: true,
1095+
expectedErrMsg: "invalid credits: at least one credit must be provided when credits is specified",
1096+
},
10691097
{
10701098
name: "successful update with credits and cweIds",
10711099
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{

pkg/github/security_advisories_write.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,9 @@ func UpdateRepositorySecurityAdvisory(t translations.TranslationHelperFunc) inve
621621
hasUpdate = true
622622
}
623623
if _, ok := args["cweIds"]; ok {
624+
if len(cweIDs) == 0 {
625+
return utils.NewToolResultError("invalid cweIds: at least one CWE ID must be provided when cweIds is specified"), nil, nil
626+
}
624627
requestBody.CWEIDs = cweIDs
625628
hasUpdate = true
626629
}
@@ -633,6 +636,9 @@ func UpdateRepositorySecurityAdvisory(t translations.TranslationHelperFunc) inve
633636
hasUpdate = true
634637
}
635638
if _, ok := args["credits"]; ok {
639+
if len(credits) == 0 {
640+
return utils.NewToolResultError("invalid credits: at least one credit must be provided when credits is specified"), nil, nil
641+
}
636642
requestBody.Credits = credits
637643
hasUpdate = true
638644
}

0 commit comments

Comments
 (0)