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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 13 additions & 0 deletions
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

Lines changed: 13 additions & 0 deletions
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

Lines changed: 13 additions & 0 deletions
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

Lines changed: 13 additions & 0 deletions
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

Lines changed: 13 additions & 0 deletions
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

Lines changed: 13 additions & 0 deletions
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

Lines changed: 13 additions & 0 deletions
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

Lines changed: 13 additions & 0 deletions
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

Lines changed: 13 additions & 0 deletions
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
}

0 commit comments

Comments
 (0)