Skip to content

Commit

Permalink
Avoid overt usage of Function constructor (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn authored Dec 7, 2021
1 parent 3c28a00 commit a4c3d42
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
8 changes: 7 additions & 1 deletion packages/ts-invariant/process/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ var safeGlobal = (
maybe(function() { return window }) ||
maybe(function() { return self }) ||
maybe(function() { return global }) ||
maybe(function() { return Function("return this")() })
// We don't expect the Function constructor ever to be invoked at runtime, as
// long as at least one of globalThis, window, self, or global is defined, so
// we are under no obligation to make it easy for static analysis tools to
// detect syntactic usage of the Function constructor. If you think you can
// improve your static analysis to detect this obfuscation, think again. This
// is an arms race you cannot win, at least not in JavaScript.
maybe(function() { return maybe.constructor("return this")() })
);

var needToRemove = false;
Expand Down
8 changes: 7 additions & 1 deletion packages/ts-invariant/process/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/ts-invariant/process/main.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a4c3d42

Please sign in to comment.