Skip to content

fix(chat): STRICT routes answer not-yours exactly like not-found (#20413) - #21015

Merged
mrveiss merged 10 commits into
mainfrom
issue-20413-strict-404
Nov 8, 2026
Merged

mrveiss merged 10 commits into
mainfrom
issue-20413-strict-404

Conversation

@mrveiss

@mrveiss mrveiss commented Nov 7, 2026 •

Copy link
Copy Markdown
Owner

Thinking Path

Finding: cancel_chat_turn answered 403 for another user's conversation, and the same call for an unknown id answered 200 no_active_turn (a write lets an id with no session through as legacy_unowned), so ids were enumerable both ways. The session trace already mapped to 404 with its own private copy of the mapping; the conversation-file owner routes mapped NotSessionOwner inline with a literal body. Three copies of one decision.

Fix: one decision point in security/session_posture.py: session_not_found() (status and body) and validate_strict_hidden(session_id, request, must_exist=...). Turn cancel and trace call it; the file owner routes and unowned_access use session_not_found(). The real denial is still logged server side (_strict_owner_check). An unreadable owner stays 403 (#14033). The STRICT attachment checks in chat_streaming.py return a boolean and never a status, so they reveal nothing.

Exception recorded: the admin-only file routes need no change. Admins pass STRICT for any id and non-admins get the admin gate's 403 for every id, so the response does not depend on whether the id exists.

What Changed

  • autobot-backend/security/session_posture.py: session_not_found, validate_strict_hidden; unowned_access uses it.
  • autobot-backend/api/chat_turn.py: uses validate_strict_hidden(..., must_exist=True).
  • autobot-backend/api/chat_trace.py: private mapping removed, uses the helper.
  • autobot-backend/api/conversation_files.py: owner routes call validate_strict_hidden(..., must_exist=True); the admin-only routes keep the explicit 403 branch.
  • autobot-backend/api/chat_turn_17273_test.py: 403 assertion now 404, plus foreign-equals-unknown (byte-identical status and body) and a seam test.
  • changelog/unreleased/20413-strict-routes-404.md.

Verification

  • pytest -q api/chat_turn_17273_test.py api/chat_trace_19963_test.py api/conversation_files_owner_routes_20195_test.py: 38 passed. The owner still succeeds (cancel 200; trace 200).
  • Control: with the four source files restored to origin/main, chat_turn_17273_test.py gives 3 failed, 4 passed (non-owner 404, foreign-equals-unknown, strict-validator seam).
  • Per route: turn cancel (new test), trace (test_a_non_owner_gets_the_response_a_missing_session_gets), file owner routes (bug(chat): a file attached to a chat message never reaches the answer #20195 test).
  • repo_tests: ownership validator, env var, route-form, changelog branch, file size ratchet: pass. black, isort, flake8 clean.

Closes #20413

Model Used

Claude Sonnet 5.5

Single-issue rationale: one security defect class (existence leak on STRICT routes) fixed once in the shared helper; it touches no file another open PR holds.

Review follow-up (local commit): api/strict_routes_hidden_20413_test.py pins, for trace and the five file owner routes, foreign == unknown byte-identical, owner succeeds, unreadable owner 403; for the admin-only routes, a non-admin gets the same 403 for existing and unknown ids and an admin passes. Control: with validate_strict_hidden neutralised, 9 tests fail (trace, 4 panel routes, upload, 3 cancel tests).

@mrveiss mrveiss added this to the M3 - Refined GUI complete milestone Nov 7, 2026
@mrveiss mrveiss added the phase:M3.9 Chat, Agents, Analytics and Settings screens label Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Notice: 29 open PRs — past the runaway threshold (25)

This is not a request to defer this PR. There is no cap on open PRs (#19397) -- nothing blocks opening or pushing a PR.

This notice only means the count is high enough to be worth a glance for a runaway — something opening PRs in a loop, or a merge pipeline that has stalled so nothing is draining.

Currently open:

If the queue is draining normally, ignore this. Otherwise:

  1. Check whether CI is dispatching at all — see the ci-dispatch-watchdog status on these PRs
  2. Approved PRs land through the merge train the coordinator sequences (merge commits, never squash) -- check the open chore(merge-train) PR is moving, not each PR on its own
  3. Look for a loop opening near-identical PRs

Warn-only runaway detector — .github/workflows/pr-queue-gate.yml. It never blocks a merge.

@coderabbitai

coderabbitai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 9 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between fdcc815 and d6ed226.

Files ignored due to path filters: 1

  • scripts/python_file_size_known_large.py is excluded by !scripts/python_file_size_known_large.py
Files selected for processing: 7

  • autobot-backend/api/chat_trace.py
  • autobot-backend/api/chat_turn.py
  • autobot-backend/api/chat_turn_17273_test.py
  • autobot-backend/api/conversation_files.py
  • autobot-backend/api/strict_routes_hidden_20413_test.py
  • autobot-backend/security/session_posture.py
  • changelog/unreleased/20413-strict-routes-404.md
Walkthrough

Strict chat routes and existing-only file operations now use shared 404 handling for specified inaccessible conversations. Tests verify matching responses for foreign and unknown conversations and confirm refused cancellation does not change turn state or checkpoints.

Changes: Strict-route conversation access

Layer / File(s) Summary
Shared hidden validation
autobot-backend/security/session_posture.py
Adds session_not_found() and validate_strict_hidden(). The validator maps NotSessionOwner and, when must_exist=True, legacy_unowned to the shared 404 response.
Route integration and validation
autobot-backend/api/chat_trace.py, autobot-backend/api/chat_turn.py, autobot-backend/api/conversation_files.py, autobot-backend/api/chat_turn_17273_test.py, changelog/unreleased/20413-strict-routes-404.md
Chat trace and cancellation routes use the shared validator. Existing-only file operations use the shared 404 helper for specified ownership failures. Tests check response equality and cancellation state; the changelog records the response behaviour.
Merge Risk: Low · previous review fdcc8

Unknown-session cancellations by administrators can return success instead of 404. This is a bounded inconsistency; normal-user response hiding is supported, with additional file-route test coverage recommended.

Pre-merge checks: Passed 5

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title describes the main change: STRICT chat routes return the same response for another user's session as for an unknown session.
Docstring Coverage Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentati…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 5 functions across 5 files. (1 skipped: 1 unsupported.)

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between abb3d51 and fdcc815.

Files selected for processing: 6

  • autobot-backend/api/chat_trace.py
  • autobot-backend/api/chat_turn.py
  • autobot-backend/api/chat_turn_17273_test.py
  • autobot-backend/api/conversation_files.py
  • autobot-backend/security/session_posture.py
  • changelog/unreleased/20413-strict-routes-404.md

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@mrveiss

mrveiss commented Nov 7, 2026

Copy link
Copy Markdown
Owner Author

Code review (code-reviewer pass) at fdcc815

Verdict: CHANGES NEEDED

Security check, traced through the code: a foreign session (NotSessionOwner from _strict_owner_check) and an unknown session (unowned_access for GET, or must_exist on legacy_unowned for the POST) both end in the single session_not_found(), so status and body are byte-identical on trace and cancel. The owner path is intact: owner_match and the admin decisions are returned untouched. An unreadable owner stays 403 independent of the id. The one gap is test coverage of that claim on the GET routes.

Severity file:line finding suggested fix
major autobot-backend/api/chat_trace.py (_require_readable) and autobot-backend/api/conversation_files.py:85-90 The behaviour changed on two routes with no test change: chat_trace_19963_test.py and conversation_files_owner_routes_20195_test.py are untouched, and the byte-identical foreign-vs-unknown assertion is only written for turn cancel. The trace route's new foreign-vs-unknown equivalence (including the unreadable-owner 403 staying 403) is unproven, and it was the route that carried the old private 404 mapping. Add a foreign-vs-unknown byte-equality test and an unreadable-owner-stays-403 test for the trace route, parametrized next to the cancel test.
minor autobot-backend/api/conversation_files.py:85-90 Second implementation left in place: this route still catches NotSessionOwner itself and maps it to session_not_found(), plus its own legacy_unowned check, which is what validate_strict_hidden(..., must_exist=existing_only) now does. It cannot be switched over blindly because existing_only=False re-raises the 403. Use validate_strict_hidden for the existing_only branch so there is one decision point; keep the 403 branch explicit.
minor autobot-backend/api/chat_turn_17273_test.py (test_the_route_goes_through_the_strict_validator) The spy replaces security.session_posture.validate_strict and asserts only that it was called with the session id. It no longer pins that the posture is STRICT or that must_exist is set (the old test pinned the posture). Removing must_exist=True at chat_turn.py:56 would not fail any test, and that argument is what stops a cancel on a nonexistent id from passing. Add a cancel test on a nonexistent id as a non-admin (expects 404), and an admin control.
nit changelog/unreleased/20413-strict-routes-404.md:5 pr: 0000 placeholder. Fill in the PR number if the changelog check expects it.

@mrveiss

mrveiss commented Nov 7, 2026

Copy link
Copy Markdown
Owner Author

Code review (code-reviewer pass) at d0fffa1

Verdict: APPROVE

Head is 0 behind main, 8 changed files (6 ahead; the review-follow-up test file is now pushed). Body claims checked against the head: api/strict_routes_hidden_20413_test.py exists and covers trace, the five file owner routes (foreign == unknown byte-identical, owner succeeds, unreadable owner 403 for any id) and the admin-only routes (same 403 for existing and unknown ids; an admin passes). Turn cancel is pinned in chat_turn_17273_test.py. Both ACs of #20413 are met: every remaining STRICT caller answers a foreign and an unknown id the same, the admin-only exception is recorded with its reason, and a test pins each route. No fixed sleeps, no hardcoded config, no duplicate helper (the private trace mapping and the inline file-route mapping are replaced by session_not_found / validate_strict_hidden), new helpers are under 30 lines, conversation_files.py is 960 lines against a ceiling lowered to 960.

file severity finding / fix
autobot-backend/api/conversation_files_owner_routes_20195_test.py (open thread, chat_turn test) LOW The owner-route comparison pits a foreign id against an unknown one; an existing but unowned session (owner None, exists True) is not compared on the file routes. Non-blocking: the helper's must_exist path is pinned for cancel. Add the third case when the file is next touched.
autobot-backend/security/session_posture.py validate_strict_hidden (open thread) LOW An admin cancelling an unknown id gets 200 no_active_turn, not 404. Intended and pinned by a test: an admin may already read every session, so no id is revealed to a non-admin. Reply on the thread with that reason.

Threads: 2 unresolved (both CodeRabbit, both addressed above as non-blocking). None resolved by me, since the head code does not itself answer either.

@mrveiss

mrveiss commented Nov 7, 2026

Copy link
Copy Markdown
Owner Author

Code review (code-reviewer pass) follow-up at 5acc4dd

Trainmaster item How it is addressed
File routes: a file that exists but is not owned by the caller must answer byte-equal to the not-found response Added test_owner_routes_file_in_another_conversation_is_byte_identical_to_an_unknown_file in strict_routes_hidden_20413_test.py (preview, download, delete); the delete 404 echoes the caller's own id, which the test masks before the byte comparison.
Admin cancel of an unknown id returns 200 Intentional; pinned by chat_turn_17273_test.py::test_cancel_on_a_nonexistent_id_is_404_for_a_user_but_not_an_admin. Replied on the thread.

Branch merged with current main before the push.

@mrveiss

mrveiss commented Nov 7, 2026

Copy link
Copy Markdown
Owner Author

Code review (code-reviewer pass) at 5acc4dd

Verdict: APPROVE. 8 files changed, 0 behind main. Reviewed the author commit 009093c since d0fffa1.

# Severity Where Finding
1 Verified strict_routes_hidden_20413_test.py::test_owner_routes_file_in_another_conversation_is_byte_identical_to_an_unknown_file For preview, download and delete, a file that exists in another conversation is requested through the caller's own conversation and compared with an id that does not exist. Status and body must match. Delete echoes the caller's own file id in its 404 detail, so the test masks that id on both sides and compares everything else. Status is also pinned to 403 or 404.
2 LOW same test status_code in (403, 404) is loose. The equality assertion is the real check, so this is not blocking.
3 Note scope The existing-but-ownerless conversation case on the file routes is not asserted. By design that case is let through as legacy_unowned, not hidden, so there is no byte-equality to pin.

Threads: 1 unresolved on entry (the chat_turn_17273_test.py missing/unowned comparison). The head now pins the missing-conversation case (existing tests) and the existing-file-in-another-conversation case (new test), and the author replied with the test name. Resolved. The other thread (session_posture.py) was already resolved, so no admin-cancel thread is open.

@mrveiss

mrveiss commented Nov 8, 2026

Copy link
Copy Markdown
Owner Author

Landed on main via merge train #21105 (merge commit 4304868); every commit of head d6ed226 is in main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

phase:M3.9 Chat, Agents, Analytics and Settings screens

Projects

None yet

Development

Successfully merging this pull request may close these issues.

security(chat): STRICT routes still reveal whether a conversation exists (403 vs 404)

1 participant