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 Utils_1 = require("./utils/Utils");
|
20 | var 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.applyWithFunction(sourceFile, walk, parseOptions(this.getOptions()));
|
27 | };
|
28 | Rule.metadata = {
|
29 | ruleName: 'no-http-string',
|
30 | type: 'maintainability',
|
31 | description: "Do not use strings that start with 'http:'. URL strings should start with 'https:'. ",
|
32 | options: null,
|
33 | optionsDescription: '',
|
34 | typescriptOnly: true,
|
35 | issueClass: 'SDL',
|
36 | issueType: 'Error',
|
37 | severity: 'Critical',
|
38 | level: 'Mandatory',
|
39 | group: 'Security',
|
40 | recommendation: '[true, "http://www.example.com/?.*", "http://localhost:?.*"]',
|
41 | commonWeaknessEnumeration: '319'
|
42 | };
|
43 | Rule.FAILURE_STRING = 'Forbidden http url in string: ';
|
44 | return Rule;
|
45 | }(Lint.Rules.AbstractRule));
|
46 | exports.Rule = Rule;
|
47 | function parseOptions(options) {
|
48 | var value;
|
49 | if (options.ruleArguments instanceof Array) {
|
50 | value = options.ruleArguments;
|
51 | }
|
52 | else if (options instanceof Array) {
|
53 | value = options;
|
54 | }
|
55 | return {
|
56 | allExceptions: value
|
57 | };
|
58 | }
|
59 | function walk(ctx) {
|
60 | function cb(node) {
|
61 | if (tsutils.isTextualLiteral(node)) {
|
62 | visitLiteralExpression(node);
|
63 | }
|
64 | else if (node.kind === ts.SyntaxKind.TemplateHead) {
|
65 | visitLiteralExpression(node);
|
66 | }
|
67 | return ts.forEachChild(node, cb);
|
68 | }
|
69 | return ts.forEachChild(ctx.sourceFile, cb);
|
70 | function visitLiteralExpression(node) {
|
71 | var stringText = node.text;
|
72 | if (stringText.indexOf('http:') === 0) {
|
73 | if (!isSuppressed(stringText)) {
|
74 | var failureString = Rule.FAILURE_STRING + "'" + stringText + "'";
|
75 | ctx.addFailureAt(node.getStart(), node.getWidth(), failureString);
|
76 | }
|
77 | }
|
78 | }
|
79 | function isSuppressed(stringText) {
|
80 | var allExceptions = ctx.options.allExceptions;
|
81 | return Utils_1.Utils.exists(allExceptions, function (exception) {
|
82 | return new RegExp(exception).test(stringText);
|
83 | });
|
84 | }
|
85 | }
|
86 |
|
\ | No newline at end of file |