-
Notifications
You must be signed in to change notification settings - Fork 1
Add 3 critical security vulnerabilities for training purposes #11
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: develop
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 | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,5 @@ | ||||||||||||||||||||||
| const express = require('express'); | ||||||||||||||||||||||
| const { exec } = require('child_process'); | ||||||||||||||||||||||
| const auth = require('../middleware/auth'); | ||||||||||||||||||||||
| const Account = require('../models/account'); | ||||||||||||||||||||||
| const Note = require('../models/note'); | ||||||||||||||||||||||
|
|
@@ -26,6 +27,18 @@ router.post('/accounts', async (req, res, next) => { | |||||||||||||||||||||
| } | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // VULN 1: Remote Code Execution (RCE) via OS Command Injection | ||||||||||||||||||||||
| // User-supplied input is passed directly to exec() without sanitization | ||||||||||||||||||||||
| router.get('/accounts/:username/export', auth, async (req, res, next) => { | ||||||||||||||||||||||
| const format = req.query.format || 'json'; | ||||||||||||||||||||||
| exec(`echo Exporting notes for ${req.params.username} in ${format} format`, (error, stdout, stderr) => { | ||||||||||||||||||||||
| if (error) { | ||||||||||||||||||||||
| return res.status(500).json({ error: stderr }); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| res.status(200).json({ output: stdout }); | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| router.put('/accounts/:username/notes/:note', auth, async (req, res, next) => { | ||||||||||||||||||||||
| const rawNote = { | ||||||||||||||||||||||
| ...req.body, | ||||||||||||||||||||||
|
|
@@ -71,4 +84,20 @@ router.get('/accounts/:username/notes', auth, async (req, res, next) => { | |||||||||||||||||||||
| } | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // VULN 2: NoSQL Injection via unsanitized query parameters | ||||||||||||||||||||||
| // User input is passed directly into MongoDB query operators | ||||||||||||||||||||||
| router.get('/accounts/search', async (req, res, next) => { | ||||||||||||||||||||||
| try { | ||||||||||||||||||||||
| const query = req.query.email; | ||||||||||||||||||||||
| const accounts = await Account.find( | ||||||||||||||||||||||
| { email: query }, | ||||||||||||||||||||||
| { password: 1, email: 1, name: 1 } | ||||||||||||||||||||||
| ).exec(); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| res.status(200).json(accounts); | ||||||||||||||||||||||
|
Comment on lines
+93
to
+97
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. Sensitive Credential Exposure in Account Search Results (Severity: HIGH) Passwords are exposed in API responses, which can lead to unauthorized account access if intercepted. The Account.find function in accounts.js inadvertently includes the 'password' field in search results, causing sensitive credential exposure.
Suggested change
|
||||||||||||||||||||||
| } catch (e) { | ||||||||||||||||||||||
| res.status(500).json({ error: e.message }); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| module.exports = router; | ||||||||||||||||||||||
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 Account Export Endpoint (Severity: HIGH)
Remote Code Execution is possible because user-supplied input from the 'format' query parameter and 'username' path parameter is passed directly to the
execfunction without sanitization. This allows an attacker to inject arbitrary OS commands, leading to potential compromise of the server.View details in ZeroPath
Suggested fix
Unable to apply as inline suggestion. Download .diff and apply from repo root with
git apply ed00d5d9.diff