Skip to content

Commit bdd45e2

Browse files
committed
Align webhook branch validation (#1781)
1 parent ac009d5 commit bdd45e2

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

controllers/scriptStorage.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,6 +2308,7 @@ exports.webhook = function (aReq, aRes) {
23082308
var repos = {};
23092309
var repo = null;
23102310
var update = null;
2311+
var defaultBranch = null;
23112312

23122313
// Return if script storage is in read-only mode
23132314
if (process.env.READ_ONLY_SCRIPT_STORAGE === 'true') {
@@ -2375,9 +2376,10 @@ exports.webhook = function (aReq, aRes) {
23752376

23762377
//
23772378

2378-
// Only accept commits from the `master` branch
2379-
if (payload.ref !== 'refs/heads/master') {
2380-
aRes.status(403).send('Default branch is not `master`.'); // Forbidden
2379+
// Only accept commits from the repository's default branch
2380+
defaultBranch = (payload.repository && payload.repository.default_branch) || 'master';
2381+
if (payload.ref !== 'refs/heads/' + defaultBranch) {
2382+
aRes.status(403).send('Push is not to default branch.'); // Forbidden
23812383
return;
23822384
}
23832385

0 commit comments

Comments
 (0)