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
path: root/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-08-19 23:49:26 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-08-19 23:49:26 +0300
commitc46a626682d64102671f6cc07049fd271e370320 (patch)
tree96983b7d7085ea74626ebcbdbe4671f735d34120 /lib
parente78903b70c4fdfbd3bfba189fd90af18d2c861e1 (diff)
Add latest changes from gitlab-org/security/gitlab@15-3-stable-ee
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/cache/import/caching.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/gitlab/cache/import/caching.rb b/lib/gitlab/cache/import/caching.rb
index 4dbce0b05e1..4e7a7f326a5 100644
--- a/lib/gitlab/cache/import/caching.rb
+++ b/lib/gitlab/cache/import/caching.rb
@@ -65,6 +65,8 @@ module Gitlab
# value - The value to set.
# timeout - The time after which the cache key should expire.
def self.write(raw_key, value, timeout: TIMEOUT)
+ validate_redis_value!(value)
+
key = cache_key_for(raw_key)
Redis::Cache.with do |redis|
@@ -99,6 +101,8 @@ module Gitlab
# timeout - The time after which the cache key should expire.
# @return - the incremented value
def self.increment_by(raw_key, value, timeout: TIMEOUT)
+ validate_redis_value!(value)
+
key = cache_key_for(raw_key)
Redis::Cache.with do |redis|
@@ -113,6 +117,8 @@ module Gitlab
# value - The value to add to the set.
# timeout - The new timeout of the key.
def self.set_add(raw_key, value, timeout: TIMEOUT)
+ validate_redis_value!(value)
+
key = cache_key_for(raw_key)
Redis::Cache.with do |redis|
@@ -128,6 +134,8 @@ module Gitlab
# raw_key - The key of the set to check.
# value - The value to check for.
def self.set_includes?(raw_key, value)
+ validate_redis_value!(value)
+
key = cache_key_for(raw_key)
Redis::Cache.with do |redis|
@@ -157,6 +165,8 @@ module Gitlab
mapping.each do |raw_key, value|
key = cache_key_for("#{key_prefix}#{raw_key}")
+ validate_redis_value!(value)
+
multi.set(key, value, ex: timeout)
end
end
@@ -186,6 +196,8 @@ module Gitlab
#
# Returns true when the key was overwritten, false otherwise.
def self.write_if_greater(raw_key, value, timeout: TIMEOUT)
+ validate_redis_value!(value)
+
key = cache_key_for(raw_key)
val = Redis::Cache.with do |redis|
redis
@@ -202,6 +214,8 @@ module Gitlab
# value - The field value to add to the hash.
# timeout - The new timeout of the key.
def self.hash_add(raw_key, field, value, timeout: TIMEOUT)
+ validate_redis_value!(value)
+
key = cache_key_for(raw_key)
Redis::Cache.with do |redis|
@@ -226,6 +240,13 @@ module Gitlab
def self.cache_key_for(raw_key)
"#{Redis::Cache::CACHE_NAMESPACE}:#{raw_key}"
end
+
+ def self.validate_redis_value!(value)
+ value_as_string = value.to_s
+ return if value_as_string.is_a?(String)
+
+ raise "Value '#{value_as_string}' of type '#{value_as_string.class}' for '#{value.inspect}' is not a String"
+ end
end
end
end