@@ -3,6 +3,7 @@ package adapter
33import (
44 "context"
55 "crypto/subtle"
6+ "encoding/json"
67 "fmt"
78 "net/http"
89
@@ -50,14 +51,46 @@ func applyIncomingParams(req *http.Request, payloadBody []byte, params []string)
5051}
5152
5253func (l * listener ) detectIncoming (ctx context.Context , req * http.Request , payloadBody []byte ) (bool , * v1alpha1.Repository , error ) {
54+ // Support both legacy (URL query) and new (POST body) secret passing
5355 repository := req .URL .Query ().Get ("repository" )
54- querySecret := req .URL .Query ().Get ("secret" )
55- pipelineRun := req .URL .Query ().Get ("pipelinerun" )
5656 branch := req .URL .Query ().Get ("branch" )
57+ pipelineRun := req .URL .Query ().Get ("pipelinerun" )
58+ querySecret := req .URL .Query ().Get ("secret" )
59+ legacyMode := false
5760
5861 if req .URL .Path != "/incoming" {
5962 return false , nil , nil
6063 }
64+
65+ // If not all required query params are present, try to parse from JSON body
66+ if repository == "" || branch == "" || pipelineRun == "" || querySecret == "" {
67+ if req .Method == http .MethodPost && req .Header .Get ("Content-Type" ) == "application/json" && len (payloadBody ) > 0 {
68+ var body struct {
69+ Repository string `json:"repository"`
70+ Branch string `json:"branch"`
71+ PipelineRun string `json:"pipelinerun"`
72+ Secret string `json:"secret"`
73+ Params map [string ]any `json:"params"`
74+ }
75+ if err := json .Unmarshal (payloadBody , & body ); err == nil {
76+ repository = body .Repository
77+ branch = body .Branch
78+ pipelineRun = body .PipelineRun
79+ querySecret = body .Secret
80+ } else {
81+ return false , nil , fmt .Errorf ("invalid JSON body for incoming webhook: %w" , err )
82+ }
83+ } else {
84+ return false , nil , fmt .Errorf ("missing query URL argument: pipelinerun, branch, repository, secret: '%s' '%s' '%s' '%s'" , pipelineRun , branch , repository , querySecret )
85+ }
86+ } else {
87+ legacyMode = true
88+ }
89+
90+ if legacyMode {
91+ l .logger .Warnf ("[SECURITY] Incoming webhook used legacy URL-based secret passing. This is insecure and will be deprecated. Please use POST body instead." )
92+ }
93+
6194 l .logger .Infof ("incoming request has been requested: %v" , req .URL )
6295 if pipelineRun == "" || repository == "" || querySecret == "" || branch == "" {
6396 err := fmt .Errorf ("missing query URL argument: pipelinerun, branch, repository, secret: '%s' '%s' '%s' '%s'" , pipelineRun , branch , repository , querySecret )
0 commit comments