Skip to content

feat(rate-limit): make trustProxy configurable in keyGenerator default #767

Description

@tada5hi

Pre-existing issue found during PR review

Reported in: PR #766, review comment by @coderabbitai[bot]
File: packages/rate-limit/src/utils/options.ts#19

Description

The default keyGenerator hardcodes trustProxy: true when calling getRequestIP():

keyGenerator: (event) => getRequestIP(event, { trustProxy: true }) || '127.0.0.1',

This enables inspection of forwarded headers (X-Forwarded-For) by default, which could allow clients to spoof IPs and evade rate limiting in non-proxied or misconfigured deployments.

This has been the default behavior since v1 and was carried through the v5 migration in PR #766.

Suggested fix

  1. Add a trustProxy boolean field to the Options type (default false)
  2. Update the default keyGenerator to use options.trustProxy instead of hardcoded true
  3. Update README documentation to reflect the new option

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions