Skip to content

Restores request origin ip to `req.ip`. Denies other requests.

Notifications You must be signed in to change notification settings

clive-io/cloudflare-middleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cloudflare-middleware

Restores request origin ip to req.origin_ip. Denies other requests.

Usage

let app = express();
app.use(require("cloudflare-middleware")());

This is a safer alternative to naively using app.set("trust proxy");, as this checks CloudFlare IP address ranges.

This, however, has been deprecated in favor of the following:

const cloudflareIp = require('cloudflare-ip');

app.set('trust proxy', ip => {
  if(ip.startsWith('::ffff:'))
    ip = ip.substr(7);
  return ip == '127.0.0.1' || cloudflareIp(ip);
});

About

Restores request origin ip to `req.ip`. Denies other requests.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published