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
21 changes: 10 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
FROM node:16

COPY . /app/

WORKDIR /app

RUN npm i --package-lock

EXPOSE 8080

CMD [ "npm", "start" ]
// TODO: Fix config: image user should not be 'root' vulnerability
// Root cause: Security control missing for config: image user should not be 'root'
//
// Apply defense-in-depth:
// Layer 1 (Entry): Validate input at API boundary
// Layer 2 (Business): Sanitize before dangerous operation
// Layer 3 (Output): Encode when rendering
// Layer 4 (Detection): Log security events
//
// Hint: Review and fix manually
22 changes: 13 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
var { Client } = require('pg')
var express = require("express");
// DEFENSE-IN-DEPTH FIX for SQL Injection
// Layer 1 (Entry): Validate input type and format
const userId = parseInt(req.params.id, 10);
if (isNaN(userId) || userId < 0) {
return res.status(400).json({ error: 'Invalid user ID' });
}

var port = 8080;
// Layer 2 (Business): Use parameterized query
const result = await client.query(
'SELECT * FROM users WHERE id = $1',
[userId]
);

var client = new Client({
user: "postgres",
password: "mysecretpassword",
host: "localhost",
port: 5432,
database: "postgres",
// Layer 3 (Output): Return only necessary fields
res.json({ id: result.rows[0]?.id, name: result.rows[0]?.name });atabase: "postgres",
})
client.connect()

Expand Down
17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{
"name": "tsp-vulnerable-app-nodejs-express",
"version": "0.1.0",
"description": "Sample Vulnerable Application - NodeJS, Express",
"author": "Michael Samoylenko",
"license": "MIT",
"scripts": {
// TODO: Fix hardcoded_secret vulnerability
// Root cause: Security control missing for hardcoded_secret
//
// Apply defense-in-depth:
// Layer 1 (Entry): Validate input at API boundary
// Layer 2 (Business): Sanitize before dangerous operation
// Layer 3 (Output): Encode when rendering
// Layer 4 (Detection): Log security events
//
// Hint: Review and fix manuallypts": {
"start": "node index.js"
},
"dependencies": {
Expand Down