Repository navigation
fix(backend): centralize request boundary validation - #8367
Conversation
- add shared request validation helpers for multipart JSON, query bounds, calendar dates, sync filenames, and image chunks - validate app/persona form JSON through a common helper - enforce bounded list/history query parameters and real calendar dates - validate sync upload timestamps with UTC-aware parsing - reject invalid websocket image chunk envelopes instead of silently ignoring them - validate parallel event/action-item status arrays at the request-model boundary Supersedes parts of #8218, #8219, #8220, #8222, #8227, #8231, #8260, #8263, #8275, #8278, #8279, #8280, #8295, #8303, #8309, #8321. Original issue discovery, reproductions, and candidate fixes by @ZachL111. Co-authored-by: ZachL111 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d98c3d48db
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
5 issues found across 15 files
Confidence score: 3/5
- In
backend/routers/sync.py,get_timestamp_from_pathno longer accepts bare{timestamp}.wavVAD segment names becauseparse_sync_filename_timestamponly handles underscore-delimited formats, which can break sync processing for existing files—restore bare-timestamp support before merging to avoid a regression. - In
backend/routers/apps.py, the auth_steps URL guard can still raise on malformedauth_stepstypes, causing a 500 instead of a client-facing 422; this turns bad input into server errors—add type-safe validation/guarding so invalid payloads are rejected cleanly. - In
backend/routers/apps.py, whitespace-onlywebhook_urlvalues bypass the required-field check and can persist as effectively empty URLs—trim then validate non-empty content before accepting updates. backend/routers/sync.pyandbackend/utils/request_validation.pyinclude redundant/dead validation branches, which is low severity but increases drift risk over time—remove or consolidate these checks to keep one clear validation contract.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="backend/routers/apps.py">
<violation number="1" location="backend/routers/apps.py:499">
P2: `webhook_url` required check is bypassed by whitespace-only values, allowing empty webhook URLs after trimming.</violation>
<violation number="2" location="backend/routers/apps.py:745">
P2: The new auth_steps URL guard can still crash with malformed `auth_steps` types, returning 500 instead of a validation 422.</violation>
</file>
<file name="backend/routers/sync.py">
<violation number="1" location="backend/routers/sync.py:673">
P1: `get_timestamp_from_path` now rejects VAD segment filenames like `{timestamp}.wav` because `parse_sync_filename_timestamp` only parses underscore-delimited names. Keep support for bare timestamp filenames here, otherwise sync jobs can fail after VAD when segment paths are sorted/parsed.</violation>
<violation number="2" location="backend/routers/sync.py:695">
P3: Timestamp range validation is duplicated after delegating to `parse_sync_filename_timestamp`, leaving redundant dead-check logic that can drift from the shared contract.</violation>
</file>
<file name="backend/utils/request_validation.py">
<violation number="1" location="backend/utils/request_validation.py:91">
P3: `self.index >= cached_total` check is unreachable after prior validators/checks, so this branch is dead code.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Git-on-my-level
left a comment
There was a problem hiding this comment.
Addressed the timestamp parser regression.
Change:
parse_sync_filename_timestampnow accepts both upload names (audio_<timestamp>.bin) and generated VAD segment names (<timestamp>.wav), while preserving the same seconds/millis normalization and range validation.
Verification:
ENCRYPTION_SECRET=*** VIRTUAL_ENV= uv run pytest tests/unit/test_request_validation_contracts.py -q→25 passed
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c3a5dab556
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Add hermetic route-level coverage for validation behavior introduced by the request-boundary aggregate PR: - malformed app/persona multipart JSON is rejected before fake storage writes - real touched routes reject invalid query/date bounds without 500s - v2 sync uploads reject invalid filename timestamps before job/storage side effects - invalid listen image chunks close the WebSocket with policy violation Timed hermetic e2e locally: - before: 73 passed, 6 skipped in 9.22s pytest / 11.89s wall - after: 78 passed, 6 skipped in 9.51s pytest / 12.25s wall Runtime delta: +0.29s pytest, +0.36s wall.
|
Harness follow-up pushed in Added
Local timing, same worktree/venv:
The wall-time delta is effectively noise/slightly faster on the final run; the added coverage does not materially increase hermetic CI runtime. I also checked the new file standalone with durations: app setup dominates (~3.2s), while the actual added route calls are small; the websocket test is ~0.6s after using the multi-channel path to avoid the existing 7s pending-conversation sweeper. |
|
Correction after rebasing onto the latest branch head: the harness commit is now Re-ran the full hermetic e2e harness after the rebase:
Measured delta: +5 e2e tests, about +0.46s pytest runtime / +0.46s wall time on this machine. CI is running on the pushed SHA now. |
There was a problem hiding this comment.
1 issue found across 1 file (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="backend/routers/sync.py">
<violation number="1" location="backend/routers/sync.py:673">
P1: `get_timestamp_from_path` now rejects VAD segment filenames like `{timestamp}.wav` because `parse_sync_filename_timestamp` only parses underscore-delimited names. Keep support for bare timestamp filenames here, otherwise sync jobs can fail after VAD when segment paths are sorted/parsed.</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
|
Addressed the unresolved review feedback in PR #8367. Changed:
Verification passed:
|
Summary
This aggregates the high-signal request/protocol-boundary fixes from @ZachL111 into shared validation helpers instead of endpoint-by-endpoint patches.
Changes:
utils.request_validationfor multipart JSON form parsing, bounded query params, real calendar dates, UTC-safe sync filename timestamps, and image chunk envelopessys.meta_path/MagicMock-heavy app JSON test with direct helper contract coverageSupersedes/redesigns parts of #8218, #8219, #8220, #8222, #8227, #8231, #8260, #8263, #8275, #8278, #8279, #8280, #8295, #8303, #8309, #8321.
Original issue discovery, reproductions, and candidate fixes by @ZachL111 — thank you for surfacing these boundary bugs. This PR keeps the useful findings while moving the implementation toward shared contracts and smaller tests.
Deferred from the Oracle boundary bucket
Not included here because they need separate design or would broaden this PR:
Test plan
pytest tests/unit/test_request_validation_contracts.py tests/unit/test_sync_file_paths_filename_none.py tests/unit/test_apps_create_app_json.py tests/unit/test_conversation_events_bounds.py -q→ 34 passedpython -m py_compile ...over modified modules/testsgit diff --checkbash backend/testing/e2e/run.sh -q --tb=short→ 73 passed, 6 skipped