GithubHelp home page GithubHelp logo

Chrome CSP about helmet HOT 5 CLOSED

helmetjs avatar helmetjs commented on July 21, 2024
Chrome CSP

from helmet.

Comments (5)

EvanHahn avatar EvanHahn commented on July 21, 2024 1

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.

EvanHahn avatar EvanHahn commented on July 21, 2024

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.

gsitu322 avatar gsitu322 commented on July 21, 2024

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.

gsitu322 avatar gsitu322 commented on July 21, 2024

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.

EvanHahn avatar EvanHahn commented on July 21, 2024

Okay. Good luck!

from helmet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.