(redirectUri: string)
| 65 | }; |
| 66 | |
| 67 | export function validateRedirectUriFormat(redirectUri: string): void { |
| 68 | if (!/^[a-z][a-z0-9+\-.]*:\/\/.+/.test(redirectUri)) { |
| 69 | throw new HTTPException(400, { |
| 70 | message: "Must be a valid URL with a scheme (e.g. https://...)", |
| 71 | }); |
| 72 | } |
| 73 | let parsed: URL; |
| 74 | try { |
| 75 | parsed = new URL(redirectUri); |
| 76 | } catch { |
| 77 | throw new HTTPException(400, { |
| 78 | message: "Must be a valid URL with a scheme (e.g. https://...)", |
| 79 | }); |
| 80 | } |
| 81 | if (parsed.hash) { |
| 82 | throw new HTTPException(400, { |
| 83 | message: "Redirect URI must not include a fragment", |
| 84 | }); |
| 85 | } |
| 86 | if (!isAllowedRedirectUrl(parsed)) { |
| 87 | throw new HTTPException(400, { |
| 88 | message: |
| 89 | "Redirect URI must use https://, except http:// is allowed for loopback hosts", |
| 90 | }); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | function parseMetadata( |
| 95 | raw: string | null | undefined, |
no test coverage detected