Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions routes/productLeaflet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) 2014-2024 Bjoern Kimminich & the OWASP Juice Shop contributors.
* SPDX-License-Identifier: MIT
*/

import { type Request, type Response, type NextFunction } from 'express'
import path from 'path'
import fs from 'fs'

// Serves the packaging leaflet that ships with each product.
module.exports = function productLeaflet () {
return (req: Request, res: Response, next: NextFunction) => {
const leaflet = req.query.leaflet ?? 'default.md'
fs.readFile(path.join('ftp/leaflets', String(leaflet)), 'utf8', (error, text) => {

@zeropath-ai-staging zeropath-ai-staging Bot Sep 9, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Path Traversal in /rest/products/leaflet (routes/productLeaflet.ts) (Severity: HIGH)

An unauthenticated request to /rest/products/leaflet can read arbitrary files. This occurs because leaflet is concatenated directly to a path under ftp/leaflets via path.join and fs.readFile, which allows traversal like ../../package.json, potentially exposing secrets. The route in server.ts:572 is mounted without auth, and routes/productLeaflet.ts:13-14 uses the attacker-controlled parameter to form the filesystem path, resulting in unintended file access.
View details in ZeroPath

Suggested change
fs.readFile(path.join('ftp/leaflets', String(leaflet)), 'utf8', (error, text) => {
fs.readFile(path.join('ftp/leaflets', path.basename(String(leaflet))), 'utf8', (error, text) => {

💬 Reply @ZeroPath false-positive because … or @ZeroPath accepted-risk because … to triage this finding, or ask it any question.

All commands

@zeropath-ai-staging zeropath-ai-staging Bot Sep 9, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Path Traversal in /rest/products/leaflet (routes/productLeaflet.ts) (Severity: HIGH)

Path traversal vulnerability: an unauthenticated request to /rest/products/leaflet with a attacker-controlled leaflet parameter leads to arbitrary file reads. The code uses req.query.leaflet directly and feeds it into path.join('ftp/leaflets', leaflet) which causes the server to escape the intended directory and read arbitrary files, resulting in exposure of source, configs, secrets, or other sensitive content.
View details in ZeroPath

Suggested change
fs.readFile(path.join('ftp/leaflets', String(leaflet)), 'utf8', (error, text) => {
fs.readFile(path.join('ftp/leaflets', path.basename(String(leaflet))), 'utf8', (error, text) => {

💬 Reply @ZeroPath false-positive because … or @ZeroPath accepted-risk because … to triage this finding, or ask it any question.

All commands

if (error != null) {
next(error)
return
}
res.type('text/plain').send(text)
})
}
}
2 changes: 2 additions & 0 deletions server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ const resetPassword = require('./routes/resetPassword')
const securityQuestion = require('./routes/securityQuestion')
const search = require('./routes/search')
const coupon = require('./routes/coupon')
const productLeaflet = require('./routes/productLeaflet')
const basket = require('./routes/basket')
const order = require('./routes/order')
const verify = require('./routes/verify')
Expand Down Expand Up @@ -568,6 +569,7 @@ restoreOverwrittenFilesWithOriginals().then(() => {
app.get('/rest/user/whoami', security.updateAuthenticatedUsers(), currentUser())
app.get('/rest/user/authentication-details', authenticatedUsers())
app.get('/rest/products/search', search())
app.get('/rest/products/leaflet', productLeaflet())
app.get('/rest/basket/:id', basket())
app.post('/rest/basket/:id/checkout', order())
app.put('/rest/basket/:id/coupon/:coupon', coupon())
Expand Down