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

Add script protection mechanisms to SVGScriptElement #524

Closed
wants to merge 1 commit into from

Conversation

lukewarlow
Copy link
Member

@lukewarlow lukewarlow commented Jun 12, 2024

Addresses #483


Preview | Diff

spec/index.bs Outdated
through a compliant sink. Equivalent to script's
[=child text content=]. Initially an empty string.

Issue: There's currently no defined processing model for {{SVGScriptElement}}s. This spec assumes one that is similar to that of {{HTMLScriptElement}}'s model.
Copy link
Member Author

Choose a reason for hiding this comment

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

This feels iffy but there really seems to be no spec for SVGScriptElement's atm. So this is an attempt to say "use common sense and good luck"

Copy link
Member Author

Choose a reason for hiding this comment

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

There's https://www.w3.org/TR/SVGMobile12/script.html#ScriptContentProcessing which is an old version of an SVG spec which could be monkey patched but idk that it really provides much value doing that.

@lukewarlow
Copy link
Member Author

I've rebased this atop the parser PR so I can account for everything SVG in one PR.

@lukewarlow lukewarlow changed the title Add script text associated data to SVGScriptElement. Add script protection mechanisms to SVGScriptElement Jun 12, 2024
@annevk
Copy link
Member

annevk commented Jun 12, 2024

Wouldn't it be better to handle HTML and SVG script at the same time?

@lukewarlow lukewarlow marked this pull request as ready for review June 12, 2024 14:46
@lukewarlow
Copy link
Member Author

Wouldn't it be better to handle HTML and SVG script at the same time?

Perhaps but they're pretty distinct from each other spec wise. This PR adds the "script text" and parser handling to svg script element that HTML script has. The only bit this PR is missing is actually doing the enforcement. I'm not sure how best to go about that due to the fact that SVG doesn't have a "prepare the script" method definition.

#525 will account for the more complicated parser stuff in one go for both SVG and HTML.

<li>...
</ol>

Issue: There's no proper definition for the processing of SVG script elements. However, you should apply a similar change to the processing of {{SVGScriptElement}}s.
Copy link
Member Author

Choose a reason for hiding this comment

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

@annevk can you think of a better way to word this, or a way to actually spec this?

I could try patching https://www.w3.org/TR/SVGMobile12/script.html#ScriptContentProcessing but it's a bit lose on the details and is fairly old, so idk that we'd ever upstream the patching.

Copy link
Member

Choose a reason for hiding this comment

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

The long term solution is probably for HTML to define both script elements, similar to how they are implemented.

Short term we might get away with some issue markers?

It's still not entirely clear to me that "script text" is a good approach as it essentially doubles the storage cost. What happened to some kind of boolean that we'd invalidate?

Copy link
Member Author

Choose a reason for hiding this comment

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

The boolean bit is currently only used as part of the "have the children been changed by an API during parsing" code.

Copy link
Member Author

Choose a reason for hiding this comment

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

The problem with a Boolean bit is how to allow the specific IDL and the "actually parsed" stuff but nothing else. I'm currently unable to think how you would do that.

Copy link
Member

Choose a reason for hiding this comment

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

Everything else that mutates would end up flipping the bit? It might help if we went through all the entry points we are concerned about or why this would be hard for some of them.

Copy link
Member

Choose a reason for hiding this comment

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

I'm still at 1 boolean. Presumably if a script set is trustworthy you can just set the existing bit to trustworthy in the end.

Copy link
Member Author

@lukewarlow lukewarlow Jul 1, 2024

Choose a reason for hiding this comment

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

Ah yeah actually we don't need a parse specific one anymore and provided it's all synchronous you're right you could set the "trusted" bit to true after the children changed steps (which would set it to false for all API calls).

If we make children changed always untrust API changes I think that solves any weirdness from mutation events too. Because we'd fail safe and the script would be untrusted. Because we only need the 3 sanctioned APIs to behave properly wrt to mutation events.

Thinking on it some more I think that could work?

cc @otherdaniel what do you think about that (Assuming we can get children changed steps spec to correctly tell us if it's API or parser)?

Relatively small changes needed (assuming my mental model is right) such as that below and then updating the children changed steps and the prepare script steps:

image

Copy link
Member Author

Choose a reason for hiding this comment

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

Thinking on this some more it would also fix #517 (different handling of new lines leading to TT errors)

Copy link
Member Author

@lukewarlow lukewarlow Jul 2, 2024

Choose a reason for hiding this comment

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

Okay so I tried implementing this and hit a snag.

https://html.spec.whatwg.org/#prepare-the-script-element:~:text=When%20a%20script%20element%20el%20that%20is%20not%20parser%2Dinserted%20experiences

This bit of the HTML spec is ran inside of children changed steps (at least in WebKit and I believe Chromium from a quick look), so prepare the script runs before the isTrusted flag is set back to true at the end of setInnerText.

So that seems to make the above plan not possible?

Edit: I think I've got a way that works using two booleans.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've opened a new draft PR which I'll use to do this new model (and will also apply to svg as best it can) #533

@lukewarlow lukewarlow closed this Jul 4, 2024
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