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`, `Request` or// Next.js' `NextRequest`const request = newRequest();
// Returns the first non-private IP address detectedconst globalIp = ip(request);
console.log(globalIp);
// Also optionally takes a platform for additional protectionconst platformGuardedGloablIp = ip(request, { platform: "fly-io" });
// You can also pass a list of trusted proxies to ignoreconst proxyExcludedGlobalIp = ip(request, { proxies: ["103.31.4.0"] });
Considerations
The IP should not be trusted as it can be spoofed in most cases, especially when
loaded via the Headers object. We apply additional platform guards if a
platform is supplied in the options argument.
If a private/internal address is encountered, it will be skipped. If only those
are detected, an empty string is returned.
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 8,109 weekly downloads. As such, @arcjet/ip popularity was classified as 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 2 open source maintainers collaborating on the project.
Package last updated on 04 Feb 2025
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.
Newly introduced telemetry in devenv 1.4 sparked a backlash over privacy concerns, leading to the removal of its AI-powered feature after strong community pushback.
TC39 met in Seattle and advanced 9 JavaScript proposals, including three to Stage 4, introducing new features and enhancements for a future ECMAScript release.