Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-02-01 12:00:48 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-02-01 12:01:16 +0300
commit33844e18d2b83dec384549802e4efb20ae964223 (patch)
tree6b636d65641155f4541863a29b3bc8b236988712
parent41b1c0469dba622a1c2c67c17f1f5e491573accf (diff)
Add latest changes from gitlab-org/security/gitlab@13-8-stable-ee
-rw-r--r--changelogs/unreleased/security-filter-graphql-logs.yml5
-rw-r--r--lib/gitlab/graphql/query_analyzers/logger_analyzer.rb14
-rw-r--r--spec/lib/gitlab/graphql/query_analyzers/logger_analyzer_spec.rb18
3 files changed, 34 insertions, 3 deletions
diff --git a/changelogs/unreleased/security-filter-graphql-logs.yml b/changelogs/unreleased/security-filter-graphql-logs.yml
new file mode 100644
index 00000000000..2c70c480289
--- /dev/null
+++ b/changelogs/unreleased/security-filter-graphql-logs.yml
@@ -0,0 +1,5 @@
+---
+title: Filter sensitive GraphQL variables from logs
+merge_request:
+author:
+type: security
diff --git a/lib/gitlab/graphql/query_analyzers/logger_analyzer.rb b/lib/gitlab/graphql/query_analyzers/logger_analyzer.rb
index 1285365376f..0665ea8b6c9 100644
--- a/lib/gitlab/graphql/query_analyzers/logger_analyzer.rb
+++ b/lib/gitlab/graphql/query_analyzers/logger_analyzer.rb
@@ -49,13 +49,21 @@ module Gitlab
private
def process_variables(variables)
- if variables.respond_to?(:to_s)
- variables.to_s
+ filtered_variables = filter_sensitive_variables(variables)
+
+ if filtered_variables.respond_to?(:to_s)
+ filtered_variables.to_s
else
- variables
+ filtered_variables
end
end
+ def filter_sensitive_variables(variables)
+ ActiveSupport::ParameterFilter
+ .new(::Rails.application.config.filter_parameters)
+ .filter(variables)
+ end
+
def duration(time_started)
Gitlab::Metrics::System.monotonic_time - time_started
end
diff --git a/spec/lib/gitlab/graphql/query_analyzers/logger_analyzer_spec.rb b/spec/lib/gitlab/graphql/query_analyzers/logger_analyzer_spec.rb
index c8432513185..138765afd8a 100644
--- a/spec/lib/gitlab/graphql/query_analyzers/logger_analyzer_spec.rb
+++ b/spec/lib/gitlab/graphql/query_analyzers/logger_analyzer_spec.rb
@@ -40,4 +40,22 @@ RSpec.describe Gitlab::Graphql::QueryAnalyzers::LoggerAnalyzer do
end
end
end
+
+ describe '#initial_value' do
+ it 'filters out sensitive variables' do
+ doc = GraphQL.parse <<-GRAPHQL
+ mutation createNote($body: String!) {
+ createNote(input: {noteableId: "1", body: $body}) {
+ note {
+ id
+ }
+ }
+ }
+ GRAPHQL
+
+ query = GraphQL::Query.new(GitlabSchema, document: doc, context: {}, variables: { body: "some note" })
+
+ expect(subject.initial_value(query)[:variables]).to eq('{:body=>"[FILTERED]"}')
+ end
+ end
end