-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
641649a
commit 2599d2a
Showing
6 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# No `innerHTML` | ||
|
||
Using `innerHTML` poses a potential security risk. It should only be used when clearing content. | ||
|
||
```js | ||
// bad | ||
function setContent(element, content) { | ||
element.innerHTML = content | ||
} | ||
|
||
// good | ||
function clearContent(element) { | ||
element.innerHTML = '' | ||
} | ||
``` | ||
|
||
## See Also | ||
|
||
https://github.com/github/paste-markdown/security/advisories/GHSA-gpfj-4j6g-c4w9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module.exports = { | ||
meta: { | ||
type: 'problem', | ||
docs: { | ||
description: 'disallow `Element.prototype.innerHTML``', | ||
url: require('../url')(module) | ||
}, | ||
schema: [] | ||
}, | ||
|
||
create(context) { | ||
return { | ||
AssignmentExpression(node) { | ||
if (node.operator === "=") { | ||
const leftNode = node.left; | ||
const rightNode = node.right; | ||
|
||
if (leftNode.property && leftNode.property.name === 'innerHTML') { | ||
if (rightNode.type === 'Literal' && rightNode.value === '') { | ||
return | ||
} | ||
|
||
context.report({ | ||
node: node, | ||
message: | ||
'Using innerHTML poses a potential security risk and should not be used other than cleaning content.' | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const rule = require('../lib/rules/no-inner-html') | ||
const RuleTester = require('eslint').RuleTester | ||
|
||
const ruleTester = new RuleTester() | ||
|
||
ruleTester.run('no-innter-html', rule, { | ||
valid: [ | ||
{ | ||
code: 'document.createElement("js-flash-text").innerHTML = ""' | ||
} | ||
], | ||
invalid: [ | ||
{ | ||
code: 'document.createElement("js-flash-text").innerHTML = "foo"', | ||
errors: [ | ||
{ | ||
message: | ||
'Using innerHTML poses a potential security risk and should not be used other than cleaning content.', | ||
type: 'AssignmentExpression' | ||
} | ||
] | ||
}, | ||
{ | ||
code: 'document.querySelector("js-flash-text").innerHTML = "<div>code</div>"', | ||
errors: [ | ||
{ | ||
message: | ||
'Using innerHTML poses a potential security risk and should not be used other than cleaning content.', | ||
type: 'AssignmentExpression' | ||
} | ||
] | ||
} | ||
] | ||
}) |