UNPKG

3.47 kBJavaScriptView Raw
1"use strict";
2var __extends = (this && this.__extends) || (function () {
3 var extendStatics = Object.setPrototypeOf ||
4 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
6 return function (d, b) {
7 extendStatics(d, b);
8 function __() { this.constructor = d; }
9 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
10 };
11})();
12Object.defineProperty(exports, "__esModule", { value: true });
13var ts = require("typescript");
14var Lint = require("tslint");
15var ErrorTolerantWalker_1 = require("./utils/ErrorTolerantWalker");
16var AstUtils_1 = require("./utils/AstUtils");
17var FAILURE_INNER = 'Writing a string to the innerHTML property is insecure: ';
18var FAILURE_OUTER = 'Writing a string to the outerHTML property is insecure: ';
19var FAILURE_JQUERY = 'Using the html() function to write a string to innerHTML is insecure: ';
20var Rule = (function (_super) {
21 __extends(Rule, _super);
22 function Rule() {
23 return _super !== null && _super.apply(this, arguments) || this;
24 }
25 Rule.prototype.apply = function (sourceFile) {
26 return this.applyWithWalker(new NoInnerHtmlRuleWalker(sourceFile, this.getOptions()));
27 };
28 Rule.metadata = {
29 ruleName: 'no-inner-html',
30 type: 'maintainability',
31 description: 'Do not write values to innerHTML, outerHTML, or set HTML using the JQuery html() function.',
32 options: null,
33 optionsDescription: '',
34 typescriptOnly: true,
35 issueClass: 'SDL',
36 issueType: 'Error',
37 severity: 'Critical',
38 level: 'Mandatory',
39 group: 'Security',
40 commonWeaknessEnumeration: '79, 85, 710'
41 };
42 return Rule;
43}(Lint.Rules.AbstractRule));
44exports.Rule = Rule;
45var NoInnerHtmlRuleWalker = (function (_super) {
46 __extends(NoInnerHtmlRuleWalker, _super);
47 function NoInnerHtmlRuleWalker() {
48 return _super !== null && _super.apply(this, arguments) || this;
49 }
50 NoInnerHtmlRuleWalker.prototype.visitBinaryExpression = function (node) {
51 if (node.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
52 if (node.left.kind === ts.SyntaxKind.PropertyAccessExpression) {
53 var propAccess = node.left;
54 var propName = propAccess.name.text;
55 if (propName === 'innerHTML') {
56 this.addFailureAt(node.getStart(), node.getWidth(), FAILURE_INNER + node.getText());
57 }
58 else if (propName === 'outerHTML') {
59 this.addFailureAt(node.getStart(), node.getWidth(), FAILURE_OUTER + node.getText());
60 }
61 }
62 }
63 _super.prototype.visitBinaryExpression.call(this, node);
64 };
65 NoInnerHtmlRuleWalker.prototype.visitCallExpression = function (node) {
66 var functionName = AstUtils_1.AstUtils.getFunctionName(node);
67 if (functionName === 'html') {
68 if (node.arguments.length > 0) {
69 this.addFailureAt(node.getStart(), node.getWidth(), FAILURE_JQUERY + node.getText());
70 }
71 }
72 _super.prototype.visitCallExpression.call(this, node);
73 };
74 return NoInnerHtmlRuleWalker;
75}(ErrorTolerantWalker_1.ErrorTolerantWalker));
76//# sourceMappingURL=noInnerHtmlRule.js.map
\No newline at end of file