summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorImre Farkas <ifarkas@gitlab.com>2018-05-30 12:12:42 +0200
committerImre Farkas <ifarkas@gitlab.com>2018-06-06 22:25:20 +0200
commit854c9636ec6aabd8941b31f0f2aa4e89c9c072ce (patch)
treec618473ce420ca8abe707ea1c821a6a94bfc16f5 /lib
parentd8eea0c4ba74a3bc821e1298e85f3fed77273099 (diff)
downloadgitlab-ce-854c9636ec6aabd8941b31f0f2aa4e89c9c072ce.tar.gz
Enforce UTF-8 encoding on user input in LogrageWithTimestamp formatter and filter out file content from logs
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/grape_logging/formatters/lograge_with_timestamp.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/gitlab/grape_logging/formatters/lograge_with_timestamp.rb b/lib/gitlab/grape_logging/formatters/lograge_with_timestamp.rb
index 1e1fdabca93..0014ce2689b 100644
--- a/lib/gitlab/grape_logging/formatters/lograge_with_timestamp.rb
+++ b/lib/gitlab/grape_logging/formatters/lograge_with_timestamp.rb
@@ -2,8 +2,12 @@ module Gitlab
module GrapeLogging
module Formatters
class LogrageWithTimestamp
+ include Gitlab::EncodingHelper
+
def call(severity, datetime, _, data)
time = data.delete :time
+ data[:params] = utf8_encode_values(data[:params]) if data.has_key?(:params)
+
attributes = {
time: datetime.utc.iso8601(3),
severity: severity,
@@ -13,6 +17,19 @@ module Gitlab
}.merge(data)
::Lograge.formatter.call(attributes) + "\n"
end
+
+ private
+
+ def utf8_encode_values(data)
+ case data
+ when Hash
+ data.merge(data) { |k, v| utf8_encode_values(v) }
+ when Array
+ data.map { |v| utf8_encode_values(v) }
+ when String
+ encode_utf8(data)
+ end
+ end
end
end
end