eslint-plugin-no-unsanitized
Version:
ESLint rule to disallow unsanitized code
93 lines (75 loc) • 2.24 kB
Markdown
The plugin allows a limit back-tracing of variables.
This will be used to check code like here:
```js
const greeting_template = `<p>Hello World!</p>`;
// ... lots of other code in between ...
someElement.innerHTML = greeting_template;
```
Currently, backtracing will only allow const and let variables that contain string literals only.
Further assignments to these variables will also be checked for validation.
**Backtracing can be disabled by setting the boolean
option `variableTracing` to `false`.**
Both values are supported and tested in CI.
You can customize the way this rule works in various ways.
- Add to the list of properties or functions to be checked for potentially
dangers variable input
- Add to the list of allowed escaping functions to mitigate security concerns
- Besides adding to the list, you may override the defaults and provide an exhaustive list yourself
```json
{
"rules": {
"no-unsanitized/method": [
"error",
{},
{
"html": {
"properties": [0]
}
}
]
}
}
```
```js
{
"plugins": ["no-unsanitized"],
"rules": {
"no-unsanitized/method": [
"error",
{
disableDefault: true,
escape: {
taggedTemplates: ["safeHTML"]
}
},
{
html: {
properties: [0]
}
}
],
"no-unsanitized/method": [
"error",
{
escape: {
taggedTemplates: ["safeHTML"]
}
},
{
innerHTML: {
objectMatches: ["document.*"]
}
}
]
}
}
```
TBD
- See [our rule schema definition](https://github.com/mozilla/eslint-plugin-no-unsanitized/blob/main/SCHEMA.md).