Let apps choose how the client IP on events is determined
Maintainers usually reply within 2 days
@sl0thentr0py is already working on this.
Since Nov 4, 2026.
Assessment
This issue has not been assessed yet.
Description
Problem Statement
With send_default_pii (data_collection.user_info in 7.x), Event#rack_env= sets user[:ip_address] from Utils::RealIp. It puts Client-IP and X-Real-IP first, then X-Forwarded-For from the right, then REMOTE_ADDR, and takes the first address that isn't a trusted proxy.
Some platforms pass those headers through from the client. Heroku's router, for one, appends the address it saw to X-Forwarded-For and passes Client-IP and X-Real-IP on as the client sent them. A client that sends Client-IP: 198.51.100.2 gets that address on its events, and the address the router saw is never used. trusted_proxies can't help: it only removes the listed proxies' addresses from those candidates, and the Client-IP value is whatever the client wrote, not a proxy, so it stays first.
real_ip.rb says spoofing "only makes data inaccurate, not insecure", and accuracy is the problem here: on such a platform the IP on an event is whatever the client chose. Only the app knows its topology, and so which header to read: the last X-Forwarded-For entry on Heroku, Fly-Client-IP on Fly.io, CF-Connecting-IP behind Cloudflare.
The only way we found that keeps the SDK's own rules is to override the private Event#calculate_real_ip_from_rack(env):
module ClientIP
private
def calculate_real_ip_from_rack(env)
env["HTTP_X_FORWARDED_FOR"]&.split(",")&.last&.strip # Heroku
end
end
Sentry::Event.prepend(ClientIP)
The SDK still decides when an event gets an address, and keeps one set with Sentry.set_user (#2350). But the method is private: a rename quietly brings back the header-based address, and a new argument makes every event from a web request fail to build, so capture_event drops it. The public alternatives fall short. A global event processor has to repeat the SDK's rules for each version, and in 5.x it also receives LogEvents, which have no request. Sentry.set_user(ip_address: ...) is replaced by any later set_user call in the app.
Solution Brainstorm
A supported way for the app to supply the address, called where calculate_real_ip_from_rack is today, so the SDK's checks stay as they are. For example, a callable:
Sentry.init do |config|
config.send_default_pii = true
# Called with the Rack env when the SDK adds the user's IP address
config.real_ip = ->(env) { env["HTTP_X_FORWARDED_FOR"]&.split(",")&.last&.strip }
end
That would also cover #2592: an app whose clients are on a private network could return their address without changing how trusted_proxies and LOCAL_ADDRESSES work for everyone else. A narrower option that picks the headers RealIp reads would fix the precedence, but not #2592.
We checked sentry-ruby 5.25, 5.28, 6.7 and 7.2, which all work out the address this way.
- Dominant language
- Ruby
- Stars
- 990
- Forks
- 552
- Avg merge
- 2d 16h
- Merged PRs (30d)
- 29
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from getsentry/sentry-ruby
-
Bug Ruby
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
getsentry/sentry-ruby#3211 · 1 comment ·
Maintainers usually reply within 2 days
-
Events dropped client-side for size are only logged at debug level and not recorded as lostPossibly taken @sentry-junior claimed this today. OpenBug Junior: repro Ruby
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
getsentry/sentry-ruby#3209 · 2 comments · 1 reaction ·
Maintainers usually reply within 2 days
-
with_child_span drops spans when blocks exit via break, return, or throwPossibly taken @itsrayeedscodespace claimed this 1 day ago. OpenBug Ruby Traces Waiting for: Product Owner
Difficulty 2/5 1-3 hours Newbie friendliness 38/100
getsentry/sentry-ruby#3206 · 1 comment ·
Maintainers usually reply within 2 days
-
breaking change Next Major
Difficulty 2/5 1-3 hours Newbie friendliness 58/100
getsentry/sentry-ruby#3176 · 1 comment ·
Maintainers usually reply within 2 days
-
With `register_error_subscriber`, view errors are reported twice: the wrapper by the middleware, and its cause by the error subscriberPossibly taken @sl0thentr0py claimed this 13 days ago. OpenBug Ruby
Difficulty 4/5 1-2 days Newbie friendliness 57/100
getsentry/sentry-ruby#3166 · 1 comment · 1 assignee ·
Maintainers usually reply within 2 days
All issues in getsentry/sentry-ruby
Similar issues
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
internetee/registry#2984 ·
Maintainers usually reply within 6 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
ecosyste-ms/issues#862 ·
Maintainers usually reply within 1 day
-
Redis Lua error `@user_script:52: ERR value is not an integer or out of range` when `window_size` is configuredPossibly taken @mimosa claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
riscv/riscv-unified-db#2829 ·
Maintainers usually reply within 1 day
-
⛓️ Security Difficulty: Easy Good First Issue Help Wanted ruby Type: Bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
rubyforgood/casa#7404 ·
Maintainers usually reply within 1 day