Skip to content

Add IP_HEADER env var to override client IP source#20

Merged
luke-owen-crowdhandler merged 1 commit into
mainfrom
feature/override-ip-source
Jun 9, 2026
Merged

Add IP_HEADER env var to override client IP source#20
luke-owen-crowdhandler merged 1 commit into
mainfrom
feature/override-ip-source

Conversation

@luke-owen-crowdhandler

Copy link
Copy Markdown
Contributor

Allows customers behind an upstream proxy (eg. zScaler, Imperva) to point the worker at a different header (typically x-forwarded-for) so the real client IP, rather than the proxy egress IP, is sent to the CrowdHandler API. For multi-value headers the left-most entry is used. Falls back to cf-connecting-ip if the configured header is missing/empty or anything throws, so existing deployments are unaffected.

Allows customers behind an upstream proxy (eg. zScaler, Imperva) to point
the worker at a different header (typically x-forwarded-for) so the real
client IP, rather than the proxy egress IP, is sent to the CrowdHandler
API. For multi-value headers the left-most entry is used. Falls back to
cf-connecting-ip if the configured header is missing/empty or anything
throws, so existing deployments are unaffected.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an environment-variable-controlled override for how the worker determines the client IP address, enabling deployments behind upstream proxies to forward the intended client IP to the CrowdHandler API while preserving the existing cf-connecting-ip behavior as a fallback.

Changes:

  • Introduces IP_HEADER env var support to optionally read the client IP from a specified request header (with left-most parsing for comma-separated values).
  • Adds defensive fallback behavior to default back to cf-connecting-ip on missing/empty overrides or runtime errors.
  • Regenerates built artifacts in dist/ to reflect the updated worker logic.

Reviewed changes

Copilot reviewed 1 out of 4 changed files in this pull request and generated 1 comment.

File Description
index.js Adds IP_HEADER-based IP resolution with fallback to cf-connecting-ip.
dist/index.js Updates compiled worker output to include the new IP resolution logic.
dist/index.js.map Updates source map to match the rebuilt output.
dist/README.md Updates build timestamp for the regenerated dist/ artifacts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread index.js
Comment on lines +147 to +155
if (env.IP_HEADER) {
const overrideValue = requestHeaders[env.IP_HEADER.toLowerCase()]
if (overrideValue) {
const parsed = overrideValue.split(',')[0].trim()
if (parsed) {
IPAddress = parsed
}
}
}
@luke-owen-crowdhandler luke-owen-crowdhandler merged commit c1dafa3 into main Jun 9, 2026
1 check passed
@luke-owen-crowdhandler luke-owen-crowdhandler deleted the feature/override-ip-source branch June 9, 2026 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants