Skip to content

Commit

Permalink
feat: add secret parameter to the webhooks
Browse files Browse the repository at this point in the history
See #11
  • Loading branch information
Marc Runkel authored and thathoff committed Feb 19, 2021
1 parent 33f88d2 commit e794ba1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ return [
- `push` (Boolean): Push your changes to remote? (default: `false`)
- `commitMessageTemplate` (String): Configure the template for the commit message (default: `:action:(:item:): :url:`)
- `cronHooksEnabled` (Boolean): Whether `/git-content/push` and `/git-content/pull` endpoints are enabled or not. (default: `true`)
- `cronHooksSecret` (String): When set, this secret must be sent with the cronHooks as a get parameter. Note: If you set
a secret, only the GET method will work on the webhooks. `/git-content/(pull|push)?secret=S0up3rS3c3t`
- `displayErrors` (Boolean): Display git errors when saving pages (default: `false`)
- `gitBin` (String): Path to the `git` binary, [See Git.php](http://kbjr.github.io/Git.php/) `Git::set_bin(string $path)`
- `windowsMode` (Boolean): [See Git.php](http://kbjr.github.io/Git.php/) `Git::windows_mode()` (default: `false`)
- `disable` (Boolean): If set to `true`, the plugin won't initialize. (default: `false`)
- `disable` (Boolean): If set to `true`, the plugin won't initialize. (default: `false`)

#### Custom Commit Message

Expand Down
1 change: 1 addition & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
'push' => null,
'commit' => null,
'cronHooksEnabled' => null,
'cronHooksSecret' => null,
'commitMessage' => ':action:(:item:): :url:',
'windowsMode' => null,
'gitBin' => null,
Expand Down
11 changes: 11 additions & 0 deletions src/KirbyGit.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ public function getRoutes()
$route['pattern'] = 'git-content/(:any)';
$route['method'] = 'GET|POST';
$route['action'] = function($gitCommand) use ($gitHelper) {
// check to see if a secret is set, and if it is, verify it
$secret = option('thathoff.git-content.cronHooksSecret', '');
if ($secret !== '') {
$passedSecret = kirby()->request()->get('secret', '');
if ($passedSecret !== $secret) {
return [
'status' => 'forbidden',
'message' => 'Invalid secret passed',
];
}
}
switch ($gitCommand) {
case "push":
try {
Expand Down

0 comments on commit e794ba1

Please sign in to comment.