Test that Turnstile rejects a verified token for an unlisted hostname#51
Conversation
The gateway rejects a Siteverify success whose hostname is not in TURNSTILE_HOSTNAMES, which stops a token minted for an attacker-controlled page from being replayed against this form. That branch had no coverage: the test double always returned the allow-listed hostname. Add a token that resolves to an unlisted hostname and assert the submission is rejected with verification_failed and no Site Data write, after Siteverify was consulted.
|
Test-only. The gateway rejects a Turnstile success whose This adds a token that resolves to an unlisted hostname and asserts the submission is rejected with no Site Data write. Worker suite goes 14 → 15 green. Hopefully a low-risk safety net. |
mberman84
left a comment
There was a problem hiding this comment.
Approved. The test specifically exercises a successful Siteverify response with the expected action but an unlisted hostname, then verifies the 400 verification failure, one Siteverify call, and no Site Data write. It remains isolated and passes on the synthesized merge with current main.
|
Thanks for the review and approval! |
Summary
verifyTurnstile()rejects a Siteverify success whosehostnameisn't in theTURNSTILE_HOSTNAMESallow-list:This is a meaningful defense — it stops a Turnstile token solved on an attacker-controlled page (a different hostname) from being replayed against this form. But the branch had no test coverage: the Siteverify test double always returned the allow-listed
signals.forwardfuture.ai, so a regression that dropped or weakened the hostname check would pass CI.Change
Adds a
wrong-hostname-tokento the Siteverify mock that returnssuccess: truewith the correct action but an unlisted hostname, plus a test asserting the submission is rejected (400/verification_failed) with no Site Data write, while confirming Siteverify was actually consulted.Test-only; no behavior change. Worker suite goes from 14 → 15 passing.
Verification
npm --prefix worker run check→ 15/15 tests pass.