Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 29f61fb

Browse files
committed
[feat] added metadata for the each rule (#17)
1 parent 1186f3f commit 29f61fb

17 files changed

+205
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Examples: [test/rules/tsr-disable-mustache-escape/default/test.ts.lint](test/rul
8080

8181
#### `tsr-detect-eval-with-expression`
8282

83-
Detects `eval(variable)` which can allow an attacker to run arbitary code inside your process.
83+
Detects `eval(variable)` which can allow an attacker to run arbitrary code inside your process.
8484

8585
More information: http://security.stackexchange.com/questions/94017/what-are-the-security-issues-with-eval-in-javascript
8686

src/rules/tsrDetectBufferNoassertRule.ts

+13
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@ const writeMethods: string[] = [
3636
];
3737

3838
export class Rule extends Lint.Rules.AbstractRule {
39+
static metadata: Lint.IRuleMetadata = {
40+
ruleName: 'tsr-detect-buffer-noassert',
41+
description: 'Warns when Buffer with noAssert flag is used',
42+
descriptionDetails: Lint.Utils.dedent`Any usage of Buffer
43+
with noAssert flag will trigger a warning.
44+
See https://github.com/webschik/tslint-config-security#tsr-detect-buffer-noassert`,
45+
optionsDescription: '',
46+
options: null,
47+
type: 'functionality',
48+
requiresTypeInfo: false,
49+
typescriptOnly: false
50+
};
51+
3952
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
4053
return this.applyWithFunction(sourceFile, walk);
4154
}

src/rules/tsrDetectChildProcessRule.ts

+13
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@ import * as ts from 'typescript';
33
import {stringLiteralKinds} from '../node-kind';
44

55
export class Rule extends Lint.Rules.AbstractRule {
6+
static metadata: Lint.IRuleMetadata = {
7+
ruleName: 'tsr-detect-child-process',
8+
description: 'Warns when child_process.exec() with non-literal first argument is used',
9+
descriptionDetails: Lint.Utils.dedent`Any usage of child_process.exec()
10+
with non-literal first argument will trigger a warning.
11+
See https://github.com/webschik/tslint-config-security#tsr-detect-child-process`,
12+
optionsDescription: '',
13+
options: null,
14+
type: 'functionality',
15+
requiresTypeInfo: false,
16+
typescriptOnly: false
17+
};
18+
619
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
720
return this.applyWithFunction(sourceFile, walk);
821
}

src/rules/tsrDetectEvalWithExpressionRule.ts

+13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ import {stringLiteralKinds} from '../node-kind';
44
import syntaxKindToName from '../syntax-kind-to-name';
55

66
export class Rule extends Lint.Rules.AbstractRule {
7+
static metadata: Lint.IRuleMetadata = {
8+
ruleName: 'tsr-detect-eval-with-expression',
9+
description: 'Warns when eval() with non-literal argument is used',
10+
descriptionDetails: Lint.Utils.dedent`Any usage of eval()
11+
with non-literal argument will trigger a warning.
12+
See https://github.com/webschik/tslint-config-security#tsr-detect-eval-with-expression`,
13+
optionsDescription: '',
14+
options: null,
15+
type: 'functionality',
16+
requiresTypeInfo: false,
17+
typescriptOnly: false
18+
};
19+
720
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
821
return this.applyWithFunction(sourceFile, walk);
922
}

src/rules/tsrDetectHtmlInjectionRule.ts

+13
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@ import * as ts from 'typescript';
33
import {stringLiteralKinds} from '../node-kind';
44

55
export class Rule extends Lint.Rules.AbstractRule {
6+
static metadata: Lint.IRuleMetadata = {
7+
ruleName: 'tsr-detect-html-injection',
8+
description: 'Warns when possible HTML injection is found',
9+
descriptionDetails: Lint.Utils.dedent`Any usage of unsafe DOM APIs as Element.innerHTML or document.write()
10+
will trigger a warning.
11+
See https://github.com/webschik/tslint-config-security#tsr-detect-html-injection`,
12+
optionsDescription: '',
13+
options: null,
14+
type: 'functionality',
15+
requiresTypeInfo: false,
16+
typescriptOnly: false
17+
};
18+
619
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
720
return this.applyWithFunction(sourceFile, walk);
821
}

src/rules/tsrDetectNoCsrfBeforeMethodOverrideRule.ts

+13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@ import * as Lint from 'tslint';
22
import * as ts from 'typescript';
33

44
export class Rule extends Lint.Rules.AbstractRule {
5+
static metadata: Lint.IRuleMetadata = {
6+
ruleName: 'tsr-detect-no-csrf-before-method-override',
7+
description: 'Warns when csrf middleware for Express.js is setup before method-override middleware',
8+
descriptionDetails: Lint.Utils.dedent`Any usage of express.csrf() middleware before
9+
express.methodOverride() will trigger a warning.
10+
See https://github.com/webschik/tslint-config-security#tsr-detect-no-csrf-before-method-override`,
11+
optionsDescription: '',
12+
options: null,
13+
type: 'functionality',
14+
requiresTypeInfo: false,
15+
typescriptOnly: false
16+
};
17+
518
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
619
return this.applyWithFunction(sourceFile, walk);
720
}

src/rules/tsrDetectNonLiteralBufferRule.ts

+13
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@ import * as ts from 'typescript';
33
import {stringLiteralKinds} from '../node-kind';
44

55
export class Rule extends Lint.Rules.AbstractRule {
6+
static metadata: Lint.IRuleMetadata = {
7+
ruleName: 'tsr-detect-non-literal-buffer',
8+
description: 'Warns when Buffer constructor with non-literal argument is used',
9+
descriptionDetails: Lint.Utils.dedent`Any usage of new Buffer()
10+
with non-literal argument will trigger a warning.
11+
See https://github.com/webschik/tslint-config-security#tsr-detect-non-literal-buffer`,
12+
optionsDescription: '',
13+
options: null,
14+
type: 'functionality',
15+
requiresTypeInfo: false,
16+
typescriptOnly: false
17+
};
18+
619
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
720
return this.applyWithFunction(sourceFile, walk);
821
}

src/rules/tsrDetectNonLiteralFsFilenameRule.ts

+13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ import fsModuleMethodsArgumentsInfo from '../fs-module-methods-arguments-info';
44
import {stringLiteralKinds} from '../node-kind';
55

66
export class Rule extends Lint.Rules.AbstractRule {
7+
static metadata: Lint.IRuleMetadata = {
8+
ruleName: 'tsr-detect-non-literal-fs-filename',
9+
description: 'Warns when methods of Node.js FileSystem API are used with non-literal argument as a filename',
10+
descriptionDetails: Lint.Utils.dedent`Any usage of Node.js FileSystem methods
11+
with non-literal argument as a filename will trigger a warning.
12+
See https://github.com/webschik/tslint-config-security#tsr-detect-non-literal-fs-filename`,
13+
optionsDescription: '',
14+
options: null,
15+
type: 'functionality',
16+
requiresTypeInfo: false,
17+
typescriptOnly: false
18+
};
19+
720
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
821
return this.applyWithFunction(sourceFile, walk);
922
}

src/rules/tsrDetectNonLiteralRegexpRule.ts

+13
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@ import * as ts from 'typescript';
33
import {stringLiteralKinds} from '../node-kind';
44

55
export class Rule extends Lint.Rules.AbstractRule {
6+
static metadata: Lint.IRuleMetadata = {
7+
ruleName: 'tsr-detect-non-literal-regexp',
8+
description: 'Warns when RegExp constructor with non-literal argument is used',
9+
descriptionDetails: Lint.Utils.dedent`Any usage of new RegExp()
10+
with non-literal argument will trigger a warning.
11+
See https://github.com/webschik/tslint-config-security#tsr-detect-non-literal-regexp`,
12+
optionsDescription: '',
13+
options: null,
14+
type: 'functionality',
15+
requiresTypeInfo: false,
16+
typescriptOnly: false
17+
};
18+
619
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
720
return this.applyWithFunction(sourceFile, walk);
821
}

src/rules/tsrDetectNonLiteralRequireRule.ts

+13
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@ import * as ts from 'typescript';
33
import {stringLiteralKinds} from '../node-kind';
44

55
export class Rule extends Lint.Rules.AbstractRule {
6+
static metadata: Lint.IRuleMetadata = {
7+
ruleName: 'tsr-detect-non-literal-require',
8+
description: 'Warns when require() function is used with non-literal argument',
9+
descriptionDetails: Lint.Utils.dedent`Any usage of require()
10+
with non-literal argument will trigger a warning.
11+
See https://github.com/webschik/tslint-config-security#tsr-detect-non-literal-require`,
12+
optionsDescription: '',
13+
options: null,
14+
type: 'functionality',
15+
requiresTypeInfo: false,
16+
typescriptOnly: false
17+
};
18+
619
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
720
return this.applyWithFunction(sourceFile, walk);
821
}

src/rules/tsrDetectPossibleTimingAttacksRule.ts

+13
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,19 @@ function isVulnerablePropertyAccessExpression(node: ts.PropertyAccessExpression)
7676
}
7777

7878
export class Rule extends Lint.Rules.AbstractRule {
79+
static metadata: Lint.IRuleMetadata = {
80+
ruleName: 'tsr-detect-possible-timing-attacks',
81+
description: 'Warns when possible timing attack is found',
82+
descriptionDetails: Lint.Utils.dedent`Any usage of unsafe comparisons ('==', '!=', '!==' and '===')
83+
that check input sequentially will trigger a warning.
84+
See https://github.com/webschik/tslint-config-security#tsr-detect-possible-timing-attacks`,
85+
optionsDescription: '',
86+
options: null,
87+
type: 'functionality',
88+
requiresTypeInfo: false,
89+
typescriptOnly: false
90+
};
91+
7992
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
8093
return this.applyWithFunction(sourceFile, walk);
8194
}

src/rules/tsrDetectPseudoRandomBytesRule.ts

+12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@ import * as Lint from 'tslint';
22
import * as ts from 'typescript';
33

44
export class Rule extends Lint.Rules.AbstractRule {
5+
static metadata: Lint.IRuleMetadata = {
6+
ruleName: 'tsr-detect-pseudo-random-bytes',
7+
description: 'Warns when crypto.pseudoRandomBytes() function is used',
8+
descriptionDetails: Lint.Utils.dedent`Any usage of crypto.pseudoRandomBytes() will trigger a warning.
9+
See https://github.com/webschik/tslint-config-security#tsr-detect-pseudo-random-bytes`,
10+
optionsDescription: '',
11+
options: null,
12+
type: 'functionality',
13+
requiresTypeInfo: false,
14+
typescriptOnly: false
15+
};
16+
517
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
618
return this.applyWithFunction(sourceFile, walk);
719
}

src/rules/tsrDetectSqlLiteralInjectionRule.ts

+13
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ import {stringLiteralKinds} from '../node-kind';
66
const generalErrorMessage: string = 'Found possible SQL injection';
77

88
export class Rule extends Lint.Rules.AbstractRule {
9+
static metadata: Lint.IRuleMetadata = {
10+
ruleName: 'tsr-detect-sql-literal-injection',
11+
description: 'Warns when possible SQL injection is found',
12+
descriptionDetails: Lint.Utils.dedent`Any usage of the unsafe string concatenation in SQL queries
13+
will trigger a warning.
14+
See https://github.com/webschik/tslint-config-security#tsr-detect-sql-literal-injection`,
15+
optionsDescription: '',
16+
options: null,
17+
type: 'functionality',
18+
requiresTypeInfo: false,
19+
typescriptOnly: false
20+
};
21+
922
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
1023
return this.applyWithFunction(sourceFile, walk);
1124
}

src/rules/tsrDetectUnsafeCrossOriginCommunicationRule.ts

+12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@ import * as Lint from 'tslint';
22
import * as ts from 'typescript';
33

44
export class Rule extends Lint.Rules.AbstractRule {
5+
static metadata: Lint.IRuleMetadata = {
6+
ruleName: 'tsr-detect-unsafe-cross-origin-communication',
7+
description: 'Warns when postMessage() API is used with the target "*" (no preference)',
8+
descriptionDetails: Lint.Utils.dedent`Any usage of postMessage() API with target "*" will trigger a warning.
9+
See https://github.com/webschik/tslint-config-security#tsr-detect-unsafe-cross-origin-communication`,
10+
optionsDescription: '',
11+
options: null,
12+
type: 'functionality',
13+
requiresTypeInfo: false,
14+
typescriptOnly: false
15+
};
16+
517
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
618
return this.applyWithFunction(sourceFile, walk);
719
}

src/rules/tsrDetectUnsafePropertiesAccessRule.ts

+13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@ import * as Lint from 'tslint';
22
import * as ts from 'typescript';
33

44
export class Rule extends Lint.Rules.AbstractRule {
5+
static metadata: Lint.IRuleMetadata = {
6+
ruleName: 'tsr-detect-unsafe-properties-access',
7+
description: 'Warns when potential unsafe access to the object properties is found',
8+
descriptionDetails: Lint.Utils.dedent`Any potential unsafe access to the object properties
9+
will trigger a warning.
10+
See https://github.com/webschik/tslint-config-security#tsr-detect-unsafe-properties-access`,
11+
optionsDescription: '',
12+
options: null,
13+
type: 'functionality',
14+
requiresTypeInfo: false,
15+
typescriptOnly: false
16+
};
17+
518
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
619
return this.applyWithFunction(sourceFile, walk);
720
}

src/rules/tsrDetectUnsafeRegexpRule.ts

+12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ import * as ts from 'typescript';
55
import {stringLiteralKinds} from '../node-kind';
66

77
export class Rule extends Lint.Rules.AbstractRule {
8+
static metadata: Lint.IRuleMetadata = {
9+
ruleName: 'tsr-detect-unsafe-regexp',
10+
description: 'Warns when potential unsafe regular expression is found',
11+
descriptionDetails: Lint.Utils.dedent`Any usage of potential unsafe regular expression will trigger a warning.
12+
See https://github.com/webschik/tslint-config-security#tsr-detect-unsafe-regexp`,
13+
optionsDescription: '',
14+
options: null,
15+
type: 'functionality',
16+
requiresTypeInfo: false,
17+
typescriptOnly: false
18+
};
19+
820
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
921
return this.applyWithFunction(sourceFile, walk);
1022
}

src/rules/tsrDisableMustacheEscapeRule.ts

+12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@ import * as Lint from 'tslint';
22
import * as ts from 'typescript';
33

44
export class Rule extends Lint.Rules.AbstractRule {
5+
static metadata: Lint.IRuleMetadata = {
6+
ruleName: 'tsr-disable-mustache-escape',
7+
description: 'Warns when escapeMarkup=false property with some template engines is used',
8+
descriptionDetails: Lint.Utils.dedent`Any usage of escapeMarkup=false property will trigger a warning.
9+
See https://github.com/webschik/tslint-config-security#tsr-disable-mustache-escape`,
10+
optionsDescription: '',
11+
options: null,
12+
type: 'functionality',
13+
requiresTypeInfo: false,
14+
typescriptOnly: false
15+
};
16+
517
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
618
return this.applyWithFunction(sourceFile, walk);
719
}

0 commit comments

Comments
 (0)