Skip to content
Path traversal Disclosed report Intermediate CVE-2014-0130

Directory traversal attack in view resolver

Wildcard URL segments in Rails routes could be abused to render views from outside the configured view paths, letting an attacker read files such as the project Gemfile. The built-in path traversal protection could also be bypassed using backslashes because the resolver treats them as directory separators.

lautis Follow

Originally disclosed on HackerOne

  • Triaged in 15 hours
  • Fixed in 2 months
  • Paid in 4 months
  • Disclosed after 16 months

There seems to be two cases that allow directory traversal when using wildcard URL segments that allow rendering view outside view paths.

For example, let say there is a route

get '/help/(*action)’, controller: ‘help’

and a matching controller

class HelpController < ApplicationController
end

This renders all views that are in 'app/views/help’ (assuming default view paths) even when matching action method is not defined.

If an attacker made a request GET /help/../../../Gemfile, ActionView::FileSystemResolver returns Gemfile from project root as the matching view. This simple case can be prevented using Rack::Protection::PathTraversal middleware, but it is not enabled by default in Rails. Also, there could be other mechanisms that may result in rendering views that are outside view path. Not sure if that’s the expected behaviour, but this surprised me.

However, Rack::Protection::PathTraversal can be bypassed using backslashes: GET /help/%5c../%5c../%5c../Gemfile. The resolver uses Dir.glob, which escapes backslashes unless File::FNM_NOESCAPE flag is used. Rack::Protection::PathTraversal won’t intercept '\../' and the resolver treats '\../' as '../'.

Attached are fixes for the mentioned vulnerabilities with test cases.

The original report as published on HackerOne, by lautis. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the view resolver builds a file path from user-controlled wildcard route segments and normalises backslashes to path separators, so traversal sequences reach the filesystem lookup.

Impact

An attacker could read files outside the view directory, and the standard middleware defence could be bypassed, though that middleware is not enabled by default.

What the attacker needed

A route with a wildcard URL segment; no path traversal middleware, or backslash bypass

The fix

The reporter attached fixes with test cases, but the text does not state that they were merged or released.

How it was found

  1. Define a route with a wildcard segment pointing at a controller.
  2. Request the route with traversal sequences to reach a file outside the view path.
  3. Observe the file from the project root being rendered as the view.
  4. Repeat the request using encoded backslashes to bypass the path traversal middleware.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A web framework picks which page template to show based on the URL. Here the URL was used to build a file path without properly stopping '..' (meaning 'go up a folder'), so someone could ask for files outside the intended template folder. A second trick using backslashes slipped past the protection that was meant to block this.

What is Path traversal?

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.

More from Ruby on Rails

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Path traversal and file inclusion

The lesson behind this report.

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.