Repository navigation
fix(ctf): remove dead auth guard in challenge check & hint endpoints - #515
prince-shakyaa wants to merge 2 commits into
Conversation
…ints Fixes GenAI-Security-Project#514 ## Problem POST /api/v1/challenges/{id}/check and POST /api/v1/challenges/{id}/hint both used get_session_context + a manual 'if not session_context: raise 401' guard. Because get_session_context NEVER returns None (it always returns request.state.session_context set by SessionMiddleware), the guard was dead code — always False. Temporary/anonymous sessions passed through freely. Impact: - Any visitor could spam POST /check → inflated attempt counters in DB - Any visitor could spam POST /hint → full hint text revealed without auth ## Fix - Add get_authenticated_session_context to the import in challenges.py - Swap check_challenge and use_hint to Depends(get_authenticated_session_context) - Remove the now-redundant dead 'if not session_context' guards - get_authenticated_session_context raises HTTP 401 automatically when session_context.is_temporary is True (caller hasn't bound an email) GET /api/v1/challenges and GET /api/v1/challenges/{id} are unchanged — they intentionally remain publicly browsable. ## Tests New file: tests/unit/apps/ctf/test_challenge_auth.py (9 tests, all passing) BUG-514-001: temp session rejected on check_challenge PASS BUG-514-002: temp session rejected on use_hint PASS BUG-514-003: auth session not blocked (happy path) PASS BUG-514-004: check_challenge dependency introspection PASS BUG-514-005: use_hint dependency introspection PASS BUG-514-006: dead guard removed from check_challenge source PASS BUG-514-007: dead guard removed from use_hint source PASS BUG-514-008: end-to-end POST /check → HTTP 401 PASS BUG-514-009: end-to-end POST /hint → HTTP 401 PASS
|
Hey @saikishu @e2hln , |
|
Sai, do we want unauthenticated users to be able to get hints? |
Hey @joshlochner , i think there should be a difference between auth and unauth users.. |
Based on feedback on GenAI-Security-Project#514 and GenAI-Security-Project#515: the CTF is meant to be playable without signing up, so /check and /hint should keep working for temporary sessions. Go back to get_session_context, keep the dead `if not session_context` check removed, and rewrite the tests to cover the real routes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @joshlochner and @stealthwhizz for the input, and @c-thiam for the comment on #514. I've updated the PR based on that. It no longer requires login. Players without an account can still check progress and use hints, same as now. The PR now just removes the dead @saikishu if you'd like players without an account to get fewer hints, I'm happy to do that in a follow-up PR. Just let me know what limit you'd want. |
Based on feedback on GenAI-Security-Project#514 and GenAI-Security-Project#515: the CTF is meant to be playable without signing up, so /check and /hint should keep working for temporary sessions. Go back to get_session_context, keep the dead `if not session_context` check removed, and rewrite the tests to cover the real routes.
be3ccbd to
785e0a6
Compare
Fixes #514
Summary
Removes a login check in the challenge
checkandhintendpoints that never actually runs. Players without an account can still use both endpoints, same as today.What was wrong
check_challengeanduse_hintinfinbot/apps/ctf/routes/challenges.pyboth had this:This never runs.
get_session_contextalways returns a session, even for players who haven't signed up (temporary sessions), sosession_contextis never empty. The code looks like it blocks logged-out players, but it doesn't do anything. That's misleading for anyone reading or changing this code later.What this PR changes
finbot/apps/ctf/routes/challenges.pycheck_challengeanduse_hint.get_session_contexton both, so players without an account can still check progress and use hints.tests/unit/apps/ctf/test_challenge_auth.py(new)POST /checkand gets a 200 (and the attempt is recorded).POST /hintand gets a 200 with the hint text.get_session_context.if not session_contextcheck is gone from both.Behavior
/checkor/hint/checkor/hintif not session_contextcheckNo change for players. This is a cleanup plus tests.
Why not require login?
The first version of this PR switched both endpoints to
get_authenticated_session_context, which would block players without an account. Based on the comments here and on #514, the CTF is meant to be playable without signing up, so I took that out.Follow-up (not in this PR)
list_challengesandget_challengehave a similarif session_context:check that is always true. It's harmless there, so I left it alone to keep this PR small.Testing
The 3 failures are in
tests/unit/agents/test_specialized_agents.py. They fail onmaintoo and aren't related to this change.Checklist
/checkand/hintGET /challengesandGET /challenges/{id}unchanged