{"version":3,"sources":["jsdelivr-header.js","/npm/cors-gate@1.1.3/index.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,ACNA,MAAM,IAAM,QAAQ,OAgBpB,SAAS,SAAS,GAYhB,GAA8B,iBAX9B,EAAU,OAAO,OAAO,CACtB,QAAQ,EACR,WAAW,EACX,OAAA,CAAQ,EAAK,EAAK,GAGhB,EAAI,WAAa,IACjB,EAAI,KACN,GACC,IAEgB,OACjB,MAAM,IAAI,MAAM,qCAGlB,MAAM,EAAa,EAAQ,OAAO,cAC5B,EAAU,EAAQ,QAExB,OAAO,SAAS,EAAK,EAAK,GACxB,MAAM,GAAU,EAAI,QAAQ,QAAU,IAAI,cAAc,OAExD,IAAK,EAAQ,CACX,MAAM,KAA4C,mBAAtB,EAAQ,UAA2B,EAAQ,UAAU,EAAK,GAAO,EAAQ,WAErG,OAAI,EAAQ,QAAY,IAAsD,IAAzC,CAAC,MAAO,QAAQ,QAAQ,EAAI,QAI1D,IAHE,EAAQ,EAAK,EAAK,EAI7B,CAGA,GAAI,IAAW,EAAY,OAAO,IAIlC,MAAM,GAAe,EAAI,UAAU,gCAAkC,IAAI,cAAc,OAIvF,GAAqB,MAAhB,GAAyB,IAAW,EAAc,OAAO,IAG9D,EAAQ,EAAK,EAAK,EACpB,CACF,CAoBA,SAAS,2BACP,OAAO,SAAS,EAAK,EAAK,GAExB,IADe,EAAI,QAAQ,OACd,CACX,MAAM,EAAM,EAAI,QAAQ,QACxB,GAAI,EAAK,CACP,MAAM,EAAQ,IAAI,MAAM,GACxB,EAAI,QAAQ,OAAS,IAAI,OAAO,CAC9B,SAAU,EAAM,SAChB,KAAM,EAAM,MAEhB,CACF,CACA,GACF,CACF,CAEA,SAAS,yBAA2B,SAAS,wBAA0B,yBAEvE,OAAO,QAAU","file":"/npm/cors-gate@1.1.3/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/cors-gate@1.1.3/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const url = require('url');\n\n/**\n * Gate requests based on CORS data. For requests that are not permitted via CORS, invoke the\n * failure options callback, which defaults to rejecting the request.\n *\n * @param {Object} options\n * @param {String} options.origin The origin of the server - requests from this origin will always\n *   proceed.\n * @param {Boolean=} options.strict Whether to reject requests that lack an Origin header. Defaults\n *   to true.\n * @param {Boolean|Function=} options.allowSafe Whether to enforce the strict mode for safe requests (HEAD,\n *   GET). Defaults to true. A function can be passed here, that will be passed req and res and should return a boolean.\n * @param {Function=} options.failure A standard connect-style callback for handling failure.\n *   Defaults to rejecting the request with 403 Unauthorized.\n */\nfunction corsGate(options) {\n  options = Object.assign({\n    strict: true,\n    allowSafe: true,\n    failure(req, res, next) {\n      // Set `statusCode` vs. using `res#status`, as https://github.com/expressjs/cors does, so this\n      // will work with any Connect-compatible server.\n      res.statusCode = 403;\n      res.end();\n    }\n  }, options);\n\n  if (typeof options.origin !== 'string') {\n    throw new Error(\"Must specify the server's origin.\");\n  }\n\n  const thisOrigin = options.origin.toLowerCase();\n  const failure = options.failure;\n\n  return function(req, res, next) {\n    const origin = (req.headers.origin || '').toLowerCase().trim();\n\n    if (!origin) {\n      const allowSafe = !!(typeof options.allowSafe === 'function' ? options.allowSafe(req, res) : options.allowSafe);\n      // Fail on missing origin when in strict mode, but allow safe requests if allowSafe set.\n      if (options.strict && (!allowSafe || ['GET', 'HEAD'].indexOf(req.method) === -1)) {\n        return failure(req, res, next);\n      }\n\n      return next();\n    }\n\n    // Always allow same-origin requests.\n    if (origin === thisOrigin) return next();\n\n    // Now this is a cross-origin request. Check if we should allow it based on headers set by\n    // previous CORS middleware. Note that `getHeader` is case-insensitive.\n    const otherOrigin = (res.getHeader('access-control-allow-origin') || '').toLowerCase().trim();\n\n    // Two values: allow any origin, or a specific origin.\n    // https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Access-Control-Allow-Origin\n    if ((otherOrigin === '*') || (origin === otherOrigin)) return next();\n\n    // CSRF! Abort.\n    failure(req, res, next);\n  };\n}\n\n/**\n * If the Origin header is missing, fill it with the origin part of the Referer.\n *\n * Firefox does not send the Origin header for same-origin requests, as of version 53. This is a\n * documented bug, so this middleware enables verification of the Origin in that case. Additionally,\n * no browser sends the Origin header when sending a GET request to load an image. We could simply\n * allow all GET requests - GET requests are safe, per HTTP - but we'd rather reject unauthorized\n * cross-origin GET requests wholesale.\n *\n * At present, Chrome and Safari do not support the strict-origin Referrer-Policy, so we can only\n * patch the Origin from the Referer on Firefox. In patching it, however, we can reject unauthorized\n * cross-origin GET requests from images, and once Chrome and Safari support strict-origin, we'll\n * be able to do so on all three platforms.\n *\n * In order to actually reject these requests, however, the patched Origin data must be visible to\n * the cors middleware. This middleware is distinct because it must appear before cors and corsGate\n * to perform all the described tasks.\n */\nfunction originFallbackToReferrer() {\n  return function(req, res, next) {\n    const origin = req.headers.origin;\n    if (!origin) {\n      const ref = req.headers.referer;\n      if (ref) {\n        const parts = url.parse(ref);\n        req.headers.origin = url.format({\n          protocol: parts.protocol,\n          host: parts.host\n        });\n      }\n    }\n    next();\n  };\n}\n\ncorsGate.originFallbackToReferrer = corsGate.originFallbackToReferer = originFallbackToReferrer;\n\nmodule.exports = corsGate;\n"]}