Comments (5)
Make a new directory, npm install express helmet body
, run this app, and visit http://localhost:1337 (or whatever port it runs on).
var express = require('express');
var helmet = require('helmet');
var body = require('body/json');
var app = express();
var port = process.env.PORT || 1337;
app.use(helmet.csp({
'default-src': ["'self'"],
'report-uri': ['http://localhost:' + port + '/csp_report']
}));
app.get('/', function(req, res) {
res.send(
'<!DOCTYPE html>' +
'<script src="https://code.jquery.com/jquery-2.1.1.js"></script>' +
'This page should trigger a CSP error.'
);
});
app.post('/csp_report', function(req, res) {
body(req, res, {}, function(err, body) {
if (err) {
res.send(500);
throw err;
}
console.log(body);
res.send(body);
});
});
app.listen(port, function() {
console.log('App listening on ' + port);
});
This works for me in Firefox 29 and Chrome 35 for OS X 10.9. The reports are slightly different, but they both work.
What happens for you?
from helmet.
You're trying to load jQuery from code.jquery.com, but that's not in your CSP. Odd that this works in Firefox, though...
from helmet.
I know I'm loading jquery. And I know it's not in my CSP. But what i'm testing is the CSP reporting which should throw an error to the back end saying that jquery is not a valid source. So the CSP should return to me this. which is correct for Firefox, but Chrome gives me an empty array.
{ 'csp-report':
{ 'document-uri': 'http://localhost:3000/',
referrer: '',
'blocked-uri': 'https://code.jquery.com/jquery-2.1.1.js',
'violated-directive': 'script-src http://localhost:3000 http://localhost:35729 unsafe-inline' }
},
from helmet.
Thanks, this snippet actually does work. I guess I'm going to have to see what other configurations in my code is messing this up.
from helmet.
Okay. Good luck!
from helmet.
Related Issues (20)
- helmet + sanitizeFilter HOT 1
- Require Node 18+ HOT 5
- Support `unsafe-none` in `helmet.crossOriginEmbedderPolicy`? HOT 1
- Typescript required versions HOT 2
- 7.1.0 Rollup error HOT 17
- Disable HSTS headers by default on localhost HOT 9
- Error "script-src-elem" is an invalid directive HOT 3
- 'self' and 'none' values lack quotes HOT 4
- swagger HOT 2
- Getting Name of Blocked Script? HOT 3
- Increase default Strict-Transport-Security maxAge to 1 year HOT 3
- remove block-all-mixed-content from helmet-csp default directives HOT 6
- helmet default directives doesnt match helmet-csp default directives HOT 3
- Strict-Transport-Security middleware should throw, not warn, when misspelling "includeSubDomains" option HOT 2
- Content-Security-Policy `getDefaultDirectives` should return a deep copy HOT 3
- csp header lack `script-src-elem` HOT 4
- [feature request] "simple allow everything" setting for development work? HOT 6
- Question: XSS HOT 3
- Request to add `Permissions-Policy` header HOT 2
- error is always undefined HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from helmet.