Skip to content

Commit 05435cd

Browse files
author
Ksenia Peguero
committed
structure cleanup
1 parent 61d0c48 commit 05435cd

10 files changed

+195
-13
lines changed

.gitignore

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
# See http://help.github.com/ignore-files/ for more about ignoring files.
22

33
# compiled output
4-
# for this project we do need the compiled version of the rules
5-
# /dist
6-
/tmp
7-
/rules
4+
# for this project we do not need the compiled version of the rules
5+
.js
86

97
# dependencies
108
/node_modules

.npmignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
/src
21
/node_modules
32
.gitignore
43
package.json
54
tsconfig.json
6-
tslint.json
5+
tslint.json

flagLocalStorageAngularPluginRule.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
"use strict";
2+
// Copyright (c) 2018 Synopsys, Inc. All rights reserved worldwide.
3+
/* The rule flags access to localStorage or web storage when Angular2+ app is used
4+
* with plugins:
5+
* - @ngx-pwa/local-storage
6+
* - angular-webstorage-service
7+
* Note that angular-webstorage-service is configured at the constuctor to use either
8+
* LOCAL_STORAGE or SESSION_STORAGE. This rule does not take this into account and
9+
* may return false positives.
10+
*/
11+
var __extends = (this && this.__extends) || (function () {
12+
var extendStatics = function (d, b) {
13+
extendStatics = Object.setPrototypeOf ||
14+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
15+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
16+
return extendStatics(d, b);
17+
}
18+
return function (d, b) {
19+
extendStatics(d, b);
20+
function __() { this.constructor = d; }
21+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
22+
};
23+
})();
24+
Object.defineProperty(exports, "__esModule", { value: true });
25+
var Lint = require("tslint");
26+
var Rule = /** @class */ (function (_super) {
27+
__extends(Rule, _super);
28+
function Rule() {
29+
return _super !== null && _super.apply(this, arguments) || this;
30+
}
31+
Rule.prototype.apply = function (sourceFile) {
32+
return this.applyWithWalker(new FlagLocalStoragePluginWalker(sourceFile, this.getOptions()));
33+
};
34+
Rule.FAILURE_STRING = "Validate that sensitive data is not written to localStorage via plugins ";
35+
Rule.metadata = {
36+
ruleName: 'flag-local-storage-angular-plugin',
37+
type: 'functionality',
38+
description: 'Sensitive data stored in localStorage may be leaked to an attacker',
39+
options: null,
40+
optionsDescription: '',
41+
typescriptOnly: true,
42+
};
43+
return Rule;
44+
}(Lint.Rules.AbstractRule));
45+
exports.Rule = Rule;
46+
var FlagLocalStoragePluginWalker = /** @class */ (function (_super) {
47+
__extends(FlagLocalStoragePluginWalker, _super);
48+
function FlagLocalStoragePluginWalker() {
49+
return _super !== null && _super.apply(this, arguments) || this;
50+
}
51+
FlagLocalStoragePluginWalker.prototype.visitPropertyAccessExpression = function (node) {
52+
//check for @ngx-pwa/local-storage plugn API
53+
if (node.expression.getText() === 'this.localStorage'
54+
&& node.name.text === 'setItem') {
55+
this.addFailureAt(node.getStart(), node.getWidth(), Rule.FAILURE_STRING);
56+
}
57+
//check for angular-webstorage-service plugin API
58+
if (node.expression.getText() === 'this.storage'
59+
&& node.name.text === 'set') {
60+
this.addFailureAt(node.getStart(), node.getWidth(), Rule.FAILURE_STRING);
61+
}
62+
// call the base version of this visitor to actually parse this node
63+
_super.prototype.visitPropertyAccessExpression.call(this, node);
64+
};
65+
return FlagLocalStoragePluginWalker;
66+
}(Lint.RuleWalker));

index.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

noBypassSecurityRule.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
"use strict";
2+
// Copyright (c) 2018 Synopsys, Inc. All rights reserved worldwide.
3+
/* The rule flags any call to Angular APIs bypassSecurityTrust*, which
4+
* when called on tainted data may result in untrusted data written into the DOM
5+
* which may lead to XSS.
6+
*/
7+
var __extends = (this && this.__extends) || (function () {
8+
var extendStatics = function (d, b) {
9+
extendStatics = Object.setPrototypeOf ||
10+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
11+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
12+
return extendStatics(d, b);
13+
}
14+
return function (d, b) {
15+
extendStatics(d, b);
16+
function __() { this.constructor = d; }
17+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
18+
};
19+
})();
20+
Object.defineProperty(exports, "__esModule", { value: true });
21+
var Lint = require("tslint");
22+
var Rule = /** @class */ (function (_super) {
23+
__extends(Rule, _super);
24+
function Rule() {
25+
return _super !== null && _super.apply(this, arguments) || this;
26+
}
27+
Rule.prototype.apply = function (sourceFile) {
28+
return this.applyWithWalker(new NoBypassSecurityWalker(sourceFile, this.getOptions()));
29+
};
30+
Rule.FAILURE_STRING = "Untrusted data sent to bypassSecurityTrust* methods may result in XSS";
31+
Rule.metadata = {
32+
ruleName: 'no-bypass-security',
33+
type: 'functionality',
34+
description: 'Angular bypassSecurityTrust* methods may lead to XSS and other attacks',
35+
options: null,
36+
optionsDescription: '',
37+
typescriptOnly: true,
38+
};
39+
return Rule;
40+
}(Lint.Rules.AbstractRule));
41+
exports.Rule = Rule;
42+
var NoBypassSecurityWalker = /** @class */ (function (_super) {
43+
__extends(NoBypassSecurityWalker, _super);
44+
function NoBypassSecurityWalker() {
45+
return _super !== null && _super.apply(this, arguments) || this;
46+
}
47+
NoBypassSecurityWalker.prototype.visitPropertyAccessExpression = function (node) {
48+
if (node.name.text === 'bypassSecurityTrustHtml'
49+
|| node.name.text === 'bypassSecurityTrustStyle'
50+
|| node.name.text === 'bypassSecurityTrustScript'
51+
|| node.name.text === 'bypassSecurityTrustUrl'
52+
|| node.name.text === 'bypassSecurityTrustResourceUrl')
53+
// create a failure at the current position
54+
this.addFailureAt(node.getStart(), node.getWidth(), Rule.FAILURE_STRING);
55+
// call the base version of this visitor to actually parse this node
56+
_super.prototype.visitPropertyAccessExpression.call(this, node);
57+
};
58+
return NoBypassSecurityWalker;
59+
}(Lint.RuleWalker));
File renamed without changes.

noElementReferenceRule.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
"use strict";
2+
// Copyright (c) 2018 Synopsys, Inc. All rights reserved worldwide.
3+
/* The rule flags any references to nativeElement, when DOM-modifying attributes or functions,
4+
* such as innerHTML, outerHTML, querySelector are called on it. The nativeElement property
5+
* allows access to the underlying DOM element.
6+
*/
7+
var __extends = (this && this.__extends) || (function () {
8+
var extendStatics = function (d, b) {
9+
extendStatics = Object.setPrototypeOf ||
10+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
11+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
12+
return extendStatics(d, b);
13+
}
14+
return function (d, b) {
15+
extendStatics(d, b);
16+
function __() { this.constructor = d; }
17+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
18+
};
19+
})();
20+
Object.defineProperty(exports, "__esModule", { value: true });
21+
var Lint = require("tslint");
22+
var Rule = /** @class */ (function (_super) {
23+
__extends(Rule, _super);
24+
function Rule() {
25+
return _super !== null && _super.apply(this, arguments) || this;
26+
}
27+
Rule.prototype.apply = function (sourceFile) {
28+
return this.applyWithWalker(new NoElementReferenceWalker(sourceFile, this.getOptions()));
29+
};
30+
Rule.FAILURE_STRING_INNER = "Forbid writing innerHTML directly through element reference";
31+
Rule.FAILURE_STRING_OUTER = "Forbid writing outerHTML directly through element reference";
32+
Rule.FAILURE_STRING_QUERY = "Validate no tainted data is written to the element accessed directly through querySelector";
33+
Rule.metadata = {
34+
ruleName: 'no-element-reference',
35+
type: 'functionality',
36+
description: 'Directly manipulating innerHTML or outerHTML of the DOM element may lead to XSS',
37+
options: null,
38+
optionsDescription: '',
39+
typescriptOnly: true,
40+
};
41+
return Rule;
42+
}(Lint.Rules.AbstractRule));
43+
exports.Rule = Rule;
44+
// The walker takes care of all the work.
45+
var NoElementReferenceWalker = /** @class */ (function (_super) {
46+
__extends(NoElementReferenceWalker, _super);
47+
function NoElementReferenceWalker() {
48+
return _super !== null && _super.apply(this, arguments) || this;
49+
}
50+
NoElementReferenceWalker.prototype.visitPropertyAccessExpression = function (node) {
51+
if (node.getText().includes('nativeElement')) {
52+
if (node.name.text === 'innerHTML') {
53+
this.addFailureAt(node.getStart(), node.getWidth(), Rule.FAILURE_STRING_INNER);
54+
}
55+
else if (node.name.text === 'outerHTML') {
56+
this.addFailureAt(node.getStart(), node.getWidth(), Rule.FAILURE_STRING_OUTER);
57+
}
58+
else if (node.name.text === 'querySelector') {
59+
this.addFailureAt(node.getStart(), node.getWidth(), Rule.FAILURE_STRING_QUERY);
60+
}
61+
}
62+
// call the base version of this visitor to actually parse this node
63+
_super.prototype.visitPropertyAccessExpression.call(this, node);
64+
};
65+
return NoElementReferenceWalker;
66+
}(Lint.RuleWalker));
File renamed without changes.

tsconfig.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
{
22
"compileOnSave": false,
33
"compilerOptions": {
4-
"outDir": "./rules",
54
"sourceMap": false,
6-
"declaration": true,
75
"target": "es5",
86
"skipLibCheck": true,
97
"lib": [
@@ -12,6 +10,6 @@
1210
]
1311
},
1412
"include": [
15-
"src"
13+
"."
1614
]
1715
}

0 commit comments

Comments
 (0)