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

Commit fcc02dd

Browse files
committed
[feat] added tsr-detect-unsafe-properties-access rule; optimized imports in source files
1 parent c4391f1 commit fcc02dd

21 files changed

+91
-19
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ By default `tslint-config-security` enables [all rules](#rules), but you may dis
3131
"tsr-detect-html-injection": false,
3232
"tsr-detect-unsafe-regexp": false
3333
}
34+
}
3435
```
3536

3637

@@ -209,3 +210,34 @@ const myWindow = document.getElementById('myIFrame').contentWindow;
209210

210211
myWindow.postMessage(message, "*"); // Noncompliant
211212
```
213+
214+
#### tsr-detect-unsafe-properties-access
215+
216+
Detects a potential unsafe access to the object properties
217+
218+
```js
219+
/*
220+
221+
It equals to `new Function(prop3)`
222+
223+
const a = {};
224+
225+
a["constructor"]["constructor"]("alert(1)")()
226+
*/
227+
228+
// unsafe
229+
obj[prop1][prop2](prop3)
230+
231+
// unsafe
232+
obj[prop1][prop2](prop3)()
233+
234+
```
235+
236+
More information:
237+
* [Web Puzzlers - Securing Dynamic Systems](https://youtu.be/SkNWAjDRLDY)
238+
* [Defensive JavaScript](https://www.javascriptjanuary.com/blog/defensive-javascript)
239+
240+
Solutions:
241+
* use [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
242+
* use `.hasOwnProperty` check
243+
* use `Content-Security-Policy` on your page

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module.exports = {
1515
'tsr-disable-mustache-escape': [true],
1616
'tsr-detect-html-injection': [true],
1717
'tsr-detect-sql-literal-injection': [true],
18-
'tsr-detect-unsafe-cross-origin-communication': [true]
18+
'tsr-detect-unsafe-cross-origin-communication': [true],
19+
'tsr-detect-unsafe-properties-access': [true]
1920
}
2021
};

npm-shrinkwrap.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tslint-config-security",
3-
"version": "1.14.0",
3+
"version": "1.15.0",
44
"description": "TSLint security rules",
55
"main": "./index.js",
66
"files": [

src/rules/tsrDetectBufferNoassertRule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as ts from 'typescript';
21
import * as Lint from 'tslint';
2+
import * as ts from 'typescript';
33

44
const readMethods: string[] = [
55
'readUInt8',

src/rules/tsrDetectChildProcessRule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as ts from 'typescript';
21
import * as Lint from 'tslint';
2+
import * as ts from 'typescript';
33
import {StringLiteral, stringLiteralKinds} from '../node-kind';
44

55
export class Rule extends Lint.Rules.AbstractRule {

src/rules/tsrDetectEvalWithExpressionRule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as ts from 'typescript';
21
import * as Lint from 'tslint';
2+
import * as ts from 'typescript';
33
import {stringLiteralKinds} from '../node-kind';
44
import syntaxKindToName from '../syntax-kind-to-name';
55

src/rules/tsrDetectHtmlInjectionRule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as ts from 'typescript';
21
import * as Lint from 'tslint';
2+
import * as ts from 'typescript';
33
import {stringLiteralKinds} from '../node-kind';
44

55
export class Rule extends Lint.Rules.AbstractRule {

src/rules/tsrDetectNoCsrfBeforeMethodOverrideRule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as ts from 'typescript';
21
import * as Lint from 'tslint';
2+
import * as ts from 'typescript';
33

44
export class Rule extends Lint.Rules.AbstractRule {
55
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {

src/rules/tsrDetectNonLiteralBufferRule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as ts from 'typescript';
21
import * as Lint from 'tslint';
2+
import * as ts from 'typescript';
33
import {stringLiteralKinds} from '../node-kind';
44

55
export class Rule extends Lint.Rules.AbstractRule {

0 commit comments

Comments
 (0)