Repository navigation
Add statically analyzed Go route and proxy configuration - #101551
timneutkens wants to merge 109 commits into
Conversation
Tests PassedCommit: f082284 |
8ac86ad to
b37fd4e
Compare
b37fd4e to
a4d00a7
Compare
a4d00a7 to
ce6cb53
Compare
ce6cb53 to
5f85fe1
Compare
5f85fe1 to
84c1fce
Compare
84c1fce to
fbec3b9
Compare
fbec3b9 to
015ab18
Compare
|
Addressed both questions in the latest review summary in 120eea4:
Focused verification passed: the actual Go parser/SDK/generated proxy wrapper served continuations, rewrites, and header overrides with the sibling handler; an actual-source hook check reproduced two overlay issues before the fix and one afterward, including fallback/config errors, fail-closed routing, and recovery. Rust formatting, Go formatting, Prettier, and ESLint passed. Full Next.js typechecking is blocked by missing dependencies in this checkout. Full native e2e tests were not run without a rebuilt native binding. |
4a0bd9e to
3cf4151
Compare
Vercel Agent Verified Review reviewed a newer commit and no longer requests changes: dismissing its change request on an earlier commit.
| // Go proxies can protect either runtime. A condition cannot safely | ||
| // select a resource when Go and JavaScript would see different values. |
There was a problem hiding this comment.
Does this correctly error even when deployed with the Vercel adapter?
There was a problem hiding this comment.
🤖 Confirmed: adapter runtimes bypass this Node guard. ea0c26c now fails adapter builds for Go proxy Has/Missing header or cookie conditions until adapters can enforce the same checks. Coverage verifies all four combinations fail and source-only adapter matchers still build. Header/cookie conditions remain supported by next dev and self-hosted next start; the restriction is documented.
There was a problem hiding this comment.
Seems like a footgun/security problem nevertheless?
There was a problem hiding this comment.
🤖 To clarify the enforcement: this is a hard build failure before onBuildComplete emits adapter output whenever proxy.go declares header or cookie Has/Missing conditions. Such a configuration cannot be deployed through adapterPath; all four combinations are tested. Source-only adapter matchers remain available. Self-hosted requests use the 400 guard. Can you point out the remaining scenario you are concerned about? Leaving this discussion open for that clarification.
There was a problem hiding this comment.
🤖 Restored header/cookie Has and Missing support in bf06ec6. The generated adapter listener now validates the relevant headers in both the Go proxy and every Go route, so skipping the proxy cannot bypass validation.
The adapter regression uses the ordinary JavaScript matcher without the Node Go-header guard. It verifies that the destination Go route rejects ambiguous duplicate and Connection-nominated headers while the proxy invocation count stays unchanged. All four condition combinations work; repeated Cookie fields and unrelated repeated headers remain supported.
Unit, dev/start config, security, Go route, type, and clippy checks pass. Leaving this open for re-review.
There was a problem hiding this comment.
🤖 Follow-up in f082284 keeps cookie Has/Missing supported and emits additional matchers that send repeated condition-cookie names through validation, including before JavaScript destinations. The Go entrypoint rejects these requests before calling the application's Proxy function.
Added regressions for both Has and Missing using the emitted JavaScript handlers. Local Prettier, ESLint, and Rust formatting checks pass; the updated runtime tests still need CI verification. Leaving this open for re-review.
| serverFields.goProxyConfigError = message | ||
| matchers = [{ regexp: '^/.*$', originalSource: '/:path*' }] | ||
| } | ||
| serverFields.middleware = { |
There was a problem hiding this comment.
Note
Unverified · Major — Dev render server keeps stale proxy.go matchers after a Config edit
loadNativeMiddleware puts the new proxy.go matchers in serverFields.middleware and the router's fsChecker, but never calls propagateServerField('middleware', ...). The render server's DevServer.middleware is set only when the watcher propagates, at setup-dev-bundler.ts:1352. A proxy.go edit fires the watcher quickly, but Turbopack has to finish the Go compile first, so the watcher usually propagates the old matchers. When the Turbopack compile finishes last, the router starts invoking the proxy for a newly matched path (for example after changing /account/:path* to /admin/:path*). The render server then re-checks the path against the old matchers in handleCatchallMiddlewareRequest, takes handleFinished(), and the route is served without running proxy.go. This lasts until some unrelated file change triggers the watcher again. The PR's own 'updates the proxy matcher after a literal edit' e2e test (edit to Source: "/", expect / to be matched) hits this ordering.
Needs your judgment: the review traced this through the code but couldn’t run anything to prove it.
What?
Add static configuration for experimental Go routes and proxies. Stacked on #101874.
Why?
Go handlers need duration and matching controls without executing application code during discovery. Static
proxy.Configis separate from per-request options such asproxy.WithRequestHeaders. Invalid proxy configuration must not let requests bypass the proxy or terminate the development server.How?
Parse entry-file literal declarations and publish validated settings through native descriptors, manifests, routing, and adapter output. Recognize the exact
next/go/proxyimport with default or named aliases; reject computed configuration and invalid duration types.When a native proxy fails compilation or static Config analysis, install catch-all/error state without reading a stale descriptor. Requests, including native Go routes, fail until successful recovery. The filesystem watcher preserves the newest native matchers at its commit point rather than overwriting failure or recovery state with an earlier snapshot. Stale Edge manifests cannot overwrite native proxy state.
The Go loader opts into throwing on invalid expanded matchers instead of calling process.exit; existing JavaScript callers keep their current behavior. The SDK remains one module with config types beside its proxy helpers.
Verification