Skip to content

Commit 0a5e820

Browse files
committed
chore: fs lib overwrite protection
1 parent 49b486a commit 0a5e820

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/phoenix/init_vfs.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,27 @@ const _createAppDirs = async function () {
288288
};
289289

290290

291+
const CORE_LIB_GUARD_INTERVAL = 5000;
291292
const _FS_ERROR_MESSAGE = 'Oops. Phoenix could not be started due to missing file system library.';
292293
export default function initVFS() {
293294
if(!window.fs || !window.path || !window.Phoenix){
294295
window.alert(_FS_ERROR_MESSAGE);
295296
throw new Error(_FS_ERROR_MESSAGE);
296297
}
298+
const savedfs = window.fs, savedPath = window.path;
299+
setInterval(()=>{
300+
if(window.fs !== savedfs){
301+
console.error("window.fs overwrite detected!! Some extension may have corrupted this." +
302+
" attempting to revert to original lib.");
303+
window.fs=savedfs;
304+
}
305+
if(window.path !== savedPath){
306+
console.error("window.path overwrite detected!! Some extension may have corrupted this." +
307+
" attempting to revert to original lib.");
308+
window.path=savedPath;
309+
}
310+
311+
}, CORE_LIB_GUARD_INTERVAL);
297312

298313
_setupVFS(window.fs, window.path);
299314
window._phoenixfsAppDirsCreatePromise = _createAppDirs();

src/utils/ExtensionLoader.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ define(function (require, exports, module) {
207207
}
208208
throw new Error("Config can only be loaded from an http url, but got" + baseConfig.baseUrl);
209209
}
210+
const savedFSlib = window.fs;
210211

211212
/**
212213
* Loads the extension module that lives at baseUrl into its own Require.js context
@@ -250,6 +251,13 @@ define(function (require, exports, module) {
250251
return extensionRequireDeferred.promise();
251252
}).then(function (module) {
252253
// Extension loaded normally
254+
if(savedFSlib !== window.fs) {
255+
console.error("fslib overwrite detected while loading extension. This means that" +
256+
" some extension tried to modify a core library. reverting to original lib..");
257+
// note that the extension name here may not be that actual extension that did the
258+
// overwrite. So we dont log the extension name here.
259+
window.fs = savedFSlib;
260+
}
253261
var initPromise;
254262

255263
_extensions[name] = module;

0 commit comments

Comments
 (0)