38 lines
743 B
Plaintext
Raw Normal View History

2020-06-30 12:50:28 +02:00
include::../description.adoc[]
include::../ask-yourself.adoc[]
include::../recommended.adoc[]
== Sensitive Code Example
In Express.js application the code is sensitive if, when using https://www.npmjs.com/package/helmet[helmet], the `+noSniff+` middleware is disabled:
2020-06-30 12:50:28 +02:00
----
const express = require('express');
const helmet = require('helmet');
2020-06-30 12:50:28 +02:00
let app = express();
2020-06-30 12:50:28 +02:00
app.use(
helmet({
noSniff: false, // Sensitive
})
);
2020-06-30 12:50:28 +02:00
----
== Compliant Solution
When using `+helmet+` in an Express.js application, the `+noSniff+` middleware should be enabled (it is also done by default):
2020-06-30 12:50:28 +02:00
----
const express = require('express');
const helmet= require('helmet');
2020-06-30 12:50:28 +02:00
let app = express();
2020-06-30 12:50:28 +02:00
app.use(helmet.noSniff());
2020-06-30 12:50:28 +02:00
----
include::../see.adoc[]