diff options
author | Imre Farkas <ifarkas@gitlab.com> | 2018-05-30 12:12:42 +0200 |
---|---|---|
committer | Imre Farkas <ifarkas@gitlab.com> | 2018-06-06 22:25:20 +0200 |
commit | 854c9636ec6aabd8941b31f0f2aa4e89c9c072ce (patch) | |
tree | c618473ce420ca8abe707ea1c821a6a94bfc16f5 /lib | |
parent | d8eea0c4ba74a3bc821e1298e85f3fed77273099 (diff) | |
download | gitlab-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.rb | 17 |
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 |