Skip to content

Instantly share code, notes, and snippets.

@shaicoleman
Last active July 5, 2023 18:03
Show Gist options
  • Save shaicoleman/4505417 to your computer and use it in GitHub Desktop.
Save shaicoleman/4505417 to your computer and use it in GitHub Desktop.
Initializer for mitigating CVE-2013-0156 and CVE-2013-0333 on all versions of rails
def rails_between(min, max)
Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new(min) && Gem::Version.new(Rails::VERSION::STRING) <= Gem::Version.new(max)
end
if rails_between('3.0.0', '3.0.18') || rails_between('3.1.0', '3.1.9') || rails_between('3.2.0', '3.2.10')
ActionDispatch::ParamsParser::DEFAULT_PARSERS.delete(Mime::XML)
end
if rails_between('2.0.0', '2.3.14')
ActionController::Base.param_parsers.delete(Mime::XML)
end
if rails_between('2.3.3', '2.3.15') || rails_between('3.0.0', '3.0.19')
require 'json'
ActiveSupport::JSON.backend = "JSONGem"
end
if rails_between('2.3.0', '2.3.2')
raise 'This version of Rails is vulnerable and no longer supported'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment