Skip to content

Commit 970a74f

Browse files
crenshaw-devtodaywasawesome
authored andcommitted
Merge commit from fork
Signed-off-by: Michael Crenshaw <[email protected]>
1 parent 51be43f commit 970a74f

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
@@ -251,13 +251,15 @@ func (a *ArgoCDWebhookHandler) affectedRevisionInfo(payloadIf any) (webURLs []st
251251

252252
// Webhook module does not parse the inner links
253253
if payload.Repository.Links != nil {
254-
for _, l := range payload.Repository.Links["clone"].([]any) {
255-
link := l.(map[string]any)
256-
if link["name"] == "http" {
257-
webURLs = append(webURLs, link["href"].(string))
258-
}
259-
if link["name"] == "ssh" {
260-
webURLs = append(webURLs, link["href"].(string))
254+
clone, ok := payload.Repository.Links["clone"].([]any)
255+
if ok {
256+
for _, l := range clone {
257+
link := l.(map[string]any)
258+
if link["name"] == "http" || link["name"] == "ssh" {
259+
if href, ok := link["href"].(string); ok {
260+
webURLs = append(webURLs, href)
261+
}
262+
}
261263
}
262264
}
263265
}

util/webhook/webhook_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,20 @@ func Test_affectedRevisionInfo_appRevisionHasChanged(t *testing.T) {
702702
{true, "refs/tags/no-slashes", bitbucketPushPayload("no-slashes"), "bitbucket push branch or tag name without slashes, targetRevision tag prefixed"},
703703
{true, "refs/tags/no-slashes", bitbucketRefChangedPayload("no-slashes"), "bitbucket ref changed branch or tag name without slashes, targetRevision tag prefixed"},
704704
{true, "refs/tags/no-slashes", gogsPushPayload("no-slashes"), "gogs push branch or tag name without slashes, targetRevision tag prefixed"},
705+
706+
{true, "some-ref", bitbucketserver.RepositoryReferenceChangedPayload{
707+
Changes: []bitbucketserver.RepositoryChange{
708+
{Reference: bitbucketserver.RepositoryReference{ID: "refs/heads/some-ref"}},
709+
},
710+
Repository: bitbucketserver.Repository{Links: map[string]any{"clone": "boom"}}, // The string "boom" here is what previously caused a panic.
711+
}, "bitbucket push branch or tag name, malformed link"}, // https://github.com/argoproj/argo-cd/security/advisories/GHSA-f9gq-prrc-hrhc
712+
713+
{true, "some-ref", bitbucketserver.RepositoryReferenceChangedPayload{
714+
Changes: []bitbucketserver.RepositoryChange{
715+
{Reference: bitbucketserver.RepositoryReference{ID: "refs/heads/some-ref"}},
716+
},
717+
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.
718+
}, "bitbucket push branch or tag name, malformed href"},
705719
}
706720
for _, testCase := range tests {
707721
testCopy := testCase

0 commit comments

Comments
 (0)