-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathno-document-write.js
41 lines (37 loc) · 1.21 KB
/
no-document-write.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/**
* @fileoverview Rule to disallow document.write or document.writeln method call
* @author Antonios Katopodis
*/
"use strict";
const astUtils = require("../ast-utils");
module.exports = {
meta: {
type: "suggestion",
fixable: "code",
schema: [],
docs: {
category: "Security",
description:
"Calls to document.write or document.writeln manipulate DOM directly without any sanitization and should be avoided. Use document.createElement() or similar methods instead.",
url: "https://github.com/microsoft/eslint-plugin-sdl/blob/master/docs/rules/no-document-write.md"
},
messages: {
default: "Do not write to DOM directly using document.write or document.writeln methods"
}
},
create: function (context) {
const fullTypeChecker = astUtils.getFullTypeChecker(context);
return {
"CallExpression[arguments.length=1][callee.property.name=/write|writeln/]"(node) {
if (astUtils.isDocumentObject(node.callee.object, context, fullTypeChecker)) {
context.report({
node: node,
messageId: "default"
});
}
}
};
}
};