Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ip): Update documentation for previous breaking changes #2278

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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