Skip to content

Compare the revalidate secret in constant time - #4882

Open
ofri-peretz wants to merge 1 commit into
pythonitalia:mainfrom
ofri-peretz:harden-revalidate-secret-compare
Open

ofri-peretz wants to merge 1 commit into
pythonitalia:mainfrom
ofri-peretz:harden-revalidate-secret-compare

Conversation

@ofri-peretz

Copy link
Copy Markdown

What was wrong

frontend/src/pages/api/revalidate.ts compares the secret supplied by the caller against process.env.REVALIDATE_SECRET with !==. String comparison with !== can return early at the first differing character, so response timing can leak information about the secret.

Fix

Both values are hashed with SHA-256 and compared with crypto.timingSafeEqual. Hashing makes the buffers equal length, so a length mismatch does not throw or leak the length. A missing caller secret or an unset env var now returns the existing 401 response. No other behaviour changes. This is the pattern flagged by node-security/no-timing-unsafe-compare.

How I verified

Ran the comparison helper under Node: equal secret returns true; different secret, shorter secret, undefined input and unset env var all return false. The edited file parses cleanly with Node's TypeScript stripping. I did not run the full app or test suite.

AI disclosure: drafted with AI assistance (Claude); I reviewed and tested the change.

@vercel

vercel Bot commented Dec 6, 2026

Copy link
Copy Markdown

@ofri-peretz is attempting to deploy a commit to the Python Italia Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant