JOHN SILLVESTOR commited on
Commit
3d57d50
·
verified ·
1 Parent(s): f2e6885

Reject foreign browser origins

Browse files
Files changed (1) hide show
  1. server.js +6 -1
server.js CHANGED
@@ -194,7 +194,7 @@ function openTicket(hex) {
194
  function cors(req, res) {
195
  const o = req.headers.origin || "";
196
  const allow = isSiteOrigin(o);
197
- if (allow) res.setHeader("Access-Control-Allow-Origin", o);
198
  res.setHeader("Vary", "Origin");
199
  res.setHeader("Access-Control-Allow-Methods", "GET,POST,HEAD,OPTIONS");
200
  res.setHeader("Access-Control-Allow-Headers", "Authorization,Content-Type,Range");
@@ -3276,6 +3276,11 @@ async function onReq(req, res) {
3276
  }
3277
  cors(req, res);
3278
  if (url.pathname === "/admin/tg-meta") applyAdminCors(req, res);
 
 
 
 
 
3279
  if (req.method === "OPTIONS") {
3280
  res.writeHead(204, { "Content-Length": "0" });
3281
  return res.end();
 
194
  function cors(req, res) {
195
  const o = req.headers.origin || "";
196
  const allow = isSiteOrigin(o);
197
+ res.setHeader("Access-Control-Allow-Origin", allow ? o : SITE_ORIGIN);
198
  res.setHeader("Vary", "Origin");
199
  res.setHeader("Access-Control-Allow-Methods", "GET,POST,HEAD,OPTIONS");
200
  res.setHeader("Access-Control-Allow-Headers", "Authorization,Content-Type,Range");
 
3276
  }
3277
  cors(req, res);
3278
  if (url.pathname === "/admin/tg-meta") applyAdminCors(req, res);
3279
+ const reqOrigin = String(req.headers.origin || "");
3280
+ if (reqOrigin && !isSiteOrigin(reqOrigin)) {
3281
+ res.writeHead(403, { "Content-Length": "0", "Cache-Control": "no-store" });
3282
+ return res.end();
3283
+ }
3284
  if (req.method === "OPTIONS") {
3285
  res.writeHead(204, { "Content-Length": "0" });
3286
  return res.end();