UNPKG

3.73 kBJavaScriptView Raw
1/*
2 * Copyright (C) 2016 salesforce.com, inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 "use strict";
18
19var util = require('../lib/util.js');
20var objectAssign = require('object-assign');
21
22var 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
67module.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 // ignoring intermediate member expressions
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 // nothing to do here, it was shadowed by the user
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
116module.exports.schema = [];