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:
Diffstat (limited to 'lib/gitlab/etag_caching/store.rb')
-rw-r--r--lib/gitlab/etag_caching/store.rb23
1 files changed, 22 insertions, 1 deletions
diff --git a/lib/gitlab/etag_caching/store.rb b/lib/gitlab/etag_caching/store.rb
index 1d2f0d7bbf4..d0d790a7c72 100644
--- a/lib/gitlab/etag_caching/store.rb
+++ b/lib/gitlab/etag_caching/store.rb
@@ -3,6 +3,8 @@
module Gitlab
module EtagCaching
class Store
+ InvalidKeyError = Class.new(StandardError)
+
EXPIRY_TIME = 20.minutes
SHARED_STATE_NAMESPACE = 'etag:'
@@ -27,9 +29,28 @@ module Gitlab
end
def redis_shared_state_key(key)
- raise 'Invalid key' if !Rails.env.production? && !Gitlab::EtagCaching::Router.match(key)
+ raise InvalidKeyError, "#{key} is invalid" unless valid_key?(key)
"#{SHARED_STATE_NAMESPACE}#{key}"
+ rescue InvalidKeyError => e
+ Gitlab::ErrorTracking.track_and_raise_for_dev_exception(e)
+ end
+
+ def valid_key?(key)
+ return true if skip_validation?
+
+ path, header = key.split(':', 2)
+ env = {
+ 'PATH_INFO' => path,
+ 'HTTP_X_GITLAB_GRAPHQL_RESOURCE_ETAG' => header
+ }
+
+ fake_request = ActionDispatch::Request.new(env)
+ !!Gitlab::EtagCaching::Router.match(fake_request)
+ end
+
+ def skip_validation?
+ Rails.env.production?
end
end
end