Socket
Socket
Sign inDemoInstall

@arcjet/ip

Package Overview
Dependencies
Maintainers
0
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@arcjet/ip

Arcjet utilities for finding the originating IP of a request


Version published
Weekly downloads
1.3K
increased by24.81%
Maintainers
0
Weekly downloads
 
Created
Source
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` or next.js'
// `NextRequest`
const request = new NextRequest();
// A `Headers` object, which is passed separately for cases where it needs to be
// constructed or sanitized
const headers = new Headers();

// Returns the first non-private IP address detected
const 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.

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.

FAQs

Package last updated on 01 Jul 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc