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

fix: ensure app load is limited to real asar files when appropriate #39808

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/asar/fs-wrapper.ts
Expand Up @@ -27,7 +27,7 @@ const cachedArchives = new Map<string, NodeJS.AsarArchive>();
const getOrCreateArchive = (archivePath: string) => {
const isCached = cachedArchives.has(archivePath);
if (isCached) {
return cachedArchives.get(archivePath);
return cachedArchives.get(archivePath)!;
}

try {
Expand All @@ -39,6 +39,8 @@ const getOrCreateArchive = (archivePath: string) => {
}
};

process._getOrCreateArchive = getOrCreateArchive;

const asarRe = /\.asar/i;

// Separate asar package's path from full path.
Expand Down
9 changes: 9 additions & 0 deletions lib/browser/init.ts
Expand Up @@ -84,11 +84,20 @@ const v8Util = process._linkedBinding('electron_common_v8_util');
let packagePath = null;
let packageJson = null;
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) {
for (packagePath of searchPaths) {
try {
packagePath = path.join(process.resourcesPath, packagePath);
if (searchPathsOnlyLoadASAR) {
if (!getOrCreateArchive?.(packagePath)) {
continue;
}
}
packageJson = Module._load(path.join(packagePath, 'package.json'));
break;
} catch {
Expand Down
7 changes: 7 additions & 0 deletions shell/common/node_bindings.cc
Expand Up @@ -512,6 +512,13 @@ node::Environment* NodeBindings::CreateEnvironment(
electron::fuses::IsOnlyLoadAppFromAsarEnabled()
? app_asar_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();
Expand Down
1 change: 1 addition & 0 deletions typings/internal-ambient.d.ts
Expand Up @@ -247,6 +247,7 @@ declare namespace NodeJS {
// Additional properties
_firstFileName?: string;
_serviceStartupScript: string;
_getOrCreateArchive?: (path: string) => NodeJS.AsarArchive | null;

helperExecPath: string;
mainModule?: NodeJS.Module | undefined;
Expand Down