Skip to content

Commit

Permalink
Don't overwrite ip_address if already set on user
Browse files Browse the repository at this point in the history
  • Loading branch information
sl0thentr0py committed Jul 22, 2024
1 parent 36866c5 commit 88f073e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
### Bug Fixes

- Drop `Gem::Specification`'s usage so it doesn't break bundler standalone ([#2335](https://github.com/getsentry/sentry-ruby/pull/2335))
- Don't overwrite `ip_address` if already set on `user` [#2301](https://github.com/getsentry/sentry-ruby/pull/2301)
- Fixes [#2347](https://github.com/getsentry/sentry-ruby/issues/2347)

## 5.18.0

Expand Down
4 changes: 1 addition & 3 deletions sentry-ruby/lib/sentry/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ def rack_env=(env)
unless request || env.empty?
add_request_interface(env)

if @send_default_pii
user[:ip_address] = calculate_real_ip_from_rack(env)
end
user[:ip_address] ||= calculate_real_ip_from_rack(env) if @send_default_pii

if request_id = Utils::RequestId.read_from(env)
tags[:request_id] = request_id
Expand Down
6 changes: 6 additions & 0 deletions sentry-ruby/spec/sentry/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@
expect(event.to_hash[:user][:ip_address]).to eq("2.2.2.2")
end

it "doesn't overwrite already set ip address" do
Sentry.set_user({ ip_address: "3.3.3.3" })
Sentry.get_current_scope.apply_to_event(event)
expect(event.to_hash[:user][:ip_address]).to eq("3.3.3.3")
end

context "with config.trusted_proxies = [\"2.2.2.2\"]" do
before do
Sentry.configuration.trusted_proxies = ["2.2.2.2"]
Expand Down

0 comments on commit 88f073e

Please sign in to comment.