Proxy Agent Policies

These methods will allow you to use the Proxy Agent family of third party modules within your application. This includes the following npm modules:

  • proxy-agent
  • http-proxy-agent
  • https-proxy-agent
  • socks-proxy-agent
  • pac-proxy-agent

These methods exist on the policy.proxyAgent object as seen in the following example:

(policy) => {
  policy.proxyAgent.allowUrl('https://proxy.example.org:8080/proxy');
}

intrinsic.virtualizeLib('proxy-agent')

Note that to enable the Proxy Agent family of modules we need to first call .virtualizeLib('proxy-agent'):

// Intrinsic for Lambda
module.exports = new IntrinsicLambda()
  .virtualizeLib('proxy-agent')
  // ...
  .run();

// Intrinsic for Node.js
intrinsic(__filename)
  .virtualizeLib('proxy-agent')
  // ...
  .run();

Also note that you don't need to use the exact name of the module you would like to virtualize. Just provide the string proxy-agent and Intrinsic will automatically take care of whatever libraries you happen to be using, such as socks-proxy-agent.

policy.proxyAgent.allowUrl(exactProxyUrl)

The allowUrl() method allows your application to connect to the specified URL for proxying requests. Note that unlike our other URL-based policies, the URL parameter exactProxyUrl only accepts an exact URL, not a glob pattern.

Pass whatever URL you would use for making a proxy connection through this method and it will work as expected.

(policy) => {
  // http-proxy-agent
  policy.proxyAgent.allowUrl('http://proxy-server-over-tcp.com:3128');

  // https-proxy-agent
  policy.proxyAgent.allowUrl('https://proxy-server-over-tls.com:3129');

  // socks-proxy-agent
  policy.proxyAgent.allowUrl('socks://username:password@some-socks-proxy.com:9050');
  policy.proxyAgent.allowUrl('socks5://username:password@some-socks-proxy.com:9050');
  policy.proxyAgent.allowUrl('socks4://some-socks-proxy.com:9050');

  // pac-proxy-agent
  policy.proxyAgent.allowUrl('pac+http://www.example.com/proxy.pac');
}

You will need to call this if you either see the following error, or if you otherwise want to enable an proxy agents using one of the above libraries:

POLICY_VIOLATION sb: "/-[[GET]]"
  | "https://proxy.example.org:8080/proxy" not in ProxyAgent whitelist