Skip to content

fix: HTML reporter should not require CSP style-src 'unsafe-inline' - #1369

Merged
Krinkle merged 2 commits into
qunitjs:masterfrom
jelhan:fix-csp-style-src-unsafe-inline
Feb 18, 2019
Merged

Krinkle merged 2 commits into
qunitjs:masterfrom
jelhan:fix-csp-style-src-unsafe-inline

Conversation

@jelhan

@jelhan jelhan commented Jan 9, 2019

Copy link
Copy Markdown
Contributor

Using style attribute of an Element requires Content-Security-Policy (CSP) style-src 'unsafe-inline'. This makes testing that a library or an application does not violate a strict CSP more difficult.

Using `style` attribute of an Element requires Content-Security-Policy (CSP)
style-src 'unsafe-inline'. This makes testing that a library or an
application does not violate a strict CSP more difficult.
Krinkle
Krinkle previously approved these changes Jan 16, 2019

@Krinkle Krinkle left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting this. I'd be quite open to have QUnit be compatible with a strict CSP policy.

Having said that, if the CSP rule works the way I think it does, we'll need a lot more changes. I'd be happy to keep reviewing and accept them in small chunks, however you prefer.

Comment thread reporter/html.js Outdated
allCheckbox.type = "checkbox";
allCheckbox.checked = config.moduleId.length === 0;

allModulesLabel.classList.add( "clickable" );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect classList we might still support browsers in QUnit that predate classList. Would need to use className instead, if so.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't expected anyone to still support IE9 and IE10 as even Microsoft has dropped support more that two years ago. But you are right, QUnit webseite says:

QUnit currently supports the same browsers as jQuery 3.x.

And jQuery lists Internet Explorer: 9+.

Pushed the change.

Comment thread reporter/html.js
label.appendChild( moduleSearch );

applyButton.textContent = "Apply";
applyButton.style.display = "none";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't confirmed, so apologies if this isn't true... I would expect the CSP policy for inline styles to disallow all three methods of dynamic style creation: <style> elements, style="" attributes, and CSSOM/style properties (like this one).

To abide the CSP strict style policy, I think we need to declare the styles in the CSS file ahead of time, and toggle them with a class only. For example, the qunit-modulefilter-dropdown element could have a class like has-selection or has-no-selection. And based on that, we could hide the buttons as needed.

However, the apply button isn't the only violation, so to address your use case we'll need numerous other changes as well. Again, that's based on my (potentially) outdated understanding of CSP.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The specification is not quite clear regarding CSSOM and CSP but as far as I'm aware of none of the implementation considers manipulating styles through CSSOM as a CSP violation. So while document.create('<button style="display: none;">') and document.create('button').style = "display: none;" require style-src 'unsafe-inline', document.create('button').style.display = 'none' is not violation style-src: 'none'.

@Krinkle
Krinkle dismissed their stale review January 16, 2019 07:17

Pressed the wrong button, sorry.

@jelhan

jelhan commented Feb 13, 2019

Copy link
Copy Markdown
Contributor Author

@Krinkle Is there still something needed here?

@trentmwillis trentmwillis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. @Krinkle any additional comments?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants