So, the backstory is that I am the developer of a pretty big CMS. hundreds of thousands of lines of code.
So when implementing a Content Security Policy I was forced to use "unsafe-inline" for the style-src and script-src directives, since the CMS outputs a lot of inline CSS in elements and also a lot of onclick-attributes for scripting.
In order to extract the inline styles, I have updated the code that creates the actual HTML to make a crc32 hash of the inline style, apply a class to the element and then print all the CSS seperately in a style tag that has a nonce-attribute. The end result looks like this:
With inline scripts, or rather onclick attributes, I have done something similar, create a crc32 of the command, add that as a inline class for the element and then adding it to a script tag. The problem is that I am using jQuery to attach these events to the elements, and the old live() function is deprecated, so I've attached it as a click event on the body element, so that hidden elements will still fire. The end result looks like this:
So, all of these were earlier <a onclick="pop('....')">
or something similar. I am wondering what the best practice for this fix is.
And before you suggest that each of these instances should have their actions attached more logically or replaced by some form of internal logic to make them fire the correct command - I agree! But it's a lot of code! My first step is to make a fix and then start addressing each instance to make a more beautiful fix.
So is there a better way to approach this?