-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
html/template: script type attribute inside condition causes an error #59112
Comments
cc @golang/security |
@ianlancetaylor I don't understand how this is related to weird semicolons in markup input or invalid quotations in markup output. What is the correct error message in this case? |
While Different content types require different types of escaping, and with a dynamic value for |
When type=module, there's no inner text, so it's not an issue in that case, but I can see how encoding is an issue for language MIME types.
Then shouldn't constructing a dynamic type attribute value with the printf function be disallowed as well? That is currently allowed, at least in Hugo in combination with Hugo's safeHTMLAttr function. |
I don't know for sure, but perhaps a better error message would be something like "attempt to change script type in conditional context". I don't see how html/template can be expected to correctly handle such a case.
Perhaps I'm missing something, but that seems like an issue with Hugo, not html/template as such. |
Just spit balling: Would it be possible to evaluate the tag first, then the inner text once the escaping is known? Then type wouldn't have to be special-cased. Regardless, the behavior is surprising, and it should be explained in the package doc, along with any other special cases, in my opinion.
Hugo uses html/template under the hood. I assume safeHTMLAttr is a normal custom function that html/template allows, but perhaps that's wrong. @jmooring or @bep might know more. |
Change https://go.dev/cl/496145 mentions this issue: |
What did you do?
Template:
What did you expect to see?
<script type=""></script>What did you see instead?
If you remove the condition around the type attribute, or rename type to something else, then there's no error.
Remarks
The <script> type attribute value should be able to be dynamic to substitute in the various valid values for type:
Note that the original template was:
See here for the original context.
This is a valid construct for every other HTML attribute I've ever tried it on.
This issue was already reported in #57136, however it's clear that the maintainer who closed the issue didn't understand it, as the author explained after it was closed. There was no reply.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputThe text was updated successfully, but these errors were encountered: