Arcjet utilities for finding the originating IP of a request.
Installation
npm install -S @arcjet/ip
Example
import ip from"@arcjet/ip";
// Some Request-like object, such as node's `http.IncomingMessage` or next.js'// `NextRequest`const request = newNextRequest();
// A `Headers` object, which is passed separately for cases where it needs to be// constructed or sanitizedconst headers = newHeaders();
// Returns the first non-private IP address detectedconst globalIp = ip(request, headers);
console.log(globalIp);
Considerations
The IP should not be trusted as it can be spoofed in most cases, especially when
loaded via the Headers object.
In non-production environments (NODE_ENV !== "production"), we allow
private/internal addresses so that the SDKs work correctly locally.
We've chosen the approach of porting Rust's IP Parser because capturing RegExps
can be the source of ReDoS attacks, which we need to avoid. We also wanted to
keep our implementation as close to Rust as possible because we will be relying
on the Rust stdlib implementation in the future, with a fallback to this
implementation. As such, we'll need to track changes in Rust's implementation,
even though it seems to change infrequently.
Arcjet utilities for finding the originating IP of a request
The npm package @arcjet/ip receives a total of 984 weekly downloads. As such, @arcjet/ip popularity was classified as not popular.
We found that @arcjet/ip demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.ย It has 0 open source maintainers collaborating on the project.
Package last updated on 09 Feb 2024
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.
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.