In Rails, controller actions and views can dynamically determine which view or partial to render by calling the “render” method. If user input is used in or for the template name, an attacker could cause the application to render an arbitrary view, such as an administrative page.
Care should be taken when using user input to determine which view to render. If possible, avoid any user input in the name or path to the view.
OWASP 是說,如果你的樣板路徑是動態產生的,而且使用者可以控制那個樣板路徑,那麼使用者就可以讀取到任意樣板,包含管理介面的樣板。這樣的描述感覺還好,但就我們的發現,這其實是更嚴重的直接存取物件問題(Insecure Direct Object References),甚至有機會造成遠端命令執行(Remote Code Execution),怎麼說呢?我們直接看下去。
# lib/action_view/template/resolver.rbdefextract_handler_and_format_and_variant(path,default_formats)pieces=File.basename(path).split(".")pieces.shiftextension=pieces.popunlessextensionmessage="The file #{path} did not specify a template handler. The default is currently ERB, "\"but will change to RAW in the future."ActiveSupport::Deprecation.warnmessagehandler=Template.handler_for_extension(extension)format,variant=pieces.last.split(EXTENSIONS[:variants],2)ifpieces.lastformat&&=Template::Types[format][handler,format,variant]