Skip to content

Commit f2e4d26

Browse files
Port template-no-triple-curlies rule from PR #2371
Co-authored-by: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com>
1 parent c7dfa70 commit f2e4d26

File tree

5 files changed

+14206
-0
lines changed

5 files changed

+14206
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,12 @@ rules in templates can be disabled with eslint directives with mustache or html
304304
| [route-path-style](docs/rules/route-path-style.md) | enforce usage of kebab-case (instead of snake_case or camelCase) in route paths | | | 💡 |
305305
| [routes-segments-snake-case](docs/rules/routes-segments-snake-case.md) | enforce usage of snake_cased dynamic segments in routes || | |
306306

307+
### Security
308+
309+
| Name                       | Description | 💼 | 🔧 | 💡 |
310+
| :--------------------------------------------------------------------- | :------------------------------------------------------------ | :- | :- | :- |
311+
| [template-no-triple-curlies](docs/rules/template-no-triple-curlies.md) | disallow usage of triple curly brackets (unescaped variables) | | | |
312+
307313
### Services
308314

309315
| Name                                      | Description | 💼 | 🔧 | 💡 |
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# ember/template-no-triple-curlies
2+
3+
<!-- end auto-generated rule header -->
4+
5+
Disallows usage of triple curly brackets (unescaped output) in templates.
6+
7+
Triple curly brackets (`{{{ }}}`) render unescaped HTML, which can lead to XSS (Cross-Site Scripting) vulnerabilities if user input is not properly sanitized.
8+
9+
## Rule Details
10+
11+
This rule disallows the use of triple curly brackets for unescaped output. If you need to render HTML, use the `htmlSafe` helper or `SafeString` API with proper sanitization.
12+
13+
## Examples
14+
15+
Examples of **incorrect** code for this rule:
16+
17+
```gjs
18+
<template>
19+
{{{this.content}}}
20+
</template>
21+
```
22+
23+
```gjs
24+
<template>
25+
<div>
26+
{{{@htmlContent}}}
27+
</div>
28+
</template>
29+
```
30+
31+
Examples of **correct** code for this rule:
32+
33+
```gjs
34+
<template>
35+
{{this.content}}
36+
</template>
37+
```
38+
39+
```gjs
40+
<template>
41+
{{htmlSafe this.sanitizedContent}}
42+
</template>
43+
```
44+
45+
```gjs
46+
<template>
47+
<div>{{@text}}</div>
48+
</template>
49+
```
50+
51+
## When Not To Use It
52+
53+
If you are certain that the content being rendered is already sanitized and safe, you may disable this rule. However, this is generally discouraged for security reasons.
54+
55+
## Related Rules
56+
57+
- [no-html-safe](./no-html-safe.md) from eslint-plugin-ember
58+
59+
## References
60+
61+
- [ember-template-lint no-triple-curlies](https://github.com/ember-template-lint/ember-template-lint/blob/master/docs/rule/no-triple-curlies.md)
62+
- [Ember.js Security Guide](https://guides.emberjs.com/release/security/)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/** @type {import('eslint').Rule.RuleModule} */
2+
module.exports = {
3+
meta: {
4+
type: 'problem',
5+
docs: {
6+
description: 'disallow usage of triple curly brackets (unescaped variables)',
7+
category: 'Security',
8+
recommended: false,
9+
url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/template-no-triple-curlies.md',
10+
},
11+
fixable: null,
12+
schema: [],
13+
messages: {
14+
unsafe:
15+
'Usage of triple curly brackets is unsafe. Use htmlSafe helper if absolutely necessary.',
16+
},
17+
},
18+
19+
create(context) {
20+
return {
21+
GlimmerMustacheStatement(node) {
22+
// Check if the statement is unescaped (triple curlies)
23+
// Use 'trusting' property (escaped is deprecated)
24+
if (node.trusting === true) {
25+
context.report({
26+
node,
27+
messageId: 'unsafe',
28+
});
29+
}
30+
},
31+
};
32+
},
33+
};

0 commit comments

Comments
 (0)