harden /api/orchestrate: cap intent input (ReDoS) + build compose steps in-process (SSRF) - #15
Open
sanjeevkkansal wants to merge 1 commit into
Open
harden /api/orchestrate: cap intent input (ReDoS) + build compose steps in-process (SSRF)#15sanjeevkkansal wants to merge 1 commit into
sanjeevkkansal wants to merge 1 commit into
Conversation
…ps in-process (SSRF) Cap the free-text intent at 2000 chars before it reaches parseIntent's heuristic regexes, so an unbounded body can't drive polynomial backtracking and stall the event loop (checkIntentText → 413; parseIntent clamps too, as defense-in-depth for any caller). The keyless heuristic path is the production parse, so this guards the live path. Build compose leaf steps by calling the build / build-yield route handlers in-process instead of self-fetching a URL whose host is derived from the incoming request — that host is attacker-controllable and made the self-fetch a self-SSRF vector. The leaf handlers only read their JSON body, so a direct call is equivalent with no network hop.
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.
What
Two security hardenings on the
/api/orchestratesurface.1. Cap natural-language intent input (ReDoS)
parseIntentHeuristicruns several regexes over the user's free text, and the keyless heuristic path is the production parse. An unbounded body could drive polynomial backtracking and stall the event loop. This caps the text before it reaches any regex:checkIntentText(newlib/orchestration/intent-input.ts) normalizes the body and rejects empty →400, over-cap (2000 chars) →413, at the request boundary inapp/api/orchestrate/route.ts.parseIntentalso clamps length, as defense-in-depth for any caller.Addresses the
js/polynomial-redosfindings inlib/orchestration/ai-router.ts.2. Build compose leaf steps in-process (SSRF)
build-compose-steppreviously derivedbaseHostfromnew URL(req.url).originand self-fetched${baseHost}/api/orchestrate/build. The request host is attacker-controllable, which made the self-fetch a self-SSRF vector. The leaf handlers (build,build-yield) only read their JSON body, so this calls them directly in-process — no network hop, no trust in the request host, behaviorally equivalent.Addresses the
js/request-forgeryfinding atapp/api/orchestrate/build-compose-step.Tests
tests/intent-input.test.ts(8 cases): empty/whitespace → 400, non-string → 400, exactly-at-cap accepted, over-cap → 413, and a fast-return assertion on a pathological ~20 KB body.tsc --noEmitclean.eslint0 errors.