mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-18 10:39:49 +00:00
Enhancement: allow disabling host header checking (#4967)
This commit is contained in:
parent
9d40b67d49
commit
16c1b2da9b
2 changed files with 7 additions and 3 deletions
|
@ -4,11 +4,11 @@ export function middleware(req) {
|
|||
// Check the Host header, if HOMEPAGE_ALLOWED_HOSTS is set
|
||||
const host = req.headers.get("host");
|
||||
const port = process.env.PORT || 3000;
|
||||
let allowedHosts = [`localhost:${port}`, `127.0.0.1:${port}`];
|
||||
const allowAll = process.env.HOMEPAGE_ALLOWED_HOSTS === "*";
|
||||
if (process.env.HOMEPAGE_ALLOWED_HOSTS) {
|
||||
allowedHosts = allowedHosts.concat(process.env.HOMEPAGE_ALLOWED_HOSTS.split(","));
|
||||
}
|
||||
if (!host || !allowedHosts.includes(host)) {
|
||||
if (!allowAll && (!host || !allowedHosts.includes(host))) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(
|
||||
`Host validation failed for: ${host}. Hint: Set the HOMEPAGE_ALLOWED_HOSTS environment variable to allow requests from this host / port.`,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue