-
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: srcset incorrectly escaped #17441
Comments
Also, I can't figure out how to override the escaping using the types in the package. The two that I thought would work ( |
@okdave I don't know the answer to your question, but you can work around the issue by using HTMLAttr with the whole attribute: https://play.golang.org/p/uZUPL7OgA2 |
Thanks @cespare that's exactly what I had to end up doing, though it felt wrong. |
This looks like it will need to introduce new states into the HTML analyzer. /cc @mikesamuel for advice. |
I would be interested in picking this up. Any advice on where to start? |
The html/template doc comment explains a lot about what is going on in this package. |
https://golang.org/src/html/template/content.go probably needs a new content type for space delimited URLs. The table of attribute types in https://golang.org/src/html/template/attr.go probably needs a mapping for srcset. url.go would then probably need a URL escaper variant that allows [\t\n\r ] through unescaped. I forgot quite where content types are mapped to escapers, but some grepping around should find it easily enough. |
Cool. I'll take a go at this. |
CL https://golang.org/cl/38324 mentions this issue. |
I've ran the trybots on that CL so that to reignite the conversation on @zombiezen's CL as I see it is marked for Go1.9, what do you think @bradfitz? |
I'm happy to carry this forward, but I need review from someone who understands the security implications. |
Punting this to Go1.10 as per @rsc's comment on the CL. |
@rsc @odeke-em @zombiezen I've tried to upload patch set for adding @rsc's comments in tests. |
Per the discussion about URL filtering in I tried to upload a patch set, but need to sort out some Gerrit credential issue. |
tl;dr: https://play.golang.org/p/8A4TQ1-Kvt
The
html/template
defaults to thecontentTypeURL
content type for any attribute that contains the substring"src"
.However the
srcset
attribute is a set of URLs which are separated by whitespace and optional extra size/density indicators (see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-srcset).For example
"image1.jpg w200, image2.jpg w400"
.When this is escaped as the
contentTypeURL
the spaces are encoded, the whole thing looks like a single URL, and the resource fails to load.Got
<img srcset="1.jpg%20w200,%202.jpg%20w200">
Want
<img srcset="1.jpg w200, 2.jpg w200">
The text was updated successfully, but these errors were encountered: