fix(flowsafe): contain malformed-path URIError in P6 routers (pre-auth)#33
Merged
Conversation
…-auth) The signal, goal, and schedule routers decoded the threadId/schedule-id path segment with bare decodeURIComponent before authentication and outside their try block, and createFlowsafeWorker.fetch wrapped the router calls in no try/catch — so an unauthenticated request with malformed percent-encoding (e.g. POST /api/threads/%/message) threw a URIError out of fetch() as a per-request 500. Introduce a shared, zero-dependency safeDecodeSegment leaf (host-kit, internal — imported directly, not barrel-exported) that treats malformed encoding as route-absent (byte-identical to a non-matching path); adopt it in the three routers, the background-tasks read route (whole-class, post-auth), and dedupe the local copy in the Track E webhook router. Add a top-level try/catch in the worker fetch handler as defense-in-depth (generic 500, no error.message leak, structured log). Behavior-preserving for all valid paths. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
anchorage-showcase | 97cb097 | Jul 18 2026, 02:23 AM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes a confirmed pre-auth defect discovered during Track E's review (post-program hardening).
The bug
The P6 ingestion routers (
signals/router.ts,goals/objective-routes.ts,schedules/router.ts) decoded the threadId/schedule-id path segment with baredecodeURIComponentbefore authentication and outside their try block, andcreateFlowsafeWorker.fetchwrapped the router calls in no try/catch. So an unauthenticated request with malformed percent-encoding —POST /api/threads/%/message,PUT /api/threads/%/goal,GET /api/schedules/%— threw aURIErrorout offetch()as a per-request 500 with a logged exception. Bounded (per-request, no data leak, no amplification, no isolate crash), but a real pre-auth exposure. Track E's own webhook router already did this correctly with a localsafeDecodeSegment.The fix
host-kit/route-path.ts—safeDecodeSegment(zero-dependency leaf; returnsundefinedon malformed encoding). Internal: imported directly by the routers, not barrel-exported, so no new public API and the changeset stays apatch.null), byte-identical to a non-matching path (no audit, no existence oracle — the null path is pre-resolve).background-tasks/routes.ts, post-auth, DO-mounted) adopts it too → malformed taskId returns its no-oracle 404 instead of throwing. Deduped the local copy from the Track E webhook router.createFlowsafeWorker.fetchcontains any handler throw (present or future) as a generic 500 — noerror.messageleaked to the client, logged asworker-fetch-error.Behavior-preserving for all valid paths (the removed
?? ''fallback was dead — the path-shape length guard already guarantees the segment exists; the schedules list route still yieldsid=undefinedand composes).Verification
spike:verify— green, run independently (3 gate runs across the change's evolution).%,%zz,a%, undefined), one malformed-%test per router (route-absent / 404, asserting no-audit / no-write / no-throw), and the worker backstop (an injected throwing router → generic 500 +worker-fetch-errorlog).patchis unambiguous and the import source is uniform. Confirmed no otherdecodeURIComponent/decodeURI/unescapein the defect class (run-router and the DO fetch handlers split pathname but never decode; INV-1 runIds are[a-z0-9_]).🤖 Generated with Claude Code