Rails Asset Pipeline Directory Traversal Vulnerability (CVE-2018-3760)
Were you affected by the recent Sprockets vulnerability? Check out this post on the Rails asset pipeline directory traversal vulnerability, or CVE-2018-3760.
Join the DZone community and get the full member experience.Join For Free
How Do I know if I’m Affected?
The Rails applications are vulnerable if they have this setting enabled in their application:
# config/environments/production.rb config.assets.compile = true # setting to true makes your app vulnerable
Note: The default value of this setting that ships with Rails in
false. By default, the Rails apps running in production mode are not vulnerable to this exploit.
How Do I Fix It?
To remediate this vulnerability, applications can either change the setting above to
false or upgrade to the latest version of Sprockets. Heroku highly recommends upgrading to the latest patch release for your version of Sprockets by running
bundle update sprockets. Make sure that the update puts your application on one of these Sprockets versions (or newer):
What Was at Risk?
If your application was targeted using this exploit and you had the
assets.compile setting enabled on your production app, it’s possible that secrets contained in your repo or your environment variables have been compromised. As a precaution, you may wish to rotate your database credentials, along with any other credentials stored in your application code or environment.
Instructions for Rotating Heroku Data Services Are Below:
For other add-on partners, please check the specific add-on documentation for instructions on how to rotate credentials.
How Does the Exploit Work?
When runtime compilation is enabled, a Sprockets' server will dynamically check to see if an asset is rendered or not when it receives a request. If Sprockets can’t find an already rendered asset, it will try to find and compile an asset that matches the request. The search process is very slow, and as such, it is not a recommended best practice for this type of asset management software.
The directory traversal vulnerability exploits this search process to fool the Sprockets server. Using a known absolute path to the directory of a source asset, an attacker can craft a URL that convinces Sprockets it is rendering an asset inside one of its permitted paths.
The Sprockets issue was reported via the Rails security bug tracker on HackerOne by Orange Tsai. It was passed to the Rails maintainers, who forwarded the issue to me, Richard Schneeman, the current Sprockets maintainer.
A patch was prepared for all three of the currently supported Sprockets versions: 2, 3, and 4. The patches were reviewed privately by the vulnerability reporter and other Rails core members. When the threat was determined to be sufficiently mitigated, a CVE was drafted, and there was a coordinated release of the CVE and the security patches.
When a severe security release that affects customers is announced, the CVE is passed to the Heroku security team and the vulnerability is given a score. Based on that score, the rest of the company determines what steps to take to best protect our customers. At the time of the CVE release, the knowledge of the security vulnerability by a Sprockets core member allowed us to quickly give it a score, and immediately begin developing a plan to communicate mitigation instructions to customers.
On June 19, we took the following actions to help ensure that customers likely to be affected were notified of the issue:
- Updated the Ruby Buildpack to fail builds for applications with runtime asset compilation enabled that are running an affected version of Sprockets.
- Contacted customers we know to be running Ruby on Rails applications that depend on Sprockets, as determined by our internal dependency tracking tool. Note that this tool may not always generate a complete list of affected applications; even if you did not receive an email, we urge you to carefully check your own dependencies to determine if you are affected.
If you cannot upgrade an affected Ruby application at this time but need to deploy, it is possible to regain deployability. This method is not recommended as it allows you to continue deploying a vulnerable application.
Published at DZone with permission of Richard Schneeman, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.