Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
The 'forwarded' npm package is designed to parse the 'X-Forwarded-For' header from an HTTP request, which is a standard header for identifying the originating IP address of a client connecting to a web server through an HTTP proxy or load balancer. This package extracts the IP addresses listed in the header and provides them in an array format, making it easier to handle cases where there are multiple proxies in use.
Parse X-Forwarded-For header
This feature allows you to parse the 'X-Forwarded-For' header from an HTTP request object and returns an array of IP addresses that were added by each proxy.
const forwarded = require('forwarded');
const req = { headers: { 'x-forwarded-for': '192.0.2.60, 198.51.100.17' } };
const ips = forwarded(req);
console.log(ips); // ['192.0.2.60', '198.51.100.17']
Similar to 'forwarded', 'proxy-addr' is used to determine the address of the client that connected to the proxy server. It provides more functionality, such as trusting custom IP address ranges and determining the client's IP address from a list of trusted proxies.
While 'ipware' is not limited to Node.js and is also available for Python, it offers similar functionality for getting the client's IP address from the 'X-Forwarded-For' header or other headers like 'X-Real-IP'. It also provides features to customize trusted proxies and private IP ranges.
The 'request-ip' package is another alternative that retrieves the client's IP address from an HTTP request. It supports both IPv4 and IPv6 addresses and works with various headers, including 'X-Forwarded-For'. It is a simple and straightforward package for getting the client's IP address without additional configuration options.
Parse HTTP X-Forwarded-For header
This is a Node.js module available through the
npm registry. Installation is done using the
npm install
command:
$ npm install forwarded
var forwarded = require('forwarded')
var addresses = forwarded(req)
Parse the X-Forwarded-For
header from the request. Returns an array
of the addresses, including the socket address for the req
, in reverse
order (i.e. index 0
is the socket address and the last index is the
furthest address, typically the end-user).
$ npm test
FAQs
Parse HTTP X-Forwarded-For header
The npm package forwarded receives a total of 13,210,487 weekly downloads. As such, forwarded popularity was classified as popular.
We found that forwarded demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.