MISC: Protect against reassigning certain globals (#972)

This commit is contained in:
Snarling 2023-12-16 05:03:52 -05:00 committed by GitHub
parent da1b8533e0
commit 97d679bdac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 15 additions and 4 deletions

@ -10,12 +10,13 @@ module.exports = {
moduleNameMapper: { moduleNameMapper: {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
"<rootDir>/test/__mocks__/fileMock.js", "<rootDir>/test/__mocks__/fileMock.js",
"\\.(css|less)$": "<rootDir>/test/__mocks__/styleMock.js", "\\.(css|less)$": "<rootDir>/test/__mocks__/NullMock.js",
"\\!!raw-loader!.*$": "<rootDir>/test/__mocks__/rawLoader.js", "\\!!raw-loader!.*$": "<rootDir>/test/__mocks__/NullMock.js",
"@player": "<rootDir>/src/Player", "@player": "<rootDir>/src/Player",
"@enums": "<rootDir>/src/Enums", "@enums": "<rootDir>/src/Enums",
"@nsdefs": "<rootDir>/src/ScriptEditor/NetscriptDefinitions", "@nsdefs": "<rootDir>/src/ScriptEditor/NetscriptDefinitions",
"^monaco-editor$": "<rootDir>/test/__mocks__/monacoMock.js", "^monaco-editor$": "<rootDir>/test/__mocks__/NullMock.js",
"^monaco-vim$": "<rootDir>/test/__mocks__/monacoMock.js", "^monaco-vim$": "<rootDir>/test/__mocks__/NullMock.js",
"/utils/Protections$": "<rootDir>/test/__mocks__/NullMock.js",
}, },
}; };

@ -9,6 +9,7 @@ import { staneksGift } from "./CotMG/Helper";
import { processPassiveFactionRepGain, inviteToFaction } from "./Faction/FactionHelpers"; import { processPassiveFactionRepGain, inviteToFaction } from "./Faction/FactionHelpers";
import { Router } from "./ui/GameRoot"; import { Router } from "./ui/GameRoot";
import { Page } from "./ui/Router"; import { Page } from "./ui/Router";
import "./utils/Protections"; // Side-effect: Protect against certain unrecoverable errors
import "./PersonObjects/Player/PlayerObject"; // For side-effect of creating Player import "./PersonObjects/Player/PlayerObject"; // For side-effect of creating Player
import { import {

9
src/utils/Protections.ts Normal file

@ -0,0 +1,9 @@
// This file is imported for side effects only.
/* Prevent inadvertantly redefining certain window properties,
which are known to cause unrecoverable game errors when redefined.
The player is able to redefine these properties as writable if desired. */
Object.defineProperties(window, {
Number: { writable: false },
Object: { writable: false },
String: { writable: false },
});