From c46a626682d64102671f6cc07049fd271e370320 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Fri, 19 Aug 2022 20:49:26 +0000 Subject: Add latest changes from gitlab-org/security/gitlab@15-3-stable-ee --- lib/gitlab/cache/import/caching.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'lib') 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 -- cgit v1.2.3