class Rack::Protection::EscapedParams
- Available: :html (default), :javascript, :url
escape - What escaping modes to use, should be Symbol or Array of Symbols.
Options:
strings if defined, to avoid double-escaping in Rails.
or JavaScript without any further issues. Callshtml_safeon the escaped
Automatically escapes Rack::Request#params so they can be embedded in HTML
More infos - en.wikipedia.org/wiki/Cross-site_scripting<br>Supported browsers
- all
Prevented attack -
XSS
#
- all
- What escaping modes to use, should be Symbol or Array of Symbols.
def call(env)
def call(env) request = Request.new(env) get_was = handle(request.GET) post_was = handle(request.POST) rescue nil app.call env ensure request.GET.replace get_was request.POST.replace post_was if post_was end
def escape(object)
def escape(object) case object when Hash then escape_hash(object) when Array then object.map { |o| escape(o) } when String then escape_string(object) else raise ArgumentError, "cannot escape #{object.inspect}" end end
def escape_hash(hash)
def escape_hash(hash) hash = hash.dup hash.each { |k,v| hash[k] = escape(v) } hash end
def handle(hash)
def handle(hash) was = hash.dup hash.replace escape(hash) was end
def initialize(*)
def initialize(*) super modes = Array options[:escape] code = "def self.escape_string(str) %s end" modes.each { |m| code %= "EscapeUtils.escape_#{m}(%s)"} eval code % 'str' end