Skip to content

Commit 85ef8a2

Browse files
committed
Merge branch 'develop' of github.com:trilbymedia/grav-plugin-git-sync into develop
2 parents 76fe723 + 509b689 commit 85ef8a2

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

git-sync.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff 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, '/');

0 commit comments

Comments
 (0)