* Only same-origin absolute paths survive, so `?next=` can never become an open * redirect. `//evil.example` and `/\evil.example` are protocol-relative URLs in * a browser, not paths — hence the second character check.
(candidate: string | null)
| 124 | * a browser, not paths — hence the second character check. |
| 125 | */ |
| 126 | function safeNextPath(candidate: string | null): string { |
| 127 | if (!candidate || !candidate.startsWith('/')) return '/'; |
| 128 | if (candidate.startsWith('//') || candidate.startsWith('/\\')) return '/'; |
| 129 | return candidate; |
| 130 | } |
| 131 | |
| 132 | function loginRedirect(url: URL): Response { |
| 133 | const next = `${url.pathname}${url.search}`; |
no outgoing calls
no test coverage detected