Skip to content

fix: add SHA-256 integrity check for cached .node files#230

Open
olegcS wants to merge 1 commit intoyao-pkg:mainfrom
olegcS:fix/integrity-check-only
Open

fix: add SHA-256 integrity check for cached .node files#230
olegcS wants to merge 1 commit intoyao-pkg:mainfrom
olegcS:fix/integrity-check-only

Conversation

@olegcS
Copy link
Copy Markdown

@olegcS olegcS commented Apr 10, 2026

Summary

  • Adds SHA-256 integrity verification for cached .node files in the single-file code path of process.dlopen
  • The node_modules path already had hash verification via copyFolderRecursiveSync, but the single-file path only checked fs.existsSync — a tampered or corrupted cached file was silently loaded
  • A mismatched file is now detected and re-extracted from the snapshot

Security context

Native addons are extracted to user-writable directories (e.g. ~/.cache/pkg/). Without integrity verification, an attacker could replace a cached .node file with a malicious one that executes at the privilege level of the packaged application. This closes that privilege escalation vector.

Relation to #228

This is the integrity-check-only portion of #228, split per reviewer feedback. The lazy PKG_NATIVE_CACHE_PATH eval has been dropped from this PR.

Test plan

  • Verify diff only touches the single-file else branch in process.dlopen
  • Package an app with a native addon, tamper with the cached .node file, confirm it gets re-extracted
  • Package an app with a native addon, leave cache intact, confirm it loads without re-extraction

🤖 Generated with Claude Code

Add integrity verification for cached .node files in the single-file
code path (the else branch of process.dlopen). The node_modules path
already had hash verification via copyFolderRecursiveSync, but the
single-file path only checked fs.existsSync. A tampered or corrupted
cached file is now detected and re-extracted from the snapshot.

This closes a privilege escalation vector where native addons are
extracted to user-writable directories (e.g. ~/.cache/pkg/) and can
be replaced with malicious .node files that execute at the privilege
level of the packaged application.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant