Skip to content

Commit

Permalink
Merging c876d6f into trunk-temp/pr-2235/c6e4541f-9f2c-4ec5-98ff-271a9…
Browse files Browse the repository at this point in the history
…dab106b
  • Loading branch information
trunk-io[bot] authored Nov 19, 2024
2 parents 7ddc386 + c876d6f commit d4560bc
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions ip/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,26 @@ npm install -S @arcjet/ip
```ts
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();
// 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, headers);
const globalIp = ip(request);
console.log(globalIp);

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

## Considerations

The IP should not be trusted as it can be spoofed in most cases, especially when
loaded via the `Headers` object.
loaded via the `Headers` object. We apply additional platform guards if a
platform is supplied in the `options` argument.

In non-production environments (`NODE_ENV !== "production"`), we allow
private/internal addresses so that the SDKs work correctly locally.
If a private/internal address is encountered, it will be skipped. If only those
are detected, an empty string is returned.

## Implementation

Expand Down

0 comments on commit d4560bc

Please sign in to comment.