Skip to content

Commit 6d86a52

Browse files
authored
Obfuscate Function(...) fallback to thwart static misanalysis (#9164)
1 parent 1bd1179 commit 6d86a52

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

package-lock.json

Lines changed: 7 additions & 7 deletions
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
@@ -85,7 +85,7 @@
8585
"optimism": "^0.16.1",
8686
"prop-types": "^15.7.2",
8787
"symbol-observable": "^4.0.0",
88-
"ts-invariant": "^0.9.0",
88+
"ts-invariant": "^0.9.4",
8989
"tslib": "^2.3.0",
9090
"zen-observable-ts": "^1.2.0"
9191
},

src/utilities/globals/global.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ export default (
99
maybe(() => window) ||
1010
maybe(() => self) ||
1111
maybe(() => global) ||
12-
maybe(() => Function("return this")())
12+
// We don't expect the Function constructor ever to be invoked at runtime, as
13+
// long as at least one of globalThis, window, self, or global is defined, so
14+
// we are under no obligation to make it easy for static analysis tools to
15+
// detect syntactic usage of the Function constructor. If you think you can
16+
// improve your static analysis to detect this obfuscation, think again. This
17+
// is an arms race you cannot win, at least not in JavaScript.
18+
maybe(function() { return maybe.constructor("return this")() })
1319
) as typeof globalThis & {
1420
__DEV__: typeof __DEV__;
1521
};

0 commit comments

Comments
 (0)