Skip to content

Prototype.js registers an event handler in a way that triggers CSP errors #320

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

Closed
april opened this issue Aug 18, 2016 · 3 comments
Closed

Comments

@april
Copy link

april commented Aug 18, 2016

This particular bit of code:

  var PROBLEMATIC_ATTRIBUTE_READING = (function() {
    DIV.setAttribute('onclick', []);
    var value = DIV.getAttribute('onclick');
    var isFunction = Object.isArray(value);
    DIV.removeAttribute('onclick');
    return isFunction;
  })();

Will trigger warnings in Firefox and Edge when 'unsafe-inline' execution of JavaScript is blocked via CSP. This code could perhaps be removed entirely; alternatively, it could use addEventListener(), which does not cause the same CSP errors.

See also:
https://bugzilla.mozilla.org/show_bug.cgi?id=1296027
https://bugs.chromium.org/p/chromium/issues/detail?id=638957

Thanks!

@jwestbrook
Copy link
Collaborator

jwestbrook commented Aug 18, 2016

This block of code is a feature detection to determine if the browser has a problem setting and retrieving a function or array as the onclick attribute. After this block it is not used anymore and will use the bool PROBLEMATIC_ATTRIBUTE_READING flag to determine how further features should be implemented.

In the github master branch this block has been removed as it was mainly for older browsers. This should be resolved at next release.

@april
Copy link
Author

april commented Aug 18, 2016

Awesome, that's great to hear! Thanks much!

@candrews
Copy link

candrews commented Nov 24, 2020

In prototype 1.7.3 (the current latest version), I changed lines 2776-2278 from:

  })();

  if (PROBLEMATIC_ATTRIBUTE_READING) {

to

  });

  if (Prototype.Browser.IE && PROBLEMATIC_ATTRIBUTE_READING()) {

as a workaround for this issue that doesn't also drop compatibility with old browsers which https://github.com/prototypejs/prototype/pull/307/files#diff-6fef80e8642914b14295c6c309ca4cff26e719fb7891045faa3ab5069a10f5e7 does (that's the change referenced in earlier comment #320 (comment) )

candrews added a commit to candrews/javamelody that referenced this issue Nov 24, 2020
candrews added a commit to candrews/javamelody that referenced this issue Nov 24, 2020
candrews added a commit to candrews/javamelody that referenced this issue Nov 24, 2020
candrews added a commit to candrews/javamelody that referenced this issue Dec 18, 2020
evernat pushed a commit to javamelody/javamelody that referenced this issue Apr 5, 2021
candrews added a commit to candrews/javamelody that referenced this issue Apr 23, 2021
evernat pushed a commit to javamelody/javamelody that referenced this issue May 6, 2021
goldyliang pushed a commit to goldyliang/javamelody that referenced this issue Mar 17, 2022
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

No branches or pull requests

4 participants