fix: ensure app load is limited to real asar files when appropriate (#39788)
This commit is contained in:
parent
ac040bf734
commit
16aec702b4
4 changed files with 20 additions and 1 deletions
|
@ -27,7 +27,7 @@ const cachedArchives = new Map<string, NodeJS.AsarArchive>();
|
||||||
const getOrCreateArchive = (archivePath: string) => {
|
const getOrCreateArchive = (archivePath: string) => {
|
||||||
const isCached = cachedArchives.has(archivePath);
|
const isCached = cachedArchives.has(archivePath);
|
||||||
if (isCached) {
|
if (isCached) {
|
||||||
return cachedArchives.get(archivePath);
|
return cachedArchives.get(archivePath)!;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -39,6 +39,8 @@ const getOrCreateArchive = (archivePath: string) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
process._getOrCreateArchive = getOrCreateArchive;
|
||||||
|
|
||||||
const asarRe = /\.asar/i;
|
const asarRe = /\.asar/i;
|
||||||
|
|
||||||
const { getValidatedPath } = __non_webpack_require__('internal/fs/utils');
|
const { getValidatedPath } = __non_webpack_require__('internal/fs/utils');
|
||||||
|
|
|
@ -84,11 +84,20 @@ const v8Util = process._linkedBinding('electron_common_v8_util');
|
||||||
let packagePath = null;
|
let packagePath = null;
|
||||||
let packageJson = null;
|
let packageJson = null;
|
||||||
const searchPaths: string[] = v8Util.getHiddenValue(global, 'appSearchPaths');
|
const searchPaths: string[] = v8Util.getHiddenValue(global, 'appSearchPaths');
|
||||||
|
const searchPathsOnlyLoadASAR: boolean = v8Util.getHiddenValue(global, 'appSearchPathsOnlyLoadASAR');
|
||||||
|
// Borrow the _getOrCreateArchive asar helper
|
||||||
|
const getOrCreateArchive = process._getOrCreateArchive;
|
||||||
|
delete process._getOrCreateArchive;
|
||||||
|
|
||||||
if (process.resourcesPath) {
|
if (process.resourcesPath) {
|
||||||
for (packagePath of searchPaths) {
|
for (packagePath of searchPaths) {
|
||||||
try {
|
try {
|
||||||
packagePath = path.join(process.resourcesPath, packagePath);
|
packagePath = path.join(process.resourcesPath, packagePath);
|
||||||
|
if (searchPathsOnlyLoadASAR) {
|
||||||
|
if (!getOrCreateArchive?.(packagePath)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
packageJson = Module._load(path.join(packagePath, 'package.json'));
|
packageJson = Module._load(path.join(packagePath, 'package.json'));
|
||||||
break;
|
break;
|
||||||
} catch {
|
} catch {
|
||||||
|
|
|
@ -586,6 +586,13 @@ std::shared_ptr<node::Environment> NodeBindings::CreateEnvironment(
|
||||||
electron::fuses::IsOnlyLoadAppFromAsarEnabled()
|
electron::fuses::IsOnlyLoadAppFromAsarEnabled()
|
||||||
? app_asar_search_paths
|
? app_asar_search_paths
|
||||||
: search_paths));
|
: search_paths));
|
||||||
|
context->Global()->SetPrivate(
|
||||||
|
context,
|
||||||
|
v8::Private::ForApi(
|
||||||
|
isolate, gin::ConvertToV8(isolate, "appSearchPathsOnlyLoadASAR")
|
||||||
|
.As<v8::String>()),
|
||||||
|
gin::ConvertToV8(isolate,
|
||||||
|
electron::fuses::IsOnlyLoadAppFromAsarEnabled()));
|
||||||
}
|
}
|
||||||
|
|
||||||
base::FilePath resources_path = GetResourcesPath();
|
base::FilePath resources_path = GetResourcesPath();
|
||||||
|
|
1
typings/internal-ambient.d.ts
vendored
1
typings/internal-ambient.d.ts
vendored
|
@ -254,6 +254,7 @@ declare namespace NodeJS {
|
||||||
// Additional properties
|
// Additional properties
|
||||||
_firstFileName?: string;
|
_firstFileName?: string;
|
||||||
_serviceStartupScript: string;
|
_serviceStartupScript: string;
|
||||||
|
_getOrCreateArchive?: (path: string) => NodeJS.AsarArchive | null;
|
||||||
|
|
||||||
helperExecPath: string;
|
helperExecPath: string;
|
||||||
mainModule?: NodeJS.Module | undefined;
|
mainModule?: NodeJS.Module | undefined;
|
||||||
|
|
Loading…
Reference in a new issue