UNPKG

2.99 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 Rule = (function (_super) {
17 __extends(Rule, _super);
18 function Rule() {
19 return _super !== null && _super.apply(this, arguments) || this;
20 }
21 Rule.prototype.applyWithProgram = function (sourceFile, program) {
22 return this.applyWithWalker(new NoCookiesWalker(sourceFile, this.getOptions(), program));
23 };
24 Rule.metadata = {
25 ruleName: 'no-cookies',
26 type: 'maintainability',
27 description: 'Do not use cookies',
28 options: null,
29 optionsDescription: '',
30 typescriptOnly: true,
31 issueClass: 'SDL',
32 issueType: 'Error',
33 severity: 'Critical',
34 level: 'Mandatory',
35 group: 'Security',
36 commonWeaknessEnumeration: '315, 539, 565, 614'
37 };
38 Rule.FAILURE_STRING = 'Forbidden call to document.cookie';
39 return Rule;
40}(Lint.Rules.TypedRule));
41exports.Rule = Rule;
42var NoCookiesWalker = (function (_super) {
43 __extends(NoCookiesWalker, _super);
44 function NoCookiesWalker(sourceFile, options, program) {
45 var _this = _super.call(this, sourceFile, options) || this;
46 _this.typeChecker = program.getTypeChecker();
47 return _this;
48 }
49 NoCookiesWalker.prototype.visitPropertyAccessExpression = function (node) {
50 var propertyName = node.name.text;
51 if (propertyName === 'cookie') {
52 var leftSide = node.expression;
53 try {
54 var leftSideType = this.typeChecker.getTypeAtLocation(leftSide);
55 var typeAsString = this.typeChecker.typeToString(leftSideType);
56 if (leftSideType.flags === ts.TypeFlags.Any || typeAsString === 'Document') {
57 this.addFailureAt(leftSide.getStart(), leftSide.getWidth(), Rule.FAILURE_STRING);
58 }
59 }
60 catch (e) {
61 if (leftSide.getFullText().trim() === 'document') {
62 this.addFailureAt(leftSide.getStart(), leftSide.getWidth(), Rule.FAILURE_STRING);
63 }
64 }
65 }
66 _super.prototype.visitPropertyAccessExpression.call(this, node);
67 };
68 return NoCookiesWalker;
69}(ErrorTolerantWalker_1.ErrorTolerantWalker));
70//# sourceMappingURL=noCookiesRule.js.map
\No newline at end of file