Skip to content

Commit 5c466a4

Browse files
authored
Merge commit from fork
Signed-off-by: Michael Crenshaw <[email protected]>
1 parent b2fa7dc commit 5c466a4

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

util/webhook/webhook.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,15 @@ func (a *ArgoCDWebhookHandler) affectedRevisionInfo(payloadIf any) (webURLs []st
255255

256256
// Webhook module does not parse the inner links
257257
if payload.Repository.Links != nil {
258-
for _, l := range payload.Repository.Links["clone"].([]any) {
259-
link := l.(map[string]any)
260-
if link["name"] == "http" {
261-
webURLs = append(webURLs, link["href"].(string))
262-
}
263-
if link["name"] == "ssh" {
264-
webURLs = append(webURLs, link["href"].(string))
258+
clone, ok := payload.Repository.Links["clone"].([]any)
259+
if ok {
260+
for _, l := range clone {
261+
link := l.(map[string]any)
262+
if link["name"] == "http" || link["name"] == "ssh" {
263+
if href, ok := link["href"].(string); ok {
264+
webURLs = append(webURLs, href)
265+
}
266+
}
265267
}
266268
}
267269
}

util/webhook/webhook_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,20 @@ func Test_affectedRevisionInfo_appRevisionHasChanged(t *testing.T) {
728728
{true, "refs/tags/no-slashes", bitbucketPushPayload("no-slashes"), "bitbucket push branch or tag name without slashes, targetRevision tag prefixed"},
729729
{true, "refs/tags/no-slashes", bitbucketRefChangedPayload("no-slashes"), "bitbucket ref changed branch or tag name without slashes, targetRevision tag prefixed"},
730730
{true, "refs/tags/no-slashes", gogsPushPayload("no-slashes"), "gogs push branch or tag name without slashes, targetRevision tag prefixed"},
731+
732+
{true, "some-ref", bitbucketserver.RepositoryReferenceChangedPayload{
733+
Changes: []bitbucketserver.RepositoryChange{
734+
{Reference: bitbucketserver.RepositoryReference{ID: "refs/heads/some-ref"}},
735+
},
736+
Repository: bitbucketserver.Repository{Links: map[string]any{"clone": "boom"}}, // The string "boom" here is what previously caused a panic.
737+
}, "bitbucket push branch or tag name, malformed link"}, // https://github.com/argoproj/argo-cd/security/advisories/GHSA-f9gq-prrc-hrhc
738+
739+
{true, "some-ref", bitbucketserver.RepositoryReferenceChangedPayload{
740+
Changes: []bitbucketserver.RepositoryChange{
741+
{Reference: bitbucketserver.RepositoryReference{ID: "refs/heads/some-ref"}},
742+
},
743+
Repository: bitbucketserver.Repository{Links: map[string]any{"clone": []any{map[string]any{"name": "http", "href": []string{}}}}}, // The href as an empty array is what previously caused a panic.
744+
}, "bitbucket push branch or tag name, malformed href"},
731745
}
732746
for _, testCase := range tests {
733747
testCopy := testCase

0 commit comments

Comments
 (0)