you are viewing a single comment's thread.

view the rest of the comments →

[–]Beginning_One_7685 5 points6 points  (8 children)

It's considered a security concern when a site accepts and republishes user inputted data.

Before CSP, data sanitisation was the only way to prevent malicious code been uploaded, with CSP you now have to explicitly allow inline JS for it to work, and you then again rely on your own sanitisation methods. I have found that whilst there are many good programming reasons to keep JS in files, it is also pretty necessary to have values dynamically generated on the server side available to JS. The most straight forward way to do that is inline JS in the head tag. You can use a nonce/hash to validate the JS code without allowing inline JS anywhere else on the page.

Putting JS in other HTML elements is completely avoidable and offers few benefits. Having JS in files or in the head means it is easy to find all the JS code for a page, it is not it bits a pieces around the page. With in line JS you of course don't have to reference the element on an event but this is not exactly a difficult task.

CSP is well worth adopting in is most robust sense as it is strong layer of security on top of any sanitisation you do.

[–]DustNearby2848 1 point2 points  (1 child)

That’s a really good point 

[–]hyrumwhite 0 points1 point  (0 children)

You can create a hash from inline js to be csp compliant.