Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fs lib overwrite protection #1191

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/phoenix/init_vfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,27 @@ const _createAppDirs = async function () {
};


const CORE_LIB_GUARD_INTERVAL = 5000;
const _FS_ERROR_MESSAGE = 'Oops. Phoenix could not be started due to missing file system library.';
export default function initVFS() {
if(!window.fs || !window.path || !window.Phoenix){
window.alert(_FS_ERROR_MESSAGE);
throw new Error(_FS_ERROR_MESSAGE);
}
const savedfs = window.fs, savedPath = window.path;
setInterval(()=>{
if(window.fs !== savedfs){
console.error("window.fs overwrite detected!! Some extension may have corrupted this." +
" attempting to revert to original lib.");
window.fs=savedfs;
}
if(window.path !== savedPath){
console.error("window.path overwrite detected!! Some extension may have corrupted this." +
" attempting to revert to original lib.");
window.path=savedPath;
}

}, CORE_LIB_GUARD_INTERVAL);

_setupVFS(window.fs, window.path);
window._phoenixfsAppDirsCreatePromise = _createAppDirs();
Expand Down
8 changes: 8 additions & 0 deletions src/utils/ExtensionLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ define(function (require, exports, module) {
}
throw new Error("Config can only be loaded from an http url, but got" + baseConfig.baseUrl);
}
const savedFSlib = window.fs;

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

_extensions[name] = module;
Expand Down
Loading