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

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

Merged
merged 2 commits into from
Feb 18, 2019

Conversation

jelhan
Copy link
Contributor

@jelhan jelhan commented Jan 9, 2019

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
Copy link
Member

@Krinkle Krinkle left a comment

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.

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

allModulesLabel.classList.add( "clickable" );
Copy link
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
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.

@@ -370,15 +374,27 @@ export function escapeText( s ) {
label.innerHTML = "Module: ";
label.appendChild( moduleSearch );

applyButton.textContent = "Apply";
applyButton.style.display = "none";
Copy link
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
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
Copy link
Contributor Author

jelhan commented Feb 13, 2019

@Krinkle Is there still something needed here?

Copy link
Member

@trentmwillis trentmwillis left a comment

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