Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use dynamic event handlers on elements to prevent nonce-based CSP errors (unsafe-inline disallowed) #675

Merged

Conversation

stringfellow
Copy link
Contributor

@stringfellow stringfellow commented Jun 9, 2023

This is a fix for issue #373 which causes significant issues for sites requiring strict CSP settings, allowing use of a nonce in the calling script tag, which which means the attached event handlers become trusted.

I have made a start as a proof of concept and on the fields/use cases that address our needs at DemandLogic. If @vedmack approves this approach, it could be refactored to match throughout.

UPDATE: JSFiddle

@stringfellow stringfellow changed the title [WIP] text, select2, select with CSP-safe events Use dynamic event handlers on elements to prevent nonce-based CSP errors (unsafe-inline disallowed) Jun 9, 2023
@stringfellow stringfellow marked this pull request as ready for review June 9, 2023 14:53
@stringfellow stringfellow mentioned this pull request Jun 9, 2023
@vedmack
Copy link
Owner

vedmack commented Jun 15, 2023

Hi @stringfellow

Thanks for the PR, can you post some basic jsfiddle / etc` with your PR to see how it behaves? I will try to go over it in the upcoming days

@stringfellow
Copy link
Contributor Author

Thanks @vedmack ! Here's an example - there is a console error but the example is functional. I can't quite track down in the call stack where the console error originates from... if you have any ideas/hints from anything that might be obvious to you that isn't to me, I'd be very happy to take another look at it :)

@stringfellow
Copy link
Contributor Author

stringfellow commented Jun 15, 2023

Scratch that @vedmack! Found it, I missed one of the element setup calls (see ede114e above, and e635a59 below). New fiddle here

@stringfellow
Copy link
Contributor Author

@vedmack we've been using this in our production code with strict CSP and all seems to be working nicely :)

@vedmack
Copy link
Owner

vedmack commented Jul 15, 2023

on it now
merged and published as a new beta
you can install it with npm install yadcf@beta

@vedmack vedmack merged commit 5a3ff4a into vedmack:master Jul 15, 2023
vedmack pushed a commit that referenced this pull request Jul 15, 2023
…n elements to prevent nonce-based CSP errors (unsafe-inline disallowed) - #675
@vedmack
Copy link
Owner

vedmack commented Jul 15, 2023

@stringfellow , although it was years ago, I remember when that when I tried to use .on("click" instead of .attr("onclick", it did not work, cause the datatables were triggered first, which was resulting in a column being sorted instead of "filtered by yadcf", so I wonder why now it does work properly, any ideas?

@stringfellow
Copy link
Contributor Author

Hmmm indeed that is a bit strange! Thanks for merging, I missed the notification somehow so will take a look at reverting to the official release ASAP. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants