1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | "use strict";
|
18 |
|
19 | var util = require('../lib/util.js');
|
20 | var objectAssign = require('object-assign');
|
21 |
|
22 | var globalBlackList = {
|
23 | setImmediate: true,
|
24 | MutationEvent: true,
|
25 | ServiceWorker: true,
|
26 | ServiceWorkerContainer: true,
|
27 | ServiceWorkerMessageEvent: true,
|
28 | ServiceWorkerRegistration: true,
|
29 | ShadowRoot: true,
|
30 | SharedWorker: true,
|
31 | WebKitMutationObserver: true,
|
32 | clientInformation: true,
|
33 | eval: true,
|
34 | onwebkitanimationend: true,
|
35 | onwebkitanimationiteration: true,
|
36 | onwebkitanimationstart: true,
|
37 | onwebkittransitionend: true,
|
38 | opener: true,
|
39 | top: true,
|
40 | webkitAudioContext: true,
|
41 | webkitCancelAnimationFrame: true,
|
42 | webkitCancelRequestAnimationFrame: true,
|
43 | webkitIDBCursor: true,
|
44 | webkitIDBDatabase: true,
|
45 | webkitIDBFactory: true,
|
46 | webkitIDBIndex: true,
|
47 | webkitIDBKeyRange: true,
|
48 | webkitIDBObjectStore: true,
|
49 | webkitIDBRequest: true,
|
50 | webkitIDBTransaction: true,
|
51 | webkitIndexedDB: true,
|
52 | webkitMediaStream: true,
|
53 | webkitOfflineAudioContext: true,
|
54 | webkitRTCPeerConnection: true,
|
55 | webkitRequestAnimationFrame: true,
|
56 | webkitRequestFileSystem: true,
|
57 | webkitResolveLocalFileSystemURL: true,
|
58 | webkitSpeechGrammar: true,
|
59 | webkitSpeechGrammarList: true,
|
60 | webkitSpeechRecognition: true,
|
61 | webkitSpeechRecognitionError: true,
|
62 | webkitSpeechRecognitionEvent: true,
|
63 | webkitStorageInfo: true,
|
64 | webkitURL: true
|
65 | };
|
66 |
|
67 | module.exports = function(context) {
|
68 | var globalScope;
|
69 |
|
70 | return {
|
71 |
|
72 | Program: function() {
|
73 | globalScope = context.getScope();
|
74 | },
|
75 |
|
76 | CallExpression: function(node) {
|
77 | var callee = node.callee,
|
78 | currentScope = context.getScope();
|
79 |
|
80 | if (callee.type === "Identifier") {
|
81 | if (!util.isShadowed(currentScope, globalScope, callee)) {
|
82 | if (globalBlackList[callee.name]) {
|
83 | context.report(node, "Invalid SecureWindow API, " + callee.name + " was blacklisted");
|
84 | }
|
85 | }
|
86 | }
|
87 | },
|
88 |
|
89 | MemberExpression: function(node) {
|
90 | if (node.parent.type === "MemberExpression") {
|
91 |
|
92 | return;
|
93 | }
|
94 | var currentScope = context.getScope();
|
95 | var ns = util.buildMemberExpressionNamespace(currentScope, globalScope, node);
|
96 | if (ns.length > 0) {
|
97 | var rootIdentifier = ns[0];
|
98 | var name = rootIdentifier.name;
|
99 | if (rootIdentifier.type === "Literal") {
|
100 | name = rootIdentifier.value;
|
101 | }
|
102 | if (util.isShadowed(currentScope, globalScope, rootIdentifier)) {
|
103 |
|
104 | return;
|
105 | }
|
106 | if (globalBlackList[name]) {
|
107 | context.report(node, "Invalid SecureWindow API, " + name + " was blacklisted");
|
108 | return;
|
109 | }
|
110 | }
|
111 | }
|
112 | };
|
113 |
|
114 | };
|
115 |
|
116 | module.exports.schema = [];
|