Security News
New Proposed CISA Mandate Would Require Critical Infrastructure to Report Ransom Payments Within 24 Hours
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
forwarded-for
Advanced tools
Abstraction for retrieving ip address information from a Node.js connection. Searches for proxy headers before degrading req.address
Weekly downloads
Readme
When you are hosting your applications behind a reverse load balancer the incoming requests will no longer have the IP address of your user but of the load balancer as it forwards the request to your node instance. Most load balancers allow you to modify the headers of the request and add original request information in it.
This module makes it easier to find the correct IP address of your connection by
detecting these headers that load balancers set and it will gracefully fall down
to the original req.address
that contained the IP address of the request
inside node.js. In addition to gracefully degrading to the original request we
also for other known locations of the address (which are usually set by
frameworks such as SockJS and Socket.IO etc.)
The module is released in the npm registry:
npm install --save forwarded-for
Let's start out with including the module in to your application:
'use strict';
var forwarded = require('forwarded-for');
The forwarded
variable will now contain the function which parses out the
request information for you in to a really simple object. This object contains
the following properties:
port
The remote port. It defaults to 0
.ip
The string representation of the remoteAddress. It defaults to '127.0.0.1'.When we fail to parse or detect an IP address we will use the default values to construct the object. To correctly parse the data the function requires the following arguments:
obj
The socket like object that probably contains the remoteAddressheaders
A reference to the HTTP headers of the requestwhitelist
, optional A white list of IP addresses of your load balancers so
people cannot make fake requests with x-forwarded-for
headers.So with all the information combined, it would look something like this:
'use strict';
var forwarded = require('forwarded-for');
require('http').createServer(function (req, res) {
var address = forwarded(req, req.headers);
res.end('Your ip address is '+ address.ip);
}).listen(8080);
MIT
FAQs
Abstraction for retrieving ip address information from a Node.js connection. Searches for proxy headers before degrading req.address
The npm package forwarded-for receives a total of 16,017 weekly downloads. As such, forwarded-for popularity was classified as popular.
We found that forwarded-for demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
Security News
Redis is no longer OSS, breaking its explicit commitment to remain under the BSD 3-Clause License forever. This has angered contributors who are now working to fork the software.
Product
Socket AI now enables 'AI detected potential malware' alerts by default, ensuring users benefit from AI-powered state-of-the-art malware detection without needing to opt-in.