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: ignore symlink file if it links outside module #8568

Closed
wants to merge 16 commits into from

Conversation

beyondkmp
Copy link
Collaborator

@beyondkmp beyondkmp commented Oct 7, 2024

If there is a symlink file in some node module that points to ../../../../../../etc/passwd, this would cause the system's passwd file to be packaged along with it.

The solution is to restrict symlinks within modules to only link to other files within their directory. Any symlinks pointing outside of this directory will be ignored, and a warning log will be generated.

Copy link

changeset-bot bot commented Oct 7, 2024

🦋 Changeset detected

Latest commit: 5eef967

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
app-builder-lib Patch
dmg-builder Patch
electron-builder-squirrel-windows Patch
electron-builder Patch
electron-forge-maker-appimage Patch
electron-forge-maker-nsis-web Patch
electron-forge-maker-nsis Patch
electron-forge-maker-snap Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

netlify bot commented Oct 7, 2024

Deploy Preview for car-park-attendant-cleat-11576 ready!

Name Link
🔨 Latest commit 5eef967
🔍 Latest deploy log https://app.netlify.com/sites/car-park-attendant-cleat-11576/deploys/6704039e2109e60008a8cfa9
😎 Deploy Preview https://deploy-preview-8568--car-park-attendant-cleat-11576.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@beyondkmp beyondkmp changed the title fix: delete symlink file if it links outside node_modules fix:ignore symlink file if it links outside node_modules Oct 7, 2024
@beyondkmp beyondkmp changed the title fix:ignore symlink file if it links outside node_modules fix: ignore symlink file if it links outside node_modules Oct 7, 2024
@beyondkmp beyondkmp requested a review from mmaietta October 7, 2024 16:02
@beyondkmp beyondkmp changed the title fix: ignore symlink file if it links outside node_modules fix: ignore symlink file if it links outside module Oct 7, 2024

test.ifDevOrLinuxCi(
"ignore symlink file if it links outside node_modules",
app(
Copy link
Collaborator

@mmaietta mmaietta Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have a test that should be failing if the symlink is outside of the project dir (doesn't need to be a node_module specifically, just any symlinked file)

test.ifNotWindows(
"outside link",
app(
{
targets: Platform.LINUX.createTarget(DIR_TARGET),
},
{
projectDirCreated: async (projectDir, tmpDir) => {
const tempDir = await tmpDir.getTempDir()
await outputFile(path.join(tempDir, "foo"), "data")
await fs.symlink(tempDir, path.join(projectDir, "o-dir"))
},
packed: async context => {
const file = (await readAsar(path.join(context.getResources(Platform.LINUX), "app.asar"))).getFile("o-dir/foo", false)
expect(removeUnstableProperties(file)).toMatchSnapshot()
},
}
)
)

I don't think we need this "ignore symlink file if it links outside node_modules" test and can instead just reuse the "outside link" test instead

log.warn({ module: moduleName, file: filePath, resolvedLinkTarget }, `deleting symlink outside module`)
return null
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this logic needs to be in asarUtil instead of NodeModuleCopyHelper as the symlink outside the project dir can't be allowed for both file assets or node modules.

Let me finish up the electron/asar migration and I can incorporate your changes here into that PR branch

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's done in asarUtil, any files linked to other workspaces within the project will all fail. I'm not sure how common this usage pattern is.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any files linked to other workspaces within the project will all fail

Can you elaborate on this? Are you referring to a two-package.json project structure?

I'm not sure how common this usage pattern is.

It's less so about how common it is and more so about enforcing best practices. For instance, electron/asar already validates making sure symlinks are within the package during asar extraction: https://github.com/electron/asar/blob/464e83436967438c74d8ac184b088fc780706b2d/src/asar.ts#L249-L253

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can close this PR in favor of electron/asar PR #8570 implementation of this symlink logic:

const realPathRelative = path.relative(this.config.appDir, realPathFile)
const symlinkTarget = path.resolve(this.rootForAppFilesWithoutAsar, realPathRelative)
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`)
throw new Error(
`Cannot copy file (${path.basename(source)}) symlinked to file (${path.basename(realPathFile)}) outside the package as that violates asar security integrity`
)
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreeded. I will close it.

@beyondkmp beyondkmp closed this Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants