Solve the fork's ALTCHA captcha on login (and every request) #189
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix-altcha-captcha"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Login against an instance with captcha turned on failed with "This instance requires a captcha…". The client now does the ALTCHA proof of work the server asks for and sends the request again, the same way the web app does.
What the fork does (the code in
~/src/fluxer-soundboard)fluxer_api/pkgs/captcha/src/providers/AltchaProvider.ts:10,67-78, altcha-lib 2.5.0pow.js) uses ALTCHA v2 withPBKDF2/SHA-256, not the classic SHA-256 counter search. The key is PBKDF2-HMAC-SHA-256 withcostiterations andkeyLength(32) bytes, the password is thenoncebytes followed by the counter as a big-endian u32, and the salt is thesaltbytes. The server picks the counter at random in[max_counter/2, max_counter]and publishes the first 16 bytes of that key askeyPrefix. The client tries counters from 0 up until the key starts withkeyPrefix.fluxer_app/src/features/auth/altcha/AltchaSolver.ts:38-40):base64(JSON.stringify({challenge:{parameters,signature},solution:{counter,derivedKey,time}})), sent inX-Captcha-Token(packages/constants/src/Headers.ts:27).verify(AltchaProvider.ts:80-105) checks the token length (at most 4096), the cost (>= minCost), the expiry (10 min), the HMAC signature and the HMAC key signature, and accepts each token only once.CaptchaMiddleware.ts:77-95: when there is no token the server answers 400CAPTCHA_REQUIRED. When the token is bad it answers 400INVALID_CAPTCHA. Both answers carry a fresh challenge, and the cost can double up to 6 times.CaptchaInterceptor.ts:76,80-143: the web app handles every request this way, with at most 2 solves per request, and gives up after 60 s (AltchaSolver.ts:10). It uses up to 8 workers that try interleaved counters.Changes
fluxer-api: a newcaptchamodule with challenge parsing, a pure solver (solve, threads × interleaved counters) and token encoding.ApiClient::executesolves the challenge and retries every request, with at mostMAX_SOLVES = 2solves. The search runs inspawn_blockingon at most 8 threads. It stops after 60 s, at the challenge's expiry by the local clock (an expiry that is already in the past counts as clock skew and is ignored), or when the request future is dropped.INVALID_CAPTCHAnow maps toCaptchaRequiredinstead of a plain 400, which the core used to read as wrong credentials.ApiError::CaptchaRequirednow only means a captcha the client could not solve: unknown provider, malformed or non-PBKDF2 challenge, timeout, or both solutions refused.fluxer-core(doc comments only) andfluxer-ui: the message now says what actually happened. While the client solves, the login screen keeps showing its usual "Logging in…", so there is no new UI.ring0.17 influxer-api. It is already in the graph through rustls/reqwest, so nothing new gets compiled. The onlyCargo.lockchange is that one edge.Tests
fixtures/captcha/altcha_login.jsoncomes from the fork's ownAltchaProvider: a throwaway node script outside both repos imported the provider directly. It holds a challenge, the solution and the web client's token, and the provider verified that token. The unit tests solve this vector on 1, 3 and 8 threads, and check that the encoded token matches the web client's byte for byte.tests/captcha.rshas a wiremock server that issues and verifies tokens the way the fork does. The checker is itself checked against the fork's fixture token. The tests cover: CAPTCHA_REQUIRED then an accepted token; a rejected token, then the fresh challenge, then success (3 sends); retries exhausted (exactly 3 sends, thenCaptchaRequired); login_totp and a GET also covered; unknown provider andINVALID_CAPTCHAwithout a challenge are not retried. Malformed bodies return errors and never panic.AltchaProvider.verify.cargo test --release -p fluxer-api --test captcha -- --ignored --nocapture.FLUXER_SCREENSHOT_TESTS=1 cargo xtask cipasses locally.I did not change
fluxer-devserver: it does not model a captcha, and it would need a signing server half to do so.🤖 Generated with Claude Code