File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -142,6 +142,9 @@ public function isRequestAuthorized($secret)
142142 }
143143 if (isset ($ _SERVER ['HTTP_X_GITLAB_TOKEN ' ])) {
144144 return $ this ->isGitlabTokenValid ($ secret , $ _SERVER ['HTTP_X_GITLAB_TOKEN ' ]);
145+ } else {
146+ $ payload = file_get_contents ('php://input ' );
147+ return $ this ->isGiteaSecretValid ($ secret , $ payload );
145148 }
146149
147150 return false ;
@@ -173,6 +176,24 @@ public function isGitlabTokenValid($secret, $token)
173176 return $ secret === $ token ;
174177 }
175178
179+ /**
180+ * Returns true if secret contained in the payload matches the client
181+ * secret
182+ * @param string $secret The webhook secret
183+ * @param string $payload The webhook request body
184+ * @return boolean Whether the client secret matches the payload secret or
185+ * not
186+ */
187+ public function isGiteaSecretValid ($ secret , $ payload )
188+ {
189+ $ payload = json_decode ($ payload , true );
190+ if (!empty ($ payload ) && isset ($ payload ['secret ' ])) {
191+ return $ secret === $ payload ['secret ' ];
192+ }
193+
194+ return false ;
195+ }
196+
176197 public function onAdminMenu ()
177198 {
178199 $ base = rtrim ($ this ->grav ['base_url ' ], '/ ' ) . '/ ' . trim ($ this ->grav ['admin ' ]->base , '/ ' );
You can’t perform that action at this time.
0 commit comments