Skip to content

fix(ctx): drop unsafe URLs in Redirect#46

Merged
joaomdsg merged 1 commit into
mainfrom
fix/redirect-validation
May 28, 2026
Merged

fix(ctx): drop unsafe URLs in Redirect#46
joaomdsg merged 1 commit into
mainfrom
fix/redirect-validation

Conversation

@joaomdsg

Copy link
Copy Markdown
Member

Summary

  • Ctx.Redirect now validates the URL before queueing a navigation frame: only http, https, and same-origin relative paths are honoured. javascript:, data:, vbscript:, protocol-relative //…, \\…, and whitespace/case variants are dropped and logged via app.logErr.
  • Leading bytes <= ' ' are trimmed before the scheme check to match how browsers parse schemes ( javascript:… collapses to javascript:…).
  • Table tests cover the safe + dangerous matrix and assert that a follow-up Toast frame still reaches the client, proving the SSE stream is unaffected.

Test plan

  • go test ./...
  • End-to-end verify against a live server (/tmp/via-verify app + curl + Brave): dangerous URLs produced no window.location.href frame and no browser navigation/alert; safe URLs emitted the expected redirect frame; server log shows Redirect: rejected unsafe URL "…" for every dropped case.

Ctx.Redirect previously forwarded any string to the client, so an
attacker-controlled value (typical ?next= flows) could yield
javascript:, data:, vbscript:, or protocol-relative // open-redirect /
XSS frames. Only http, https, and same-origin relative paths are now
honoured; everything else is dropped and logged. Leading whitespace
and control bytes are trimmed first to match browser scheme parsing.
@joaomdsg
joaomdsg merged commit 4ffe40b into main May 28, 2026
4 checks passed
@joaomdsg
joaomdsg deleted the fix/redirect-validation branch May 28, 2026 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant