Skip to content

Commit 37dbc7b

Browse files
nodirtbradfitz
authored andcommitted
html/template: escape JS in application/json script tag
Since ffd1c78 HTML templates check MIME type in the "type" attribute of "script" tag to decide if contents should be escaped as JavaScript. The whitelist of MIME types did not include application/json. Include it in this CL. Fixes golang#18159 Change-Id: I17a8a38f2b7789b4b7e941d14279de222eaf2b6a Reviewed-on: https://go-review.googlesource.com/33899 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
1 parent d29f72f commit 37dbc7b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/html/template/js.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,10 @@ func isJSIdentPart(r rune) bool {
368368
// It is used to determine whether a script tag with a type attribute is a javascript container.
369369
func isJSType(mimeType string) bool {
370370
// per
371-
// http://www.w3.org/TR/html5/scripting-1.html#attr-script-type
371+
// https://www.w3.org/TR/html5/scripting-1.html#attr-script-type
372372
// https://tools.ietf.org/html/rfc7231#section-3.1.1
373-
// http://tools.ietf.org/html/rfc4329#section-3
373+
// https://tools.ietf.org/html/rfc4329#section-3
374+
// https://www.ietf.org/rfc/rfc4627.txt
374375

375376
// discard parameters
376377
if i := strings.Index(mimeType, ";"); i >= 0 {
@@ -381,6 +382,7 @@ func isJSType(mimeType string) bool {
381382
case
382383
"application/ecmascript",
383384
"application/javascript",
385+
"application/json",
384386
"application/x-ecmascript",
385387
"application/x-javascript",
386388
"text/ecmascript",

0 commit comments

Comments
 (0)