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
Copy file name to clipboardExpand all lines: README.md
+8-4Lines changed: 8 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ npm i ghtml
12
12
13
13
### `html`
14
14
15
-
The `html` function is designed to tag template literals and automatically escape their expressions to prevent XSS attacks. To intentionally bypass escaping for a specific expression, prefix it with `!`.
15
+
The `html` function is designed to tag template literals and automatically escape their expressions. To intentionally bypass escaping a specific expression, prefix it with `!`.
16
16
17
17
### `htmlGenerator`
18
18
@@ -32,7 +32,7 @@ Because they return generators instead of strings, a key difference of `htmlGene
32
32
33
33
### `includeFile`
34
34
35
-
Available for Node.js users, the `includeFile` function is a wrapper around `readFileSync`. It reads and outputs the content of a file while also caching it in memory for faster future reuse.
35
+
Available in Node.js, the `includeFile` function is a wrapper around `readFileSync`. It reads and outputs the content of a file while also caching it in memory for faster future reuse.
36
36
37
37
## Usage
38
38
@@ -41,11 +41,11 @@ Available for Node.js users, the `includeFile` function is a wrapper around `rea
@@ -168,3 +168,7 @@ const logo = includeFile("static/logo.svg");
168
168
console.log(logo);
169
169
// Output: content of "static/logo.svg"
170
170
```
171
+
172
+
## Security
173
+
174
+
Like [similar](https://handlebarsjs.com/guide/#html-escaping)[tools](https://github.com/mde/ejs/blob/main/SECURITY.md#out-of-scope-vulnerabilities), `ghtml` will not prevent all kinds of XSS attacks. It is the responsibility of consumers to sanitize user inputs. Some inherently insecure uses include dynamically generating JavaScript, failing to quote HTML attribute values (especially when they contain expressions), and using unsanitized user-provided URLs.
"<p>This is a safe description.<script>alert('This is an unsafe description.')</script>12345255</p>",
159
+
"<p>This is a safe description.<script>alert('This is an unsafe description.')</script>12345255</p>",
160
160
);
161
161
});
162
162
@@ -199,7 +199,7 @@ test("htmlGenerator works with other generators (escaped)", () => {
199
199
200
200
assert.strictEqual(
201
201
accumulator,
202
-
"<div><p>This is a safe description.<script>alert('This is an unsafe description.')</script>12345255</p></div>",
202
+
"<div><p>This is a safe description.<script>alert('This is an unsafe description.')</script>12345255</p></div>",
203
203
);
204
204
assert.strictEqual(generator.next().done,true);
205
205
});
@@ -229,7 +229,7 @@ test("htmlGenerator works with other generators within an array (escaped)", () =
229
229
230
230
assert.strictEqual(
231
231
accumulator,
232
-
"<div><p>This is a safe description.<script>alert('This is an unsafe description.')</script>1,2,3,4,5255</p></div>",
232
+
"<div><p>This is a safe description.<script>alert('This is an unsafe description.')</script>1,2,3,4,5255</p></div>",
"<p>This is a safe description.<script>alert('This is an unsafe description.')</script>12345255</p>",
261
+
"<p>This is a safe description.<script>alert('This is an unsafe description.')</script>12345255</p>",
262
262
);
263
263
});
264
264
@@ -286,7 +286,7 @@ test("htmlAsyncGenerator works with other generators (escaped)", async () => {
286
286
287
287
assert.strictEqual(
288
288
accumulator,
289
-
"<div><p>This is a safe description.<script>alert('This is an unsafe description.')</script>12345255</p></div>",
289
+
"<div><p>This is a safe description.<script>alert('This is an unsafe description.')</script>12345255</p></div>",
290
290
);
291
291
});
292
292
@@ -302,7 +302,7 @@ test("htmlAsyncGenerator works with nested htmlAsyncGenerator calls in an array"
0 commit comments