@arcjet/ip
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-alpha.34 • Public • Published
Arcjet Logo

@arcjet/ip

npm badge

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 = new Request();

// Returns the first non-private IP address detected
const globalIp = ip(request);
console.log(globalIp);

// Also optionally takes a platform for additional protection
const platformGuardedGloablIp = ip(request, { platform: "fly-io" });

// You can also pass a list of trusted proxies to ignore
const 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.

Implementation

The implementation of this library is based on the Parser, global ipv4 comparisons, and global ipv6 comparisons in the Rust stdlib and the header lookups in the request-ip package. Both licensed MIT with licenses included in our source code.

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.

License

Licensed under the Apache License, Version 2.0.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.0-alpha.343,517latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.0-alpha.343,517
1.0.0-alpha.33165
1.0.0-alpha.32812
1.0.0-alpha.3198
1.0.0-alpha.301
1.0.0-alpha.293
1.0.0-alpha.28755
1.0.0-alpha.2712
1.0.0-alpha.2610
1.0.0-alpha.251
1.0.0-alpha.240
1.0.0-alpha.232
1.0.0-alpha.225
1.0.0-alpha.2125
1.0.0-alpha.204
1.0.0-alpha.191
1.0.0-alpha.184
1.0.0-alpha.172
1.0.0-alpha.161
1.0.0-alpha.154
1.0.0-alpha.140
1.0.0-alpha.132
1.0.0-alpha.120
1.0.0-alpha.111
1.0.0-alpha.100
1.0.0-alpha.92
1.0.0-alpha.80
1.0.0-alpha.70
1.0.0-alpha.60
1.0.0-alpha.50
1.0.0-alpha.41
1.0.0-alpha.30
1.0.0-alpha.20
1.0.0-alpha.10
1.0.0-alpha.00

Package Sidebar

Install

npm i @arcjet/ip

Homepage

arcjet.com

Weekly Downloads

5,428

Version

1.0.0-alpha.34

License

Apache-2.0

Unpacked Size

42 kB

Total Files

5

Last publish

Collaborators

  • blaine-arcjet
  • davidmytton