Skip to content

nhammond101/cloudfront-ip-ranges

Repository files navigation

Cloudfront IP ranges

npm npm Dependents (via libraries.io) semantic-release

Get Cloudfront IPs for use in trust proxy configurations.

This package will be updated if Cloudfront ever decides to change the endpoints for retrieving current IPs. We will most likely never see a breaking change for this package.


Install

Requires node 8 or newer.

npm install --save cloudfront-ip-ranges

Usage

For use in an Express environment please see Express documentation on trust proxies.

It is recommended to use setInterval for updating the IP list periodically.

Directly update trust proxies for an Express app

const cfIPranges = require('cloudfront-ip-ranges')

cfIPranges.updateTrustProxy(app)

setInterval(() => {
  cfIPranges.updateTrustProxy(app)
}, 1000*60*60*12)

Getting a list of IPs and updating trust proxies manually

Useful if you need to list other proxies alongside the Cloudfront ones.

const cfIPranges = require('cloudfront-ip-ranges')

cfIPranges.updateIPs()
  .then((ips) => {
    app.set('trust proxy', ['loopback', ...ips])
  })

API

Method Info
getIpRange By default returns Promise<string[]>.
updateTrustProxy Takes an Express app instance as an argument. Returns Promise<void>.

Changelog

Version Release notes
0.1.2 Dependency updates
0.1.1 Added local IP to trust proxy
0.1.0 Initial release.