1 | "use strict";
|
2 | var __extends = (this && this.__extends) || (function () {
|
3 | var extendStatics = function (d, b) {
|
4 | extendStatics = Object.setPrototypeOf ||
|
5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
6 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
7 | return extendStatics(d, b);
|
8 | }
|
9 | return function (d, b) {
|
10 | extendStatics(d, b);
|
11 | function __() { this.constructor = d; }
|
12 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
13 | };
|
14 | })();
|
15 | Object.defineProperty(exports, "__esModule", { value: true });
|
16 | var ts = require("typescript");
|
17 | var Lint = require("tslint");
|
18 | var tsutils = require("tsutils");
|
19 | var Rule = (function (_super) {
|
20 | __extends(Rule, _super);
|
21 | function Rule() {
|
22 | return _super !== null && _super.apply(this, arguments) || this;
|
23 | }
|
24 | Rule.prototype.applyWithProgram = function (sourceFile, program) {
|
25 | return this.applyWithFunction(sourceFile, walk, undefined, program);
|
26 | };
|
27 | Rule.metadata = {
|
28 | ruleName: 'no-cookies',
|
29 | type: 'maintainability',
|
30 | description: 'Do not use cookies',
|
31 | options: null,
|
32 | optionsDescription: '',
|
33 | typescriptOnly: true,
|
34 | issueClass: 'SDL',
|
35 | issueType: 'Error',
|
36 | severity: 'Critical',
|
37 | level: 'Mandatory',
|
38 | group: 'Security',
|
39 | commonWeaknessEnumeration: '315, 539, 565, 614'
|
40 | };
|
41 | Rule.FAILURE_STRING = 'Forbidden call to document.cookie';
|
42 | return Rule;
|
43 | }(Lint.Rules.TypedRule));
|
44 | exports.Rule = Rule;
|
45 | function walk(ctx, program) {
|
46 | var typeChecker = program.getTypeChecker();
|
47 | function cb(node) {
|
48 | if (tsutils.isPropertyAccessExpression(node)) {
|
49 | var propertyName = node.name.text;
|
50 | if (propertyName === 'cookie') {
|
51 | var leftSide = node.expression;
|
52 | try {
|
53 | var leftSideType = typeChecker.getTypeAtLocation(leftSide);
|
54 | var typeAsString = typeChecker.typeToString(leftSideType);
|
55 | if (leftSideType.flags === ts.TypeFlags.Any || typeAsString === 'Document') {
|
56 | ctx.addFailureAt(leftSide.getStart(), leftSide.getWidth(), Rule.FAILURE_STRING);
|
57 | }
|
58 | }
|
59 | catch (e) {
|
60 | if (leftSide.getFullText().trim() === 'document') {
|
61 | ctx.addFailureAt(leftSide.getStart(), leftSide.getWidth(), Rule.FAILURE_STRING);
|
62 | }
|
63 | }
|
64 | }
|
65 | }
|
66 | return ts.forEachChild(node, cb);
|
67 | }
|
68 | return ts.forEachChild(ctx.sourceFile, cb);
|
69 | }
|
70 |
|
\ | No newline at end of file |