What is Cross-Site Scripting (XSS) in Node.js applications?
XSS is a security flaw where attackers inject malicious scripts into web pages viewed by other users. In Node.js apps, this often happens when user input is not properly sanitized before rendering in the browser.
Click to reveal answer
beginner
How can SQL Injection affect a Node.js app?
SQL Injection happens when untrusted user input is directly used in database queries. Attackers can manipulate queries to access or change data they shouldn't. Using parameterized queries or ORM libraries helps prevent this.
Click to reveal answer
beginner
What is the risk of using outdated npm packages in Node.js?
Outdated packages may have known security flaws. Attackers can exploit these to harm your app or steal data. Regularly updating packages and checking for vulnerabilities keeps your app safer.
Click to reveal answer
intermediate
Explain the concept of 'Insecure Deserialization' in Node.js.
Insecure deserialization occurs when untrusted data is converted back into objects without proper checks. Attackers can craft data to execute harmful code or change app behavior. Always validate and sanitize data before deserializing.
Click to reveal answer
beginner
Why is improper error handling a security concern in Node.js?
If error messages reveal too much info (like stack traces or database details), attackers can learn about your app's internals and find weaknesses. Use generic error messages for users and log detailed errors securely.
Click to reveal answer
Which practice helps prevent SQL Injection in Node.js?
AUsing parameterized queries
BIgnoring user input
CStoring passwords in plain text
DDisabling HTTPS
✗ Incorrect
Parameterized queries separate code from data, stopping attackers from injecting malicious SQL.
What does XSS allow an attacker to do?
ACrash the Node.js server
BAccess server file system directly
CInject malicious scripts into web pages
DBypass user login without credentials
✗ Incorrect
XSS lets attackers run harmful scripts in users' browsers by injecting code into web pages.
Why should you keep npm packages updated?
ATo fix known security vulnerabilities
BTo get new features only
CTo increase app size
DTo slow down the app
✗ Incorrect
Updating packages patches security holes that attackers might exploit.
What is a sign of improper error handling in Node.js apps?
ADisplaying generic error messages
BShowing detailed stack traces to users
CUsing try-catch blocks
DLogging errors securely
✗ Incorrect
Detailed errors shown to users can reveal sensitive info useful to attackers.
Insecure deserialization can lead to:
ABetter user experience
BFaster app performance
CAutomatic updates
DExecution of malicious code
✗ Incorrect
Attackers can craft data that runs harmful code when deserialized without checks.
Describe three common security vulnerabilities in Node.js and how to prevent them.
Think about how attackers exploit user input and dependencies.
You got /3 concepts.
Explain why proper error handling is important for Node.js security.
Consider what attackers can learn from error details.
You got /3 concepts.
Practice
(1/5)
1. Which of the following is a common security vulnerability in Node.js applications?
easy
A. Memory Leak
B. SQL Injection
C. Slow Network
D. Syntax Error
Solution
Step 1: Understand common vulnerabilities
SQL Injection is a well-known security risk where attackers inject malicious SQL code.
Step 2: Identify relevant options
Memory leaks and slow networks are performance issues, syntax errors are coding mistakes, not security vulnerabilities.
Final Answer:
SQL Injection -> Option B
Quick Check:
Common Node.js security risk = SQL Injection [OK]
Hint: Security risks often involve data injection or unauthorized access [OK]
Common Mistakes:
Confusing performance issues with security vulnerabilities
Thinking syntax errors are security problems
Ignoring injection attacks
2. Which syntax correctly prevents Cross-Site Scripting (XSS) in a Node.js Express app when rendering user input in a template?
easy
A. res.send(`
${escape(userInput)}
`);
B. res.render('page', { data: userInput });
C. res.send(`
${userInput}
`);
D. res.send(userInput);
Solution
Step 1: Identify safe rendering method
Escaping user input before inserting into HTML prevents XSS attacks.
Step 2: Compare options
Only res.send(`
${escape(userInput)}`); uses an escape function to sanitize input before sending.
Final Answer:
res.send(`
${escape(userInput)}
`); -> Option A
Quick Check:
Escape user input to prevent XSS = res.send(`
${escape(userInput)}
`); [OK]
Hint: Always escape user input before rendering in HTML [OK]
Common Mistakes:
Sending raw user input directly in HTML
Assuming template rendering auto-escapes input
Not using escape functions
3. What will be the output of this Node.js code snippet vulnerable to prototype pollution?