Require shared Altcha HMAC key in prod, fail closed on Redis errors#462
Open
simonaszilinskas wants to merge 1 commit into
Open
Require shared Altcha HMAC key in prod, fail closed on Redis errors#462simonaszilinskas wants to merge 1 commit into
simonaszilinskas wants to merge 1 commit into
Conversation
…rors Two hardening fixes flagged in review: - ALTCHA_HMAC_KEY: refuse to start in non-debug mode when unset. The random fallback breaks across multi-worker / multi-pod setups (a challenge issued by one process won't verify on another) and silently changes on every restart. Dev still gets the auto-key with an explicit warning. - Replay check: when Redis is unreachable, return False instead of silently allowing the request. A captured token would otherwise be replayable for the rest of the challenge expiry window. Old fail-open behavior is still available behind ALTCHA_FAIL_OPEN_ON_REDIS_ERROR for deliberate degraded-mode operation.
e-lie
force-pushed
the
fix/altcha-server-hardening
branch
from
May 1, 2026 14:21
4d28d01 to
f3a4f1c
Compare
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.
Why
Two things bothered me while looking at the Altcha code path:
ALTCHA_HMAC_KEYis unset, each backend process generates its own random key. In any multi-worker / multi-pod setup that means a challenge issued by one process can fail verification on another, and every restart silently invalidates pending challenges. Right now this fails open in a confusing way.What
backend/config.py: refuse to start in non-debug mode whenALTCHA_HMAC_KEYis empty. Dev still gets the auto-generated key, with a warning so it's obvious it's ephemeral.backend/arena/captcha.py: when the Redis call raises, return(False, "Replay check unavailable")instead of allowing the request through. Old fail-open behavior is still available behind a new env flag (ALTCHA_FAIL_OPEN_ON_REDIS_ERROR) for deliberate degraded-mode operation..env.example: documents both flags.Test plan
LANGUIA_DEBUG=false ALTCHA_HMAC_KEY=""→ raises (verified)LANGUIA_DEBUG=true ALTCHA_HMAC_KEY=""→ ephemeral key + warning (verified)