Files
MyIP/server/referer-check.js
jason5ng32andClaude Opus 5.5 c29e48687b Refactor(layout): split backend-only code out of common/, group frontend utils
common/ had become the backend's library: 30 of its 41 modules were
imported by nothing in the frontend, so the name no longer said what
belonged there. It now holds only what the frontend or the build imports
too; backend-only code moved to server/, flat except for datasets/ (the
dataset engine and its readers). The *-db/ dataset directories stay in
common/: self-hosting docs and Docker volumes mount those paths.

frontend/utils/ keeps its app-wide modules at the root and gains ip/
(IP / ASN shaping and validation), report/ (the report pipeline) and
features/ (the pure layer of a single feature). Paths only — no logic
changes. The Dockerfile copies server/, and the AGENTS.md files say where
a new module goes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 13:10:02 +08:00

23 lines
770 B
JavaScript

// dotenv.config() is called once in backend-server.js before any handler
// imports this module, so process.env.ALLOWED_DOMAINS is already populated.
// Avoid the duplicate call to keep this a pure, fast function.
function refererCheck(referer) {
const allowedDomains = ['localhost', ...(process.env.ALLOWED_DOMAINS || '').split(',')];
if (referer) {
// Scanners send garbage Referer headers; a parse failure means
// "not an allowed origin", never a thrown 500.
let domain;
try {
domain = new URL(referer).hostname;
} catch {
return false;
}
return allowedDomains.includes(domain);
}
return false; // if no referer is provided, return false
}
export { refererCheck };