fix(security): require CRON_SECRET on cron + LoTW sync endpoints#220
Merged
Conversation
The cron routes trusted any request whose host/user-agent/x-vercel-id header
mentioned vercel, which disabled the CRON_SECRET check on every *.vercel.app
deployment. Separately, /api/lotw/{upload,download} skipped auth entirely on
a spoofable X-Cron-Job: true header, letting anonymous callers trigger
uploads/downloads for any station_id.
- New src/lib/cron-auth.ts: strict Bearer CRON_SECRET check, no fallbacks.
- Cron routes require the Bearer token unconditionally and fail closed (500)
when CRON_SECRET is unset. Vercel attaches the header automatically when
the env var exists.
- X-Cron-Job is now only a mode discriminator: cron mode additionally
requires the valid Bearer token; the cron routes' internal fetches send it.
- README: "Scheduled sync" section for Vercel + self-hosted crontab setup.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This was referenced Jul 13, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Closes two authentication bypasses that allowed anonymous callers to trigger LoTW upload/download work by spoofing Vercel/cron-related headers, and documents the required deployment configuration.
Changes:
- Introduces a shared
hasValidCronSecret()helper that strictly validatesAuthorization: Bearer ${CRON_SECRET}with no trusted-host/user-agent fallbacks. - Requires a valid Bearer token for
/api/cron/lotw-{upload,download}and for cron-mode execution of/api/lotw/{upload,download}(whereX-Cron-Jobis now only a mode discriminator). - Documents scheduled sync setup for Vercel and self-hosted schedulers in the README.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/lib/cron-auth.ts | Adds centralized strict Bearer-token validation for cron authentication. |
| src/app/api/lotw/upload/route.ts | Prevents X-Cron-Job spoofing by requiring a valid cron Bearer token in cron mode. |
| src/app/api/lotw/download/route.ts | Prevents X-Cron-Job spoofing by requiring a valid cron Bearer token in cron mode. |
| src/app/api/cron/lotw-upload/route.ts | Removes trusted-host sniffing; enforces CRON_SECRET presence and Bearer validation; forwards Authorization internally. |
| src/app/api/cron/lotw-download/route.ts | Removes trusted-host sniffing; enforces CRON_SECRET presence and Bearer validation; forwards Authorization internally. |
| README.md | Documents CRON_SECRET requirements and example scheduler invocations for the cron endpoints. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Two authentication holes made the LoTW sync endpoints publicly triggerable:
/api/cron/lotw-{upload,download}treated any request whosehostcontains "vercel" (or with ax-vercel-id/ vercel user-agent header) as a trusted cron — on any*.vercel.appdeployment theCRON_SECRETcheck was effectively disabled. All of these signals are caller-controlled.X-Cron-Jobheader./api/lotw/uploadand/api/lotw/downloadskipped user auth entirely when the request carriedX-Cron-Job: true— any anonymous caller could trigger uploads/downloads for anystation_id.Fix
src/lib/cron-auth.ts—hasValidCronSecret(): strictAuthorization: Bearer ${CRON_SECRET}comparison, no fallbacks.CRON_SECRETfails closed (500) instead of open. (Vercel attaches the header automatically when the env var is set.)X-Cron-Jobremains only as a mode discriminator — cron mode now additionally requires the valid Bearer token, and a cron-flagged request without it gets a 401 (never falls through to cookie auth). The cron routes' internal fetches now pass the Authorization header.CRON_SECRETon Vercel and the self-hosted crontab pattern.Verification
npm run lint/npm run typecheck/npm run buildclean.X-Cron-Job: truealone → 401 (regression check for the bypass); valid Bearer → 200.🤖 Generated with Claude Code