Skip to content

Instantly share code, notes, and snippets.

@MahmoudAgamy
Forked from joshuap/redis.rb
Created September 22, 2019 15:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MahmoudAgamy/6fc21396f073332f85f2079ccca322de to your computer and use it in GitHub Desktop.
Save MahmoudAgamy/6fc21396f073332f85f2079ccca322de to your computer and use it in GitHub Desktop.
Disable dangerous Redis commands in Ruby
# config/initializers/redis.rb
require 'redis'
# Disables the `flushdb` and `flushall` commands.
class Redis
module DangerousCommands
def flushdb
raise 'This is EXTREMELY DANGEROUS! If you really want to EMPTY THE ENTIRE DATABASE, do it from `redis-cli`.'
# You could call `super` here if you want to allow access in some circumstances.
end
def flushall
raise 'This is EXTREMELY DANGEROUS! If you really want to FLUSH ALL DATABASES, do it from `redis-cli`.'
# You could call `super` here if you want to allow access in some circumstances.
end
end
prepend DangerousCommands
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment