[ponse] Path traversal in ponse module allows to read any file on server
The ponse module's static file handler passed a user-supplied path into file resolution without guarding against directory traversal. An attacker could request paths that climb out of the served directory and read arbitrary files on the server, such as the system password file.
- Triaged in 22 hours
- Fixed in 24 hours
- Disclosed after 43 hours
I would like to report path traversal in ponse. It allows reading local files on the target server.
Module
module name: ponse
version: 2.0.1
npm page: https://www.npmjs.com/package/ponse
Module Description
Module for work with requests and responses
Module Stats
[317] downloads in the last week [1633] downloads in the last month
Vulnerability
Vulnerability Description
Path traversal vulnerability in ponse module allows to go up in directory tree and read content of any file, like /etc/passwd.
Vulnerability exists in the getStatic function, because ponse uses user submitted variable without any protection against path traversal attacks.
Steps To Reproduce:
- install module
npm i --save ponse
- create index.js. for example:
var ponse = require('ponse')
var http = require('http')
http.createServer(
ponse.static(__dirname)
).listen(8080)
- start server
node index.js
- use curl to acces any file on the target server outside the given directory(__dirname). For example:
$ curl --path-as-is localhost:1337/../../../../../../../etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/usr/bin/nologin
daemon:x:2:2:daemon:/:/usr/bin/nologin
...
Supporting Material/References:
- linux 4.17.5-1-ARCH
- v10.6.0
- 6.2.0
- curl 7.61.0
Wrap up
- I contacted the maintainer to let them know: [N]
- I opened an issue in the related repository: [N]
Impact
Malicious user can read any file on the target server.
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 getStatic function used the user-submitted path without normalising or confining it to the served directory, so '..' segments escaped the base folder.
Impact
A malicious user could read any file on the target server that the process can access.
What the attacker needed
Server uses ponse.static to serve files; attacker can send HTTP requests to it
How it was found
- Install the ponse module.
- Create a small server script that serves the current directory with ponse.static.
- Start the server with node.
- Send a request whose path climbs out of the served directory with curl, using --path-as-is so the path is not normalised.
- Observe the contents of a system file returned in the response.
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 server that serves files from a folder should only hand out files inside that folder. Here, the module took the path from the request and used it directly, so a request containing '..' segments (which mean 'go up one folder') could step outside the intended folder. That let anyone read files elsewhere on the machine, including sensitive system files.
What is Path traversal?
Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.