-
Notifications
You must be signed in to change notification settings - Fork 0
feat(routes): add product datasheet renderer (rerun) #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /* | ||
| * 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 { exec } from 'child_process' | ||
|
|
||
| // Renders a product datasheet to PDF for the storefront download button. | ||
| module.exports = function datasheetRender () { | ||
| return (req: Request, res: Response, next: NextFunction) => { | ||
| const sku = req.query.sku ?? '' | ||
| exec(`/usr/bin/wkhtmltopdf ftp/datasheets/${sku}.html /tmp/${sku}.pdf`, (error, stdout) => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OS Command Injection in datasheetRender.ts (sku param) (Severity: CRITICAL) An attacker can inject arbitrary shell commands via the sku query parameter which is interpolated into a shell invocation, leading to remote code execution with the Node.js process user. This happens in routes/datasheetRender.ts where req.query.sku is interpolated into /usr/bin/wkhtmltopdf ... and executed, with the public route registered in server.ts:572 and no authentication. Suggested fixUnable to apply as inline suggestion. Download .diff and apply from repo root with diff --git a/routes/datasheetRender.ts b/routes/datasheetRender.ts
--- a/routes/datasheetRender.ts
+++ b/routes/datasheetRender.ts
@@ -4,13 +4,13 @@
*/
import { type Request, type Response, type NextFunction } from 'express'
-import { exec } from 'child_process'
+import { execFile } from 'child_process'
// Renders a product datasheet to PDF for the storefront download button.
module.exports = function datasheetRender () {
return (req: Request, res: Response, next: NextFunction) => {
- const sku = req.query.sku ?? ''
- exec(`/usr/bin/wkhtmltopdf ftp/datasheets/${sku}.html /tmp/${sku}.pdf`, (error, stdout) => {
+ const sku = typeof req.query.sku === 'string' && /^[\w-]+$/.test(req.query.sku) ? req.query.sku : ''
+ execFile('/usr/bin/wkhtmltopdf', [`ftp/datasheets/${sku}.html`, `/tmp/${sku}.pdf`], (error, stdout) => {
if (error != null) {
next(error)
return
💬 Reply |
||
| if (error != null) { | ||
| next(error) | ||
| return | ||
| } | ||
| res.type('text/plain').send(stdout) | ||
| }) | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OS Command Injection in datasheetRender route (Severity: CRITICAL)
The datasheet endpoint is vulnerable to OS command injection by interpolating the attacker-supplied sku query parameter into a shell command, which causes arbitrary commands to run as the Node.js process and can overwrite arbitrary /tmp files. This occurs in routes/datasheetRender.ts where req.query.sku is interpolated into exec(
/usr/bin/wkhtmltopdf ftp/datasheets/${sku}.html /tmp/${sku}.pdf). Evidence shows unauthenticated access via server.ts:572 that mounts this function without validation, enabling inputs like sku=x.html;touch /tmp/pwned;# to execute commands.View details in ZeroPath
Suggested fix
Unable to apply as inline suggestion. Download .diff and apply from repo root with
git apply 13d2f2b1.diff💬 Reply
@ZeroPath false-positive because …or@ZeroPath accepted-risk because …to triage this finding, or ask it any question.All commands