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

Manipulation: Make domManip run scripts under TrustedScriptURL CSP enforcement [trusted-types] #4963

Open
mgol opened this issue Nov 1, 2021 · 0 comments
Assignees
Milestone

Comments

@mgol
Copy link
Member

mgol commented Nov 1, 2021

Description

This is a followup to gh-4948. In gh-4949, we stopped stringifying attributes which makes setting the src attribute on a script tag work under trusted types TrustedScriptURL enforcement via Content Security Policy. However, such scripts are still blocked. This is because in domManip scripts are not inserted directly but instead first disabled and then their src attributes are read and inserted in fresh scripts.

There's probably not much we can do when the scripts are deep inside of the inserted HTML string - natively scripts would not fire then but jQuery does execute them which will not work here. However, we could at least make .append(scriptElem) work by forking the code path and treating such top-level scripts independently.

Link to test case

This test is failing:
https://github.com/mgol/jquery/blob/2ba71fa76c09fad476669a320294edeca6b5513c/test/data/trusted-types-attributes.html#L27-L31

For posterity, JS source, more or less:

const policy = trustedTypes.createPolicy( "jquery-test-policy", {
	createScriptURL: function( html ) {
		return html;
	}
} );

const elem = jQuery( "<script></script>" )
	.attr( "src", policy.createScriptURL( "trusted-types-attributes.js" ) );
elem.appendTo( document.body );

The expectation is the trusted-types-attributes.js script is executed but currently it is not if the header:

Content-Security-Policy: require-trusted-types-for 'script'

is set.

@mgol mgol added this to the 4.0.0 milestone Nov 1, 2021
@mgol mgol self-assigned this Nov 1, 2021
@jquery jquery deleted a comment Apr 11, 2022
@jquery jquery deleted a comment Apr 11, 2022
@timmywil timmywil modified the milestones: 4.0.0, 4.1.0 Aug 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants