Repository navigation
[APPS-2953] Fix: check Origin, Host and Content-Type on the apps dev-server routes - #588
Conversation
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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.
🔵 Needs a closer look
The security-sensitive host-validation port warrants human confirmation across supported Vite versions despite no concrete defects being identified.
0 open findings
What changed in this PR
Hardens the Apps plugin’s three dev-server POST endpoints, which run before Vite’s own request checks.
Changes:
- Adds Host, Origin, and JSON content-type validation before handler execution.
- Integrates the guard with resolved Vite configuration.
- Adds unit and HTTP integration coverage, updates mocks, and documents request requirements.
| File | Description |
|---|---|
| packages/tests/src/_jest/helpers/mocks.ts | Defaults mock requests to same-origin JSON. |
| packages/plugins/apps/src/vite/index.ts | Creates and passes the configured host check. |
| packages/plugins/apps/src/vite/index.test.ts | Updates fake server configurations. |
| packages/plugins/apps/src/vite/dev-server.ts | Guards requests before route dispatch. |
| packages/plugins/apps/src/vite/dev-server.test.ts | Tests rejection and allowed preview requests. |
| packages/plugins/apps/src/vite/dev-server.integration.test.ts | Adds real-HTTP validation and Vite parity tests. |
| packages/plugins/apps/src/vite/dev-server-request-guard.ts | Implements request validation. |
| packages/plugins/apps/src/vite/dev-server-request-guard.test.ts | Covers host rules and request decisions. |
| packages/plugins/apps/README.md | Documents endpoint requirements and curl usage. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…n and allowed hosts The apps dev-server middleware runs before Vite's CORS and host-check middleware, so its POST routes (/__dd/debugBundle, /__dd/executeAction, /__dd/executeActionViaCloud) now check each request themselves: - the Host must pass the same rules as Vite's server.allowedHosts check, built from the resolved Vite config; - an Origin, when sent, must match the Host; - the body must be sent as Content-Type: application/json. Rejected requests get a 403 or 415 before any handler runs. Refs: APPS-2953 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
843fe71 to
a68c95a
Compare
|
/merge |
|
View all feedbacks in Devflow UI.
The expected merge time in
|
Motivation
/__dd/debugBundle,/__dd/executeActionand/__dd/executeActionViaCloudroutes are registered fromconfigureServer.server.allowedHostsmiddleware.Architecture
server.allowedHostsrules, because Vite doesn't export its check. It reads the resolved Vite config, including hosts added through Vite's__VITE_ADDITIONAL_SERVER_ALLOWED_HOSTS.httpswhile the dev server listens overhttp./__dd/*paths and non-POST requests go to the next middleware as before.Changes
9 changes across dev-server-request-guard.ts, dev-server.ts, index.ts, README.md and tests
packages/plugins/apps/src/vite/dev-server-request-guard.tspackages/plugins/apps/src/vite/dev-server.tspackages/plugins/apps/src/vite/index.tscurlexample.packages/plugins/apps/README.mdpackages/plugins/apps/src/vite/dev-server-request-guard.test.ts/__ddpaths fall through, and an allowed preview proxy host is served.packages/plugins/apps/src/vite/dev-server.test.tsconfigureServer-installed middleware, including a host-by-host parity check against Vite's own host check.packages/plugins/apps/src/vite/dev-server.integration.test.tsserver/previewconfig.packages/plugins/apps/src/vite/index.test.tscreateMockRequestsends same-origin JSON headers by default, overridable per test.packages/tests/src/_jest/helpers/mocks.tsQA Instructions
masterand once from this branch, driven withcurl(HTTP/1.1 and HTTP/2).text/plainbody, or under a Host outsideallowedHostsare rejected.localhostand under an allowed preview proxy host still get 200.vite devsession and the Vite-version parity check are in the second reproduction below.Manual QA reproduction: scripts, run command and full captured output
Layout: one directory holding the four scripts and an
app/fixture.FIXEDis a checkout of this branch andBASELINEa checkout ofmaster, each withyarn installandyarn workspace @datadog/vite-plugin buildrun.app/index.htmlapp/main.jsapp/backend/greet.backend.tsqa-server.cjsqa-curl.shqa-https-curl.shqa-run-all.shRun command:
Captured output:
Second reproduction: real
vite dev, Vite-version parity and the integration parity rowsReal
vite devwith a same-origin page.vite-dev-app/holds a copy of theapp/fixture plus this config. The dev server runs with local test keys and a preload that fails every non-loopback socket, so the executeAction handler's Datadog API call fails withfetch failed(500) on this branch and on master alike: the request passed the guard and reached the handler.vite-dev-app/vite.config.mjsloopback-only.cjsqa-vite-dev-client.cjsqa-vite-dev.shRun command and captured output (branch, then master):
Host check parity across Vite versions.
parity.cjslifts Vite's own host-check functions out of each version's publisheddistand compares them withcreateViteHostCheck, bundled from this branch.parity.cjsIntegration parity rows (real HTTP through the
configureServer-installed middleware, compared with Vite's own host check on aGET):yarn workspace @dd/tests test:unit packages/plugins/apps/src/vite/dev-server.integration.test.ts -t 'request origin and host checks over real HTTP' --verboseBlast Radius
/__ddPOST routes change. Production builds and the deployed package are unaffected: the guard is used only fromconfigureServer.Content-Type: application/json.curlneeds-H 'Content-Type: application/json', which the README now shows.server.allowedHostsrules reject now gets a 403 from these routes on every supported Vite version. That includes versions older than 5.4.12 or 6.0.9, which had no host check of their own.Out of Scope / Follow-ups
7 items deferred
createDevServerMiddlewareand its dispatch.server.allowedHosts: trueorserver.httpsturns the host check off, as Vite does; the Origin and content-type checks still apply.true.server.allowedHostsstill works on them at runtime.host-validation-middlewarepackage for the same rules.server.cors.originis the narrowest option.server.https) is covered by unit tests and manual QA, not an automated real-TLS test.Documentation
server.allowedHostsdebugBundlefetch)🤖 Generated with Claude Code