You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 5, 2018. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+37-4Lines changed: 37 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -103,18 +103,51 @@ npm test
103
103
104
104
### Warnings and Workarounds
105
105
When output expressions are found inside dangerous (yet-to-be-supported) contexts, we echo warnings and gracefully fallback to apply the default Handlebars [`escapeExpression()`](http://handlebarsjs.com/#html-escaping). These warnings are indications of potential security exploits, and thus require closer inspections. Instead of simply abusing `{{{raw_expression}}}` to suppress the warnings, here are some alternative suggestions to secure your applications.
106
-
- Output expression in the `<script>` tag: <br/>`[WARNING] SecureHandlebars: Unsafe output expression found at scriptable <script> tag`
107
-
```html
106
+
-[WARNING] SecureHandlebars: Unsafe output expression found at scriptable `<script>` tag
- Output expression in an event attribute (e.g., `onclick=""`): <br/>`[WARNING] SecureHandlebars: Unsafe output expression found at onclick JavaScript event attribute`
113
-
```html
113
+
-[WARNING] SecureHandlebars: Unsafe output expression found at onclick JavaScript event attribute
114
+
115
+
-*Case 1.* the data is trusted, or will not be used as URI/HTML output
-*Case 2A.* the data will be used as URI/HTML output<br/>The contextual analyzer does not (cannot) evaluate your JavaScript code, and thus lacks the information on which contexts the data will be ultimately used. Therefore, you must manually apply the escaping filters including `uriData` (a patched `encodeURI()`), `uriComponentData` (alias of `encodeURIComponent()`), and the [xss-filters](https://github.com/yahoo/xss-filters#client-side-browser) that are already registered as Handlebars helpers.
123
+
```html
124
+
<script>
125
+
functionsearch(url, keyword) {
126
+
var xhr =newXMLHttpRequest(); xhr.open('GET', url, true); // ...
127
+
document.getElementById('status').innerHTML='Searching for '+ keyword;
The manually-applied filters here are to pre-escape `{{keyword}}` depending on the ultimate output contexts, while the `{{``}}` is still needed (**NOT**`{{{ }}}`) to let `secure-handlebars` automatically applies the escaping filter for the immediate attribute value context.
136
+
137
+
-*Case 2B.* Alternatively, just in case the output pre-escaping is what you want to avoid, please embed the [xss-filters](https://github.com/yahoo/xss-filters/#client-side-browser) on the client-side for filtering.
138
+
```html
139
+
<scriptsrc="dist/xss-filters.min.js"></script>
140
+
<script>
141
+
functionsearch(keyword) {
142
+
// ...
143
+
document.getElementById('status').innerHTML='Searching for '+xssFilters.inHTMLData(keyword);
0 commit comments