Add ALTCHA challenge provider (Fixes #72)#76
Open
sean-e-dietrich wants to merge 1 commit into
Open
Conversation
Second built-in ChallengeProviderInterface alongside math: embeds the ALTCHA v2 widget with a pre-computed challenge so the server stays stateless, brute-forces SHA-256(salt + N) == challenge in-browser, and verifies with an HMAC signature on the challenge value via the existing TokenManager. The salt embeds an ?expires=<unix> query string so a precomputed solution can't be replayed indefinitely. Demo gets a /secure-altcha route via path-based dispatch in index.php (two configs since only one challenge.provider is configurable per Firewall instance), with distinct challenge submit path, cookie name, and header name so the math and altcha pass tokens coexist. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
Kanopi\Firewall\Challenge\AltchaChallengeProvider— stateless ALTCHA v2 provider. Server pre-computes{algorithm, challenge, maxnumber, salt, signature}and embeds it in the widget viachallengejson=; salt carries?expires=<unix>; signature isTokenManager::sign(challenge). Verify decodes the base64altchapayload, re-hashessalt + number, checks the HMAC, and rejects expired salts.'altcha'inChallengeProviderFactory::BUILTINS— same shape as the existing math builtin.example/demo/grows a fourth route (/secure-altcha) via path-based dispatch inindex.phpto a second config (config.altcha.yml). Only onechallenge.provideris configurable per Firewall instance, so the demo runs two instances in sequence based on which path is being requested. Distinct submit path / cookie / header per provider so the two pass tokens coexist.example/config.notes.ymllists altcha alongside math.Test plan
tests/Unit/Challenge/AltchaChallengeProviderTest.php— 13 cases: render shape + escaping, accepts solved payload, rejects tampered challenge / wrong number / bad signature / expired salt / no-expiry salt / wrong algorithm / non-base64 / non-JSON / empty payload.ChallengeProviderFactoryTest::testResolvesAltchaShortName— short-name resolution./secure-altcha→ 200 with widget; POST garbage to/_firewall/challenge-altcha→ 400invalid_solution; POST solved payload → 200 +fw_challenge_altcha_passcookie; reload with that cookie → success page.Notes for the reviewer
script type="module"on the widget bundle is required — the official ALTCHAaltcha.min.jsdistribution ships as an ES module; a classic<script>tag fails withUnexpected token 'export'.cdn.jsdelivr.net/npm/altcha/dist/altcha.min.js. If a self-hosted bundle is preferred down the line, that string is a class constant and can be extracted to config without API changes.REDIRECT_FIELD/TTL_FIELDconstants are named identically (redirect_to/ttl) soFirewall::handleChallengeSubmission()doesn't need to know which provider is wired up — it reads a shared field name regardless.🤖 Generated with Claude Code