fix(security): do not HTML-purify Turnstile tokens - #29
Conversation
Captcha tokens are opaque POST strings. Running them through HTMLPurifier can empty or alter the value so siteverify always fails. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Thanks for this — the diagnosis is right and the test is a good addition. I confirmed the bug independently: passing a token through the purifier turns One request before merge, on the shape rather than the substance. Core already has an idiom for reading a value without any transformation: The one thing your helper genuinely adds over the existing idiom is POST-only enforcement, and that is worth keeping. Could it become a small private method on the captcha class, or a Separately, and not something you introduced — the guard immediately above is broken: if ($gReCaptchaResponse !== '' || $gReCaptchaResponse !== false || $gReCaptchaResponse !== 0)Those are ORed, so the condition is always true regardless of the value ( Also note the branch is currently conflicting with develop. |
Summary
auto/recaptcha/turnstile/none). When it is on,osc_check_captcha()sentcf-turnstile-responsethroughParams::getParam(), which HTML-purifies the value.g-recaptcha-response.osc_posted_captcha_token()). A query-string copy is ignored. Length cap for Turnstile is unchanged (2048).Test plan
php tests/captcha-posted-token.php(POST kept as-is, GET ignored, HTMLPurifier contrast)?cf-turnstile-response=query string is not accepted as a tokenNOTE: I have been running a heavily customized version of Osclass for 12 years volunteersbase.com - Thank you for keeping the project alive! Here is my humble contribution, hope you can find it useful :)