diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 3356f2a7b..7252e7cb1 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -38,6 +38,10 @@ endif::[] [[release-notes-3.9.0]] ==== 3.9.0 (2020-08-04) +[float] +===== Fixed +- Scrub request body of illegal UTF-8 characters {pull}832[#832] + [float] ===== Added diff --git a/lib/elastic_apm/context_builder.rb b/lib/elastic_apm/context_builder.rb index bd0c00b7b..54efe44e3 100644 --- a/lib/elastic_apm/context_builder.rb +++ b/lib/elastic_apm/context_builder.rb @@ -76,7 +76,7 @@ def get_body(req) else body = req.body.read req.body.rewind - body.byteslice(0, MAX_BODY_LENGTH).force_encoding('utf-8') + body.byteslice(0, MAX_BODY_LENGTH).force_encoding('utf-8').scrub end end diff --git a/spec/elastic_apm/context_builder_spec.rb b/spec/elastic_apm/context_builder_spec.rb index 97de34aa9..835dcabe9 100644 --- a/spec/elastic_apm/context_builder_spec.rb +++ b/spec/elastic_apm/context_builder_spec.rb @@ -112,6 +112,7 @@ module ElasticAPM expect(result.request.body).to eq '{"something":"everything"}' expect(result.request.body.encoding).to eq Encoding::UTF_8 + expect(result.request.body.valid_encoding?).to be true end end end