0
0
Expressframework~20 mins

Helmet for security headers in Express - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Helmet Security Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the effect of using Helmet's default configuration in an Express app?

Consider an Express app that uses app.use(helmet()) with no options. What does this do?

Express
const express = require('express');
const helmet = require('helmet');
const app = express();
app.use(helmet());
app.get('/', (req, res) => res.send('Hello'));
app.listen(3000);
AIt sets a collection of common security headers with default safe values.
BIt automatically redirects all HTTP requests to HTTPS.
CIt only sets the Content-Security-Policy header with a strict policy.
DIt disables all HTTP headers to improve performance.
Attempts:
2 left
💡 Hint

Think about what Helmet does by default without extra options.

📝 Syntax
intermediate
2:00remaining
Which Helmet middleware usage is syntactically correct to disable the Content Security Policy?

You want to disable the Content Security Policy (CSP) middleware in Helmet. Which code snippet is correct?

Aapp.use(helmet({ contentSecurityPolicy: false }));
Bapp.use(helmet.disable('contentSecurityPolicy'));
Capp.use(helmet({ disable: ['contentSecurityPolicy'] }));
Dapp.use(helmet().contentSecurityPolicy(false));
Attempts:
2 left
💡 Hint

Check Helmet's option object syntax for disabling specific middleware.

🔧 Debug
advanced
2:00remaining
Why does this Helmet setup cause a runtime error?

Review this code snippet and identify why it throws an error when starting the server.

Express
const express = require('express');
const helmet = require('helmet');
const app = express();
app.use(helmet.contentSecurityPolicy());
app.listen(3000);
Ahelmet middleware must be used after app.listen, not before.
Bhelmet.contentSecurityPolicy requires options and cannot be called without arguments.
Chelmet.contentSecurityPolicy is not a function; it must be called from helmet() or imported separately.
Dhelmet.contentSecurityPolicy is deprecated and removed in latest versions.
Attempts:
2 left
💡 Hint

Check how Helmet middleware functions are accessed.

state_output
advanced
2:00remaining
What headers are set after this Helmet configuration?

Given this Express app code, which security header will NOT be set?

Express
const express = require('express');
const helmet = require('helmet');
const app = express();
app.use(helmet({
  frameguard: false,
  dnsPrefetchControl: false
}));
app.get('/', (req, res) => res.send('OK'));
app.listen(3000);
AStrict-Transport-Security header is NOT set.
BAll default Helmet headers are set.
CContent-Security-Policy header is NOT set.
DX-Frame-Options and X-DNS-Prefetch-Control headers are NOT set.
Attempts:
2 left
💡 Hint

Look at which middleware are disabled explicitly.

🧠 Conceptual
expert
3:00remaining
Why is it important to configure Helmet's Content Security Policy carefully in a React app?

In a React single-page app served by Express with Helmet, why must the Content Security Policy (CSP) be configured carefully?

ABecause Helmet disables React's rendering lifecycle when CSP is enabled.
BBecause a strict CSP can block inline scripts and styles React relies on, causing the app to break.
CBecause CSP automatically disables React's state management if misconfigured.
DBecause CSP only affects server-side code and has no impact on React apps.
Attempts:
2 left
💡 Hint

Think about what CSP blocks and how React uses scripts and styles.