Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unhandled URI::InvalidURIError in Cleaner#clean_url #811

Merged
merged 2 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

## v6.26.2 (17 January 2024)

### Fixes

* Fix unhandled `URI::InvalidURIError` in `Cleaner#clean_url`
| [#811](https://github.com/bugsnag/bugsnag-ruby/pull/811)

## v6.26.1 (9 January 2024)

### Fixes
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.26.1
6.26.2
10 changes: 9 additions & 1 deletion lib/bugsnag/cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,16 @@ def clean_object(object)
# @return [String]
def clean_url(url)
return url if @configuration.meta_data_filters.empty? && @configuration.redacted_keys.empty?
return url unless url.include?('?')

begin
uri = URI(url)
rescue URI::InvalidURIError
pre_query_string, _query_string = url.split('?', 2)

return "#{pre_query_string}?#{FILTERED}"
end

uri = URI(url)
return url unless uri.query

query_params = uri.query.split('&').map { |pair| pair.split('=') }
Expand Down
12 changes: 12 additions & 0 deletions spec/cleaner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -540,5 +540,17 @@ def to_s
let(:url) { "https://host.example/sessions?access_token=abc123" }
it { should eq "https://host.example/sessions?access_token=[FILTERED]" }
end

context "with an invalid URL" do
let(:filters) { [/token/] }
let(:url) { "https://host.example/a b c d e f g?access_token=abc123&password=secret&token2=xyz987" }
it { should eq "https://host.example/a b c d e f g?[FILTERED]" }
end

context "with an invalid URL and no query string" do
let(:filters) { [/token/] }
let(:url) { "https://host.example/a b c d e f g" }
it { should eq "https://host.example/a b c d e f g" }
end
end
end
Loading