Skip to content

banditcallback: forward client IP via True-Client-IP#669

Merged
reflog merged 1 commit into
mainfrom
reflog/banditcallback-client-ip
May 22, 2026
Merged

banditcallback: forward client IP via True-Client-IP#669
reflog merged 1 commit into
mainfrom
reflog/banditcallback-client-ip

Conversation

@reflog
Copy link
Copy Markdown
Contributor

@reflog reflog commented May 22, 2026

Why

The arm-callback emitter introduced in #668 fires GET /v1/bandit/callback?token=arm-…&did=… from the proxy VPS. The API-side handler resolves ASN/country from the request's source IP via MaxMind — but the source IP is the VPS's egress (Linode/OCI/Hetzner), not the device's. Per-ASN blocking signals on the lantern-cloud side were keyed to the hosting ASN, so the data fed into selection-time scoring never matched the (country, asn) keys the selector reads back. Effectively dead data.

Caught in Copilot review on lantern-cloud#2792.

What

  • Filter.Apply pulls client IP from req.RemoteAddr (same source opsfilter uses for measured reporting)
  • EmitIfFirstSeen(ctx, deviceID, clientIP) — clientIP is forwarded as True-Client-IP header when non-empty
  • Empty clientIP omits the header entirely so the API's existing RemoteAddr fallback path stays intact
  • Per-arm token already authenticates the caller as a provisioned proxy daemon, so trusting True-Client-IP on the arm-callback endpoint is safe (consumer-side trust gate lands in lantern-cloud#2792)

Test plan

  • go test ./banditcallback/... — passes (existing tests + new TestEmitter_OmitsTrueClientIPWhenEmpty; TestEmitter_FirstSeenFires asserts the header lands)
  • go build ./http-proxy/ — binary compiles
  • Merge → nightly deb → flip staging global setting bandit_vps_http_proxy_default_short_tag
  • Verify on staging: arm-callback request hits API with True-Client-IP: <device IP>; bandit:blocking-signals:* keys land under the device's ASN, not the VPS's

🤖 Generated with Claude Code

Without this, the API-side handleArmCallback derives ASN/country from
the request's source IP, which is the proxy VPS's egress — not the
device. Per-ASN blocking signals were keyed to the hosting ASN
(Linode/OCI/Hetzner) rather than the client's ISP, so the data fed into
selection-time scoring never matched the (country, asn) keys the
selector reads back.

Filter.Apply now pulls the client IP from req.RemoteAddr (same source
opsfilter uses for measured reporting) and passes it to EmitIfFirstSeen,
which sets True-Client-IP on the outbound callback when non-empty. Empty
clientIP omits the header entirely so the API's existing RemoteAddr
fallback path stays intact. The per-arm token already authenticates the
caller as a provisioned proxy daemon, so trusting True-Client-IP on the
arm-callback endpoint is safe.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@reflog reflog merged commit 8448614 into main May 22, 2026
1 check passed
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.

1 participant