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,SAAW,CAAC,EAAK,IACrB,EAGE,EAAI,WAAW,SAAW,IAAI,2BAA2B,GAAW,IAAI,0BAA0B,GAF9F,EAAI,WAAW,SAAW,iBAAmB","file":"/npm/request-filtering-agent@3.0.2/lib/request-filtering-agent.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/request-filtering-agent@3.0.2/lib/request-filtering-agent.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","import * as net from \"node:net\";\nimport * as http from \"node:http\";\nimport * as https from \"node:https\";\nimport ipaddr from \"ipaddr.js\";\nimport * as dns from \"node:dns\";\nexport const DefaultRequestFilteringAgentOptions = {\n    allowPrivateIPAddress: false,\n    allowMetaIPAddress: false,\n    allowIPAddressList: [],\n    denyIPAddressList: []\n};\n/**\n * validate the address that is matched the validation options\n * @param address ip address\n * @param host optional\n * @param family optional\n * @param options\n */\nconst validateIPAddress = ({ address, host, family }, options) => {\n    // if it is not IP address, skip it\n    if (net.isIP(address) === 0) {\n        return;\n    }\n    try {\n        const addr = ipaddr.parse(address);\n        const range = addr.range();\n        // prefer allowed list\n        if (options.allowIPAddressList.length > 0 && options.allowIPAddressList.includes(address)) {\n            return;\n        }\n        if (!options.allowMetaIPAddress) {\n            // address === \"0.0.0.0\" || address == \"::\"\n            if (range === \"unspecified\") {\n                return new Error(`DNS lookup ${address}(family:${family}, host:${host}) is not allowed. Because, It is meta IP address.`);\n            }\n        }\n        // TODO: rename option name\n        if (!options.allowPrivateIPAddress && range !== \"unicast\") {\n            return new Error(`DNS lookup ${address}(family:${family}, host:${host}) is not allowed. Because, It is private IP address.`);\n        }\n        if (options.denyIPAddressList.length > 0 && options.denyIPAddressList.includes(address)) {\n            return new Error(`DNS lookup ${address}(family:${family}, host:${host}) is not allowed. Because It is defined in denyIPAddressList.`);\n        }\n    }\n    catch (error) {\n        return error; // if can not parse IP address, throw error\n    }\n    return;\n};\nconst makeLookup = (createConnectionOptions, requestFilterOptions) => {\n    // @ts-expect-error - @types/node has a poor definition of this callback\n    return (hostname, options, cb) => {\n        const lookup = createConnectionOptions.lookup || dns.lookup;\n        let lookupCb;\n        if (options.all) {\n            lookupCb = ((err, addresses) => {\n                if (err) {\n                    cb(err);\n                    return;\n                }\n                for (const { address, family } of addresses) {\n                    const validationError = validateIPAddress({ address, family, host: hostname }, requestFilterOptions);\n                    if (validationError) {\n                        cb(validationError);\n                        return;\n                    }\n                }\n                cb(null, addresses);\n            });\n        }\n        else {\n            lookupCb = ((err, address, family) => {\n                if (err) {\n                    cb(err);\n                    return;\n                }\n                const validationError = validateIPAddress({ address: address, family: family, host: hostname }, requestFilterOptions);\n                if (validationError) {\n                    cb(validationError);\n                    return;\n                }\n                cb(null, address, family);\n            });\n        }\n        // @ts-expect-error - @types/node has a poor definition of this callback\n        lookup(hostname, options, lookupCb);\n    };\n};\n/**\n * A subclass of http.Agent with request filtering\n */\nexport class RequestFilteringHttpAgent extends http.Agent {\n    requestFilterOptions;\n    constructor(options) {\n        super(options);\n        this.requestFilterOptions = {\n            allowPrivateIPAddress: options && options.allowPrivateIPAddress !== undefined\n                ? options.allowPrivateIPAddress\n                : DefaultRequestFilteringAgentOptions.allowPrivateIPAddress,\n            allowMetaIPAddress: options && options.allowMetaIPAddress !== undefined\n                ? options.allowMetaIPAddress\n                : DefaultRequestFilteringAgentOptions.allowMetaIPAddress,\n            allowIPAddressList: options && options.allowIPAddressList\n                ? options.allowIPAddressList\n                : DefaultRequestFilteringAgentOptions.allowIPAddressList,\n            denyIPAddressList: options && options.denyIPAddressList\n                ? options.denyIPAddressList\n                : DefaultRequestFilteringAgentOptions.denyIPAddressList\n        };\n    }\n    // override http.Agent#createConnection\n    // https://nodejs.org/api/http.html#http_agent_createconnection_options_callback\n    // https://nodejs.org/api/net.html#net_net_createconnection_options_connectlistener\n    createConnection(options, connectionListener) {\n        const { host } = options;\n        if (host !== undefined) {\n            // Direct ip address request without dns-lookup\n            // Example: http://127.0.0.1\n            // https://nodejs.org/api/net.html#net_socket_connect_options_connectlistener\n            const validationError = validateIPAddress({ address: host }, this.requestFilterOptions);\n            if (validationError) {\n                throw validationError;\n            }\n        }\n        // https://nodejs.org/api/net.html#net_socket_connect_options_connectlistener\n        return super.createConnection({ ...options, lookup: makeLookup(options, this.requestFilterOptions) }, connectionListener);\n    }\n}\n/**\n * A subclass of https.Agent with request filtering\n */\nexport class RequestFilteringHttpsAgent extends https.Agent {\n    requestFilterOptions;\n    constructor(options) {\n        super(options);\n        this.requestFilterOptions = {\n            allowPrivateIPAddress: options && options.allowPrivateIPAddress !== undefined ? options.allowPrivateIPAddress : false,\n            allowMetaIPAddress: options && options.allowMetaIPAddress !== undefined ? options.allowMetaIPAddress : false,\n            allowIPAddressList: options && options.allowIPAddressList ? options.allowIPAddressList : [],\n            denyIPAddressList: options && options.denyIPAddressList ? options.denyIPAddressList : []\n        };\n    }\n    // override http.Agent#createConnection\n    // https://nodejs.org/api/http.html#http_agent_createconnection_options_callback\n    // https://nodejs.org/api/net.html#net_net_createconnection_options_connectlistener\n    createConnection(options, connectionListener) {\n        const { host } = options;\n        if (host !== undefined) {\n            // Direct ip address request without dns-lookup\n            // Example: http://127.0.0.1\n            // https://nodejs.org/api/net.html#net_socket_connect_options_connectlistener\n            const validationError = validateIPAddress({ address: host }, this.requestFilterOptions);\n            if (validationError) {\n                throw validationError;\n            }\n        }\n        // https://nodejs.org/api/net.html#net_socket_connect_options_connectlistener\n        return super.createConnection({ ...options, lookup: makeLookup(options, this.requestFilterOptions) }, connectionListener);\n    }\n}\nexport const globalHttpAgent = new RequestFilteringHttpAgent();\nexport const globalHttpsAgent = new RequestFilteringHttpsAgent();\n/**\n * Get an agent for the url\n * return http or https agent\n * @param url\n * @param options\n */\nexport const useAgent = (url, options) => {\n    if (!options) {\n        return url.startsWith(\"https\") ? globalHttpsAgent : globalHttpAgent;\n    }\n    return url.startsWith(\"https\") ? new RequestFilteringHttpsAgent(options) : new RequestFilteringHttpAgent(options);\n};\n"]}