Skip to content

Commit 13040d4

Browse files
authored
Release v6.26.3
2 parents c052209 + 6480ca2 commit 13040d4

4 files changed

Lines changed: 67 additions & 16 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Changelog
22
=========
33

4+
## v6.26.3 (24 January 2024)
5+
6+
* Handle mailto links in `Cleaner#clean_url`
7+
| [#813](https://github.com/bugsnag/bugsnag-ruby/pull/813)
8+
49
## v6.26.2 (17 January 2024)
510

611
### Fixes

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6.26.2
1+
6.26.3

lib/bugsnag/cleaner.rb

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,19 @@ def clean_url(url)
3030

3131
begin
3232
uri = URI(url)
33-
rescue URI::InvalidURIError
34-
pre_query_string, _query_string = url.split('?', 2)
35-
36-
return "#{pre_query_string}?#{FILTERED}"
37-
end
3833

39-
return url unless uri.query
40-
41-
query_params = uri.query.split('&').map { |pair| pair.split('=') }
42-
query_params.map! do |key, val|
43-
if filters_match?(key)
44-
"#{key}=#{FILTERED}"
34+
if uri.is_a?(URI::MailTo)
35+
clean_mailto_url(url, uri)
4536
else
46-
"#{key}=#{val}"
37+
clean_generic_url(url, uri)
4738
end
48-
end
39+
rescue URI::InvalidURIError
40+
pre_query_string, _query_string = url.split('?', 2)
4941

50-
uri.query = query_params.join('&')
51-
uri.to_s
42+
"#{pre_query_string}?#{FILTERED}"
43+
rescue StandardError
44+
FILTERED
45+
end
5246
end
5347

5448
##
@@ -209,5 +203,33 @@ def scope_should_be_filtered?(scope)
209203
scope.start_with?("#{scope_to_filter}.")
210204
end
211205
end
206+
207+
def clean_generic_url(original_url, uri)
208+
return original_url unless uri.query
209+
210+
query_params = uri.query.split('&').map { |pair| pair.split('=') }
211+
212+
uri.query = filter_uri_parameter_array(query_params).join('&')
213+
uri.to_s
214+
end
215+
216+
def clean_mailto_url(original_url, uri)
217+
return original_url unless uri.headers
218+
219+
# headers in mailto links can't contain square brackets so we replace
220+
# filtered parameters with 'FILTERED' instead of '[FILTERED]'
221+
uri.headers = filter_uri_parameter_array(uri.headers, 'FILTERED').join('&')
222+
uri.to_s
223+
end
224+
225+
def filter_uri_parameter_array(parameters, replacement = FILTERED)
226+
parameters.map do |key, value|
227+
if filters_match?(key)
228+
"#{key}=#{replacement}"
229+
else
230+
"#{key}=#{value}"
231+
end
232+
end
233+
end
212234
end
213235
end

spec/cleaner_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,5 +552,29 @@ def to_s
552552
let(:url) { "https://host.example/a b c d e f g" }
553553
it { should eq "https://host.example/a b c d e f g" }
554554
end
555+
556+
context "with a mailto URL" do
557+
let(:filters) { [/token/] }
558+
let(:url) { "mailto:hello@example.com?token=secret&subject=Hello" }
559+
it { should eq "mailto:hello@example.com?token=FILTERED&subject=Hello" }
560+
end
561+
562+
context "with a mailto URL without a to address" do
563+
let(:filters) { [/token/] }
564+
let(:url) { "mailto:?subject=Hello&token=password" }
565+
it { should eq "mailto:?subject=Hello&token=FILTERED" }
566+
end
567+
568+
context "with a websocket URL" do
569+
let(:filters) { [/secret/] }
570+
let(:url) { "ws://example.com?abc=xyz&secret=password" }
571+
it { should eq "ws://example.com?abc=xyz&secret=[FILTERED]" }
572+
end
573+
574+
context "with a websocket over TLS URL" do
575+
let(:filters) { [/secret/] }
576+
let(:url) { "wss://example.com?abc=xyz&secret=password" }
577+
it { should eq "wss://example.com?abc=xyz&secret=[FILTERED]" }
578+
end
555579
end
556580
end

0 commit comments

Comments
 (0)