@@ -18,16 +18,28 @@ type (
18
18
// 4. The CSS3 value production, such as `rgba(0, 0, 255, 127)`.
19
19
// See http://www.w3.org/TR/css3-syntax/#parsing and
20
20
// https://web.archive.org/web/20090211114933/http://w3.org/TR/css3-syntax#style
21
+ //
22
+ // Use of this type presents a security risk:
23
+ // the encapsulated content should come from a trusted source,
24
+ // as it will be included verbatim in the template output.
21
25
CSS string
22
26
23
27
// HTML encapsulates a known safe HTML document fragment.
24
28
// It should not be used for HTML from a third-party, or HTML with
25
29
// unclosed tags or comments. The outputs of a sound HTML sanitizer
26
30
// and a template escaped by this package are fine for use with HTML.
31
+ //
32
+ // Use of this type presents a security risk:
33
+ // the encapsulated content should come from a trusted source,
34
+ // as it will be included verbatim in the template output.
27
35
HTML string
28
36
29
37
// HTMLAttr encapsulates an HTML attribute from a trusted source,
30
38
// for example, ` dir="ltr"`.
39
+ //
40
+ // Use of this type presents a security risk:
41
+ // the encapsulated content should come from a trusted source,
42
+ // as it will be included verbatim in the template output.
31
43
HTMLAttr string
32
44
33
45
// JS encapsulates a known safe EcmaScript5 Expression, for example,
@@ -37,6 +49,15 @@ type (
37
49
// statement/expression ambiguity as when passing an expression like
38
50
// "{ foo: bar() }\n['foo']()", which is both a valid Expression and a
39
51
// valid Program with a very different meaning.
52
+ //
53
+ // Use of this type presents a security risk:
54
+ // the encapsulated content should come from a trusted source,
55
+ // as it will be included verbatim in the template output.
56
+ //
57
+ // Using JS to include valid but untrusted JSON is not safe.
58
+ // A safe alternative is to parse the JSON with json.Unmarshal and then
59
+ // pass the resultant object into the template, where it will be
60
+ // converted to sanitized JSON when presented in a JavaScript context.
40
61
JS string
41
62
42
63
// JSStr encapsulates a sequence of characters meant to be embedded
@@ -46,13 +67,21 @@ type (
46
67
// | EscapeSequence
47
68
// Note that LineContinuations are not allowed.
48
69
// JSStr("foo\\nbar") is fine, but JSStr("foo\\\nbar") is not.
70
+ //
71
+ // Use of this type presents a security risk:
72
+ // the encapsulated content should come from a trusted source,
73
+ // as it will be included verbatim in the template output.
49
74
JSStr string
50
75
51
76
// URL encapsulates a known safe URL or URL substring (see RFC 3986).
52
77
// A URL like `javascript:checkThatFormNotEditedBeforeLeavingPage()`
53
78
// from a trusted source should go in the page, but by default dynamic
54
79
// `javascript:` URLs are filtered out since they are a frequently
55
80
// exploited injection vector.
81
+ //
82
+ // Use of this type presents a security risk:
83
+ // the encapsulated content should come from a trusted source,
84
+ // as it will be included verbatim in the template output.
56
85
URL string
57
86
)
58
87
0 commit comments