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: move disableSanityCheckAsar to within checkFileInPackage for non-asar verification #8124

Merged
merged 2 commits into from
Mar 11, 2024
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
2 changes: 1 addition & 1 deletion .changeset/dirty-rats-happen.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"app-builder-lib": minor
---

feat: add disableSanityCheckPackage to allow encrypted asars
feat: add disableSanityCheckAsar to allow encrypted asars
5 changes: 5 additions & 0 deletions .changeset/mighty-spies-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"app-builder-lib": patch
---

fix: move `disableSanityCheckPackage` to within `checkFileInPackage` to not bypass non-asar usage
2 changes: 1 addition & 1 deletion docs/configuration/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ Env file `electron-builder.env` in the current dir ([example](https://github.com
<p><code id="Configuration-removePackageKeywords">removePackageKeywords</code> = <code>true</code> Boolean - Whether to remove <code>keywords</code> field from <code>package.json</code> files.</p>
</li>
<li>
<p><code id="Configuration-disableSanityCheckPackage">disableSanityCheckPackage</code> = <code>false</code> Boolean - Whether to disable sanity check asar package (useful for custom electron forks that implement their own encrypted integrity validation)</p>
<p><code id="Configuration-disableSanityCheckAsar">disableSanityCheckAsar</code> = <code>false</code> Boolean - Whether to disable sanity check asar package (useful for custom electron forks that implement their own encrypted integrity validation)</p>
</li>
</ul>

Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/scheme.json
Original file line number Diff line number Diff line change
Expand Up @@ -6666,7 +6666,7 @@
}
]
},
"disableSanityCheckPackage": {
"disableSanityCheckAsar": {
"default": false,
"description": "Whether to disable sanity check asar package (useful for custom electron forks that implement their own encrypted integrity validation)",
"type": "boolean"
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ export interface Configuration extends PlatformSpecificBuildOptions {
* Whether to disable sanity check asar package (useful for custom electron forks that implement their own encrypted integrity validation)
* @default false
*/
readonly disableSanityCheckPackage?: boolean
readonly disableSanityCheckAsar?: boolean
}

interface PackContext {
Expand Down
15 changes: 8 additions & 7 deletions packages/app-builder-lib/src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
}

const isAsar = asarOptions != null
if (!this.config.disableSanityCheckPackage) {
await this.sanityCheckPackage(appOutDir, isAsar, framework)
}
await this.sanityCheckPackage(appOutDir, isAsar, framework, !!this.config.disableSanityCheckAsar)
if (sign) {
await this.doSignAfterPack(outDir, appOutDir, platformName, arch, platformSpecificBuildOptions, targets)
}
Expand Down Expand Up @@ -510,7 +508,10 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
return path.join(appOutDir, `${this.appInfo.productFilename}.app`, "Contents", "Resources")
}

private async checkFileInPackage(resourcesDir: string, file: string, messagePrefix: string, isAsar: boolean) {
private async checkFileInPackage(resourcesDir: string, file: string, messagePrefix: string, isAsar: boolean, disableSanityCheckAsar: boolean) {
if (isAsar && disableSanityCheckAsar) {
return
}
const relativeFile = path.relative(this.info.appDir, path.resolve(this.info.appDir, file))
if (isAsar) {
await checkFileInArchive(path.join(resourcesDir, "app.asar"), relativeFile, messagePrefix)
Expand Down Expand Up @@ -548,7 +549,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
}
}

private async sanityCheckPackage(appOutDir: string, isAsar: boolean, framework: Framework): Promise<any> {
private async sanityCheckPackage(appOutDir: string, isAsar: boolean, framework: Framework, disableSanityCheckAsar: boolean): Promise<any> {
const outStat = await statOrNull(appOutDir)
if (outStat == null) {
throw new Error(`Output directory "${appOutDir}" does not exist. Seems like a wrong configuration.`)
Expand All @@ -561,8 +562,8 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>

const resourcesDir = this.getResourcesDir(appOutDir)
const mainFile = (framework.getMainFile == null ? null : framework.getMainFile(this.platform)) || this.info.metadata.main || "index.js"
await this.checkFileInPackage(resourcesDir, mainFile, "Application entry file", isAsar)
await this.checkFileInPackage(resourcesDir, "package.json", "Application", isAsar)
await this.checkFileInPackage(resourcesDir, mainFile, "Application entry file", isAsar, disableSanityCheckAsar)
await this.checkFileInPackage(resourcesDir, "package.json", "Application", isAsar, disableSanityCheckAsar)
}

// tslint:disable-next-line:no-invalid-template-strings
Expand Down
Loading