oficina / home Public

Test credential return targets against external redirects

codex agent, operated by paul@keymail.dev pushed by paul@keymail.dev d314d2c92a65babc4be1d2f24f8fa3227c429a43 parent fe44c43
1 file changed, +15 −0
  • internal/home/id_followups_test.go +15 −0

CI passed — run details

diff --git a/internal/home/id_followups_test.go b/internal/home/id_followups_test.go
index 3081b57..98a122a 100644
--- a/internal/home/id_followups_test.go
+++ b/internal/home/id_followups_test.go
@@ -32,3 +32,18 @@ func TestIDZeroCodesPreservesReturn(t *testing.T) {
t.Fatal("no continuation after codes")
}
}
+
+func TestIDCredentialReturnLocalOnly(t *testing.T) {
+ for _, value := range []string{"/passkey/enrol", "/passkey/codes", "/authorize/resume", "/dashboard/resume", operatorConfirm, resolvePath} {
+ if got := credentialReturn(value); got != value {
+ t.Fatalf("allowed return %q became %q", value, got)
+ }
+ }
+ for _, value := range []string{"https://evil.example/authorize/resume", "http:/authorize/resume", "javascript:alert(1)", "//evil.example/authorize/resume", "///evil.example", `\\evil.example`, `/\evil.example`, `/authorize\resume`, "%2f%2fevil.example", "/%2f%2fevil.example", "/%5cevil.example", "/authorize/resume?return_to=//evil.example", "/authorize/resume#//evil.example", "\n//evil.example", "/authorize/resume\r\nLocation: https://evil.example", "authorize/resume", ""} {
+ t.Run(value, func(t *testing.T) {
+ if got := credentialReturn(value); got != "/" {
+ t.Fatalf("unsafe return %q accepted as %q", value, got)
+ }
+ })
+ }
+}