fix(app): skip csrf injection for off-origin post forms#785
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 095001874c
ℹ️ 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".
| if request.TLS != nil { | ||
| scheme = "https" | ||
| } else { | ||
| scheme = "http" |
There was a problem hiding this comment.
Honor forwarded HTTPS when deriving form origin
In the documented TLS-terminating reverse-proxy setup, the generated app receives plain HTTP with request.TLS == nil and X-Forwarded-Proto: https; this branch still defaults the origin to http, so an absolute same-site form action such as https://example.com/signup is treated as off-origin and no hidden CSRF field or cookie is injected, while the generated POST validator still requires CSRF. Reuse the existing HTTPS/proxy detection before defaulting to http so same-origin absolute HTTPS actions keep working behind the proxy.
Useful? React with 👍 / 👎.
| if scheme == "" || host == "" { | ||
| return false | ||
| } | ||
| actionURL, err := url.Parse(action) |
There was a problem hiding this comment.
Use browser URL parsing for form actions
When an HTML file reaches this runtime path with an action like ///evil.example/collect or /\evil.example/collect, Go's net/url resolves it as a same-host path, but browsers submit those forms as network-path URLs to evil.example (the repo's URL safety code already treats /\ as protocol-relative). In that scenario this check returns same-origin and injects the CSRF token into an off-origin POST form, reintroducing the token leak this commit is trying to prevent.
Useful? React with 👍 / 👎.
Summary
actionresolves to the current request origin.Issue Closure
Fixes #779
Verification
scripts/test-go-modules.shwhen Go code or compiler behavior changed.go build ./cmd/gowdkwhen CLI, compiler, runtime, addon, or release behavior changed.node --check editors/vscode/extension.jswhen editor files changed.Commands run:
go test ./runtime/app -count=1go test ./internal/appgen -run 'TestGenerate.*CSRF|TestSSR.*CSRF|TestGenerateSSR.*CSRF' -count=1go build ./cmd/gowdkgit diff --checkLLM Assistance