Code RoomPing command injection
HardPrep Room Coding #2172

Ping command injection

Code reviewSecuritySenior–Staff~22 min

Review this Node.js endpoint that pings a host for a diagnostics tool.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.

0:00 of about 22 min
Mark a line and say what kind of problem it is.0 findings
1const { exec } = require('child_process');
2const express = require('express');
3const app = express();
4 
5app.get('/diag/ping', (req, res) => {
6 const host = req.query.host;
7 exec(`ping -c 4 ${host}`, (err, stdout, stderr) => {
8 if (err) {
9 return res.status(500).send(stderr);
10 }
11 res.type('text/plain').send(stdout);
12 });
13});
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.