0
0
Node.jsframework~20 mins

Common Node.js security vulnerabilities in Node.js - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Node.js Security Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the main risk of using unsanitized user input in Node.js?

Consider a Node.js app that directly uses user input in database queries without cleaning it. What is the main security risk?

ACross-Site Scripting (XSS) attack
BMan-in-the-Middle (MitM) attack
CSQL Injection attack
DDenial of Service (DoS) attack
Attempts:
2 left
💡 Hint

Think about attacks that manipulate database commands.

component_behavior
intermediate
2:00remaining
What happens if you use eval() on user input in Node.js?

Given a Node.js server that runs eval(userInput), what is the likely security consequence?

AIt can lead to remote code execution vulnerabilities
BIt safely executes user code without risks
CIt prevents injection attacks automatically
DIt only runs code in a sandboxed environment
Attempts:
2 left
💡 Hint

Consider what eval() does with arbitrary code strings.

📝 Syntax
advanced
2:00remaining
Which code snippet properly prevents prototype pollution in Node.js?

Prototype pollution happens when attackers modify object prototypes. Which snippet blocks this?

Aobj['__proto__'] = value; // directly assign
Bdelete obj['constructor']; obj[key] = value;
CObject.assign(obj, userInput); // blindly assign
Dif (key === '__proto__') throw new Error('Pollution attempt'); obj[key] = value;
Attempts:
2 left
💡 Hint

Check which option blocks dangerous keys before assignment.

🔧 Debug
advanced
2:00remaining
Why does this Node.js code cause a denial of service (DoS)?

Examine the code below:

const http = require('http');
http.createServer((req, res) => {
  while(true) {}
  res.end('Hello');
}).listen(3000);

What is the problem?

Node.js
const http = require('http');
http.createServer((req, res) => {
  while(true) {}
  res.end('Hello');
}).listen(3000);
AThe server leaks memory causing slowdowns
BThe infinite loop blocks the event loop causing DoS
CThe server crashes due to missing response headers
DThe server responds with wrong content type
Attempts:
2 left
💡 Hint

Think about what an infinite loop does in Node.js single-threaded model.

state_output
expert
2:00remaining
What is the output of this Express.js middleware chain with a missing next() call?

Consider this Express.js code:

const express = require('express');
const app = express();

app.use((req, res, next) => {
  console.log('First middleware');
  // missing next()
});

app.use((req, res, next) => {
  console.log('Second middleware');
  res.send('Done');
});

app.listen(3000);

What happens when a request is made?

Node.js
const express = require('express');
const app = express();

app.use((req, res, next) => {
  console.log('First middleware');
  // missing next()
});

app.use((req, res, next) => {
  console.log('Second middleware');
  res.send('Done');
});

app.listen(3000);
AOnly 'First middleware' logs; request hangs without response
B'First middleware' and 'Second middleware' both log; response sent
COnly 'Second middleware' logs; response sent immediately
DServer crashes with an error about missing next()
Attempts:
2 left
💡 Hint

Think about what happens if next() is not called in middleware.