2020-06-30 12:50:28 +02:00
|
|
|
include::../description.adoc[]
|
|
|
|
|
|
|
|
include::../ask-yourself.adoc[]
|
|
|
|
|
|
|
|
include::../recommended.adoc[]
|
|
|
|
|
|
|
|
== Sensitive Code Example
|
|
|
|
|
2020-12-21 15:38:52 +01:00
|
|
|
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 14:49:38 +02:00
|
|
|
|
2020-06-30 12:50:28 +02:00
|
|
|
----
|
|
|
|
const express = require('express');
|
2020-12-21 15:38:52 +01:00
|
|
|
const helmet = require('helmet');
|
2020-06-30 12:50:28 +02:00
|
|
|
|
2020-12-21 15:38:52 +01:00
|
|
|
let app = express();
|
2020-06-30 12:50:28 +02:00
|
|
|
|
2020-12-21 15:38:52 +01:00
|
|
|
app.use(
|
|
|
|
helmet({
|
|
|
|
noSniff: false, // Sensitive
|
|
|
|
})
|
|
|
|
);
|
2020-06-30 12:50:28 +02:00
|
|
|
----
|
|
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
|
2020-12-21 15:38:52 +01:00
|
|
|
When using `+helmet+` in an Express.js application, the `+noSniff+` middleware should be enabled (it is also done by default):
|
2020-06-30 14:49:38 +02:00
|
|
|
|
2020-06-30 12:50:28 +02:00
|
|
|
----
|
|
|
|
const express = require('express');
|
2020-12-21 15:38:52 +01:00
|
|
|
const helmet= require('helmet');
|
2020-06-30 12:50:28 +02:00
|
|
|
|
2020-12-21 15:38:52 +01:00
|
|
|
let app = express();
|
2020-06-30 12:50:28 +02:00
|
|
|
|
2020-12-21 15:38:52 +01:00
|
|
|
app.use(helmet.noSniff());
|
2020-06-30 12:50:28 +02:00
|
|
|
----
|
|
|
|
|
|
|
|
include::../see.adoc[]
|