(req: Request, res: Response, next: NextFunction)
| 2 | import { config } from "../config.js"; |
| 3 | |
| 4 | export function httpsRedirect(req: Request, res: Response, next: NextFunction) { |
| 5 | if (config.disableHttpsRedirect) return next(); |
| 6 | if (req.headers["x-forwarded-proto"] === "http") { |
| 7 | // Only use the Host header (not x-forwarded-host) to prevent open redirects |
| 8 | const host = (req.headers["host"] || "").replace(/[^\w.\-:]/g, ""); |
| 9 | if (!host) return next(); |
| 10 | return res.redirect(301, `https://${host}${req.url}`); |
| 11 | } |
| 12 | next(); |
| 13 | } |
no test coverage detected