未验证 提交 4c46a15e 编写于 作者: M Matthew Draper 提交者: Aaron Patterson

Restrict which local names can be eval'd

[CVE-2020-8163]
上级 e06a1e09
......@@ -312,8 +312,12 @@ def handle_render_error(view, e) #:nodoc:
end
def locals_code #:nodoc:
# Only locals with valid variable names get set directly. Others will
# still be available in local_assigns.
locals = @locals.to_set - Module::DELEGATION_RESERVED_METHOD_NAMES
locals = locals.grep(/\A(?![A-Z0-9])(?:[[:alnum:]_]|[^\0-\177])+\z/)
# Double assign to suppress the dreaded 'assigned but unused variable' warning
@locals.each_with_object('') { |key, code| code << "#{key} = #{key} = local_assigns[:#{key}];" }
locals.each_with_object('') { |key, code| code << "#{key} = #{key} = local_assigns[:#{key}];" }
end
def method_name #:nodoc:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册