Skip to content

Commit 8f50f83

Browse files
authored
fix(templates): prevent jobs run if secret unset (#15207)
<!-- Thank you for the PR! Please go through the checklist below and make sure you've completed all the steps. Please review the [CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md) document in this repository if you haven't already. The following items will ensure that your PR is handled as smoothly as possible: - PR Title must follow conventional commits format. For example, `feat: my new feature`, `fix(plugin-seo): my fix`. - Minimal description explained as if explained to someone not immediately familiar with the code. - Provide before/after screenshots or code diffs if applicable. - Link any related issues/discussions from GitHub or Discord. - Add review comments if necessary to explain to the reviewer the logic behind a change ### What? ### Why? ### How? Fixes # --> ### What? This PR prevents running jobs via `run` if a CRON_SECRET is unset. This change is only necessary for the website templates and docs. ### Why? To harden the access controls around the `run` access check in the website templates. ### How? Checking if the secret is truthy prior to comparing it against the auth header.
1 parent 3337403 commit 8f50f83

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

docs/jobs-queue/queues.mdx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,14 @@ export default buildConfig({
122122
// Allow logged in users to execute this endpoint (default)
123123
if (req.user) return true
124124

125+
const secret = process.env.CRON_SECRET
126+
if (!secret) return false
127+
125128
// If there is no logged in user, then check
126129
// for the Vercel Cron secret to be present as an
127130
// Authorization header:
128131
const authHeader = req.headers.get('authorization')
129-
return authHeader === `Bearer ${process.env.CRON_SECRET}`
132+
return authHeader === `Bearer ${secret}`
130133
},
131134
},
132135
// Other job configurations...

templates/website/src/payload.config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,14 @@ export default buildConfig({
7575
// Allow logged in users to execute this endpoint (default)
7676
if (req.user) return true
7777

78+
const secret = process.env.CRON_SECRET
79+
if (!secret) return false
80+
7881
// If there is no logged in user, then check
7982
// for the Vercel Cron secret to be present as an
8083
// Authorization header:
8184
const authHeader = req.headers.get('authorization')
82-
return authHeader === `Bearer ${process.env.CRON_SECRET}`
85+
return authHeader === `Bearer ${secret}`
8386
},
8487
},
8588
tasks: [],

templates/with-vercel-website/src/payload.config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,14 @@ export default buildConfig({
8686
// Allow logged in users to execute this endpoint (default)
8787
if (req.user) return true
8888

89+
const secret = process.env.CRON_SECRET
90+
if (!secret) return false
91+
8992
// If there is no logged in user, then check
9093
// for the Vercel Cron secret to be present as an
9194
// Authorization header:
9295
const authHeader = req.headers.get('authorization')
93-
return authHeader === `Bearer ${process.env.CRON_SECRET}`
96+
return authHeader === `Bearer ${secret}`
9497
},
9598
},
9699
tasks: [],

0 commit comments

Comments
 (0)