Skip to content

Commit

Permalink
fix(asar): check ResolvedFileSet src when verifying symlinks to be wi…
Browse files Browse the repository at this point in the history
…thin project directory (#8654)
  • Loading branch information
mmaietta authored Nov 1, 2024
1 parent 796e1a0 commit 9e11358
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/smooth-camels-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"app-builder-lib": patch
---

fix: check ResolvedFileSet src when verifying symlinks to be within project directory
16 changes: 11 additions & 5 deletions packages/app-builder-lib/src/asar/asarUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export class AsarPackager {

constructor(
private readonly config: {
appDir: string
defaultDestination: string
resourcePath: string
options: AsarOptions
Expand Down Expand Up @@ -86,7 +85,14 @@ export class AsarPackager {
return
}
}
const writeFileOrSymlink = async (transformedData: string | Buffer | undefined, source: string, destination: string, stat: fs.Stats) => {
const writeFileOrSymlink = async (options: { transformedData: string | Buffer | undefined; file: string; destination: string; stat: fs.Stats; fileSet: ResolvedFileSet }) => {
const {
transformedData,
file: source,
destination,
stat,
fileSet: { src: sourceDir },
} = options
copiedFiles.add(destination)

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

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

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

matchUnpacker(file, dest, metadata)
taskManager.addTask(writeFileOrSymlink(transformedData, file, dest, metadata))
taskManager.addTask(writeFileOrSymlink({ transformedData, file, destination: dest, stat: metadata, fileSet }))

if (taskManager.tasks.length > MAX_FILE_REQUESTS) {
await taskManager.awaitTasks()
Expand Down
1 change: 0 additions & 1 deletion packages/app-builder-lib/src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,6 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
}

await new AsarPackager({
appDir,
defaultDestination,
resourcePath,
options: asarOptions,
Expand Down

0 comments on commit 9e11358

Please sign in to comment.