Byass due to validation before canonicalization in serve
Affected releases · serve
- 6.x6.0.0 – 6.5.1Fixed in 6.5.2
- 5.x and older0.0.1 – 5.2.4No fix, no longer updated
On 6.x, the newest line:
npm install serve@6.5.2Not affected
14.0.0 – 14.2.6
12 releases, latest
Affected
6.0.0 – 6.5.1
25 releases
Fixed
6.5.2 – 6.5.8
7 releases
Affected
5.0.0 – 5.2.4
16 releases
Affected
4.0.0 – 4.0.2
3 releases
Affected
3.0.0 – 3.4.1
19 releases
Affected
2.0.0 – 2.4.4
11 releases
Affected
1.0.0 – 1.4.0
8 releases
Affected
0.0.1 – 0.0.5
5 releases
Is your project affected?
Paste your package.json, or type the range you declare for serve. It is read in your browser and sent nowhere.
What happens
Versions of serve before 6.5.2 are vulnerable to the bypass of the ignore functionality. The bypass is possible because validation happens before canonicalization of paths and filenames.
Example: Here we have a server that ignores the file test.txt.
const serve = require('serve')
const server = serve(__dirname, {
port: 1337,
ignore: ['test.txt']
})Using the URL encoded form of a letter (%65 instead of e) attacker can bypass the ignore control accessing the file.
curl http://localhost:1337/t%65st.txt
Additionally this technique can be used to get directory listings of ignored directories.
Recommendation
Update to version 6.5.2 or later.