Skip to content

Commit 9e11358

Browse files
authored
fix(asar): check ResolvedFileSet src when verifying symlinks to be within project directory (#8654)
1 parent 796e1a0 commit 9e11358

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

.changeset/smooth-camels-decide.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"app-builder-lib": patch
3+
---
4+
5+
fix: check ResolvedFileSet src when verifying symlinks to be within project directory

packages/app-builder-lib/src/asar/asarUtil.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export class AsarPackager {
1919

2020
constructor(
2121
private readonly config: {
22-
appDir: string
2322
defaultDestination: string
2423
resourcePath: string
2524
options: AsarOptions
@@ -86,7 +85,14 @@ export class AsarPackager {
8685
return
8786
}
8887
}
89-
const writeFileOrSymlink = async (transformedData: string | Buffer | undefined, source: string, destination: string, stat: fs.Stats) => {
88+
const writeFileOrSymlink = async (options: { transformedData: string | Buffer | undefined; file: string; destination: string; stat: fs.Stats; fileSet: ResolvedFileSet }) => {
89+
const {
90+
transformedData,
91+
file: source,
92+
destination,
93+
stat,
94+
fileSet: { src: sourceDir },
95+
} = options
9096
copiedFiles.add(destination)
9197

9298
// If transformed data, skip symlink logic
@@ -100,8 +106,7 @@ export class AsarPackager {
100106
return this.copyFileOrData(undefined, source, destination, stat)
101107
}
102108

103-
const realPathRelative = path.relative(this.config.appDir, realPathFile)
104-
const symlinkTarget = path.resolve(this.rootForAppFilesWithoutAsar, realPathRelative)
109+
const realPathRelative = path.relative(sourceDir, realPathFile)
105110
const isOutsidePackage = realPathRelative.startsWith("..")
106111
if (isOutsidePackage) {
107112
log.error({ source: log.filePath(source), realPathFile: log.filePath(realPathFile) }, `unable to copy, file is symlinked outside the package`)
@@ -110,6 +115,7 @@ export class AsarPackager {
110115
)
111116
}
112117

118+
const symlinkTarget = path.resolve(this.rootForAppFilesWithoutAsar, realPathRelative)
113119
await this.copyFileOrData(undefined, source, symlinkTarget, stat)
114120
const target = path.relative(path.dirname(destination), symlinkTarget)
115121
fsNode.symlinkSync(target, destination)
@@ -130,7 +136,7 @@ export class AsarPackager {
130136
const dest = path.resolve(this.rootForAppFilesWithoutAsar, relative)
131137

132138
matchUnpacker(file, dest, metadata)
133-
taskManager.addTask(writeFileOrSymlink(transformedData, file, dest, metadata))
139+
taskManager.addTask(writeFileOrSymlink({ transformedData, file, destination: dest, stat: metadata, fileSet }))
134140

135141
if (taskManager.tasks.length > MAX_FILE_REQUESTS) {
136142
await taskManager.awaitTasks()

packages/app-builder-lib/src/platformPackager.ts

-1
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,6 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
505505
}
506506

507507
await new AsarPackager({
508-
appDir,
509508
defaultDestination,
510509
resourcePath,
511510
options: asarOptions,

0 commit comments

Comments
 (0)