Skip to content

fix: prevent query params leaking into typed session dict#854

Open
temrjan wants to merge 1 commit intoAnswerDotAI:mainfrom
temrjan:fix/session-dict-query-params
Open

fix: prevent query params leaking into typed session dict#854
temrjan wants to merge 1 commit intoAnswerDotAI:mainfrom
temrjan:fix/session-dict-query-params

Conversation

@temrjan
Copy link
Copy Markdown

@temrjan temrjan commented Mar 27, 2026

Summary

Fixes #845

When a session parameter is type-hinted as dict, query parameters from the request leak into the session, eventually causing the session cookie to exceed its size limit and get cleared on every request.

Root Cause

In _find_p, the check if anno is dict: return data (line 201) runs before the session name check on line 203. Since _find_ps merges query params into data via data |= dict(conn.query_params), returning data for session: dict includes all query parameters.

# Before (broken order):
if anno is dict: return data          # ← catches session: dict, returns contaminated data
if _is_body(anno):
    if 'session'.startswith(arg.lower()): return conn.scope.get('session', {})  # ← never reached

Fix

Move the session name check before anno is dict:

# After (correct order):
if 'session'.startswith(arg.lower()) and _is_body(anno): return conn.scope.get('session', {})
if anno is dict: return data
if _is_body(anno):
    return await _from_body(conn, p, data)

Test Plan

  • Fixed test_get_toaster_with_typehint (was failing on main)
  • Added test_session_dict_no_query_param_leak regression test
  • All 6 tests pass

🤖 Generated with Claude Code

When a session parameter is type-hinted as `dict`, the `anno is dict`
check in `_find_p` returned the contaminated `data` dict (which includes
merged query params from `_find_ps`) before the session name check could
run.

Move the session name check before `anno is dict` so that `session: dict`
correctly returns `conn.scope['session']` instead of the request data.

Also fix the existing `test_get_toaster_with_typehint` test which was
failing on main due to this bug (missing toast setup step).

Closes AnswerDotAI#845

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Typehinting session parameter pulls in query parameters

1 participant