Skip to content

Commit

Permalink
Make cache_id unpredictable. Closes #2326
Browse files Browse the repository at this point in the history
A random number up to 10^(15+4) is almost equivalent to 64 bits of entropy,
it should be enough for preventing easy-guessing.
Refs. 818ad98
  • Loading branch information
mshibuya committed Jun 23, 2019
1 parent 629afec commit fc65d16
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/carrierwave/uploader/cache.rb
Expand Up @@ -25,9 +25,9 @@ def self.increment
#
def self.generate_cache_id
[Time.now.utc.to_i,
Process.pid,
'%04d' % (CarrierWave::CacheCounter.increment % 10000),
'%04d' % SecureRandom.random_number(10000)
SecureRandom.random_number(1_000_000_000_000_000),
'%04d' % (CarrierWave::CacheCounter.increment % 10_000),
'%04d' % SecureRandom.random_number(10_000)
].map(&:to_s).join('-')
end

Expand Down

0 comments on commit fc65d16

Please sign in to comment.