47 lines
1.2 KiB
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
2021-01-27 13:42:22 +01:00
In Express.js application the code is sensitive if the https://www.npmjs.com/package/helmet-csp[helmet-csp] or https://www.npmjs.com/package/helmet[helmet] middleware is used without the ``++blockAllMixedContent++`` directive:
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();
app.use(
helmet.contentSecurityPolicy({
directives: {
"default-src": ["'self'", 'example.com', 'code.jquery.com']
} // Sensitive: blockAllMixedContent directive is missing
})
);
2020-06-30 12:50:28 +02:00
----
== Compliant Solution
2021-01-27 13:42:22 +01:00
In Express.js application a standard way to block mixed-content is to put in place the https://www.npmjs.com/package/helmet-csp[helmet-csp] or https://www.npmjs.com/package/helmet[helmet] middleware with the ``++blockAllMixedContent++`` directive:
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();
app.use(
helmet.contentSecurityPolicy({
directives: {
"default-src": ["'self'", 'example.com', 'code.jquery.com'],
blockAllMixedContent: [] // Compliant
}
})
);
2020-06-30 12:50:28 +02:00
----
include::../see.adoc[]