Skip to content

Commit 6133bd2

Browse files
committed
impr: block Math.random from simple reassignments at runtime
!nuf
1 parent e4a102a commit 6133bd2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

frontend/src/ts/index.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,25 @@ import { getDevOptionsModal } from "./utils/async-modules";
4949
import * as Sentry from "./sentry";
5050
import * as Cookies from "./cookies";
5151

52+
// Lock Math.random
53+
Object.defineProperty(Math, "random", {
54+
value: Math.random,
55+
writable: false,
56+
configurable: false,
57+
enumerable: true,
58+
});
59+
60+
// Freeze Math object
61+
Object.freeze(Math);
62+
63+
// Lock Math on window
64+
Object.defineProperty(window, "Math", {
65+
value: Math,
66+
writable: false,
67+
configurable: false,
68+
enumerable: true,
69+
});
70+
5271
function addToGlobal(items: Record<string, unknown>): void {
5372
for (const [name, item] of Object.entries(items)) {
5473
//@ts-expect-error dev

0 commit comments

Comments
 (0)