π A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!
Vue awesomedashboarddockerhomelabhomepagemitnodejsorganizationproductivitypwaself-hostedstartpagevue
π Restrict host and prototocol for cors proxy
Alicia Sykes0c09a812459e
diff --git a/services/cors-proxy.js b/services/cors-proxy.jsindex 6a71baa5..474d5767 100644--- a/services/cors-proxy.js+++ b/services/cors-proxy.js@@ -6,6 +6,44 @@const request = require('./request');+// List of hosts to disallow by default, for cloud instances+// Covers AWS, Azure, GCP, DO, Hetzner, Oracle, etc on IPv4/6+const BLOCKED_HOSTS = new Set([+ '169.254.169.254',+ '::ffff:a9fe:a9fe',+ 'fd00:ec2::254',+ 'metadata.google.internal',+ '100.100.100.200',+]);++// Operator escape hatch, set this env var to bypass all proxy restrictions+const restrictionsDisabled = !!process.env.DANGEROUSLY_DISABLE_PROXY_RESTRICTIONS;++// Validate the target URL against scheme and host policies+// Returns { ok: true } on success, or { ok: false, status, error } on rejection+const validateTargetUrl = (raw) => {+ if (restrictionsDisabled) return { ok: true };+ let url;+ try { url = new URL(raw); } catch (e) {+ return { ok: false, status: 400, error: 'Target-URL is not a valid URL' };+ }+ if (url.protocol !== 'http:' && url.protocol !== 'https:') {+ return { ok: false, status: 400, error: 'Target-URL must use http:// or https://' };+ }+ // url.hostname includes brackets for IPv6 (e.g. '[fd00:ec2::254]') - strip em+ const host = url.hostname.toLowerCase().replace(/^\[|\]$/g, '');+ if (BLOCKED_HOSTS.has(host)) {+ return {+ ok: false,+ status: 403,+ error: `Target-URL host '${host}' is blocked by the CORS proxy. `+ + 'This address is reserved for cloud instance metadata services. '+ + 'To bypass, set DANGEROUSLY_DISABLE_PROXY_RESTRICTIONS=true.',+ };+ }+ return { ok: true };+};+module.exports = (req, res) => {// Apply allow-all response headersres.header('Access-Control-Allow-Origin', '*');@@ -20,12 +58,18 @@ module.exports = (req, res) => {return;}- // Get desired URL, from Target-URL header+ // Get desired URL, from Target-URL header, and validate it against the policyconst targetURL = req.header('Target-URL');if (!targetURL) {res.status(400).send({ error: 'Missing required Target-URL header' });return;}+ const validation = validateTargetUrl(targetURL);+ if (!validation.ok) {+ res.status(validation.status).send({ error: validation.error });+ return;+ }+// Apply any custom headers, if neededlet headers = {};const rawCustomHeaders = req.header('CustomHeaders');@@ -38,7 +82,6 @@ module.exports = (req, res) => {}}-// Prepare the requestconst requestConfig = {method: req.method,