Skip to content

fix(codeql): resolving GH CodeQL alerts#9783

Merged
mmaietta merged 10 commits into
masterfrom
fix/codeql
May 30, 2026
Merged

fix(codeql): resolving GH CodeQL alerts#9783
mmaietta merged 10 commits into
masterfrom
fix/codeql

Conversation

@mmaietta
Copy link
Copy Markdown
Collaborator

This pull request addresses several security and reliability improvements across the build tooling, with a focus on path handling, sensitive environment variable management, and minor bug fixes. The most significant changes include consistently resolving file system paths to absolute paths to prevent issues with relative paths, improving the handling of sensitive environment variables (especially on Windows), and fixing a regular expression bug. Additionally, the Squirrel Windows target now ensures executable names are sanitized, and some debug logging has been improved.

  • Replaced multiple uses of path.join with path.resolve throughout macPackager.ts, platformPackager.ts, ElectronFramework.ts, and electronGet.ts to ensure all file and directory paths are absolute, reducing the risk of path traversal or misplacement bugs.
  • Updated getProcessEnv in util.ts to strip sensitive environment variables from child process environments on non-Windows platforms, preventing accidental leakage of credentials to subprocesses. On Windows, the previous behavior is retained to avoid breaking critical system tools.
  • Fixed a regular expression in packageMetadata.ts to correctly extract versions from Yarn Berry patch syntax, preventing incorrect parsing.
  • Added sanitizeFileName to ensure the Squirrel Windows target executable name is valid, and updated references to use the sanitized name.
  • Improved debug logging in httpExecutor.ts by omitting request and response headers from logs.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 29, 2026

🦋 Changeset detected

Latest commit: c03fa75

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

This PR includes changesets to release 12 packages
Name Type
electron-builder-squirrel-windows Patch
builder-util-runtime Patch
app-builder-lib Patch
builder-util Patch
electron-builder Patch
electron-publish Patch
electron-updater Patch
dmg-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

Comment thread packages/app-builder-lib/src/util/packageMetadata.ts Dismissed
Comment thread packages/app-builder-lib/src/electron/ElectronFramework.ts Fixed
Comment thread packages/app-builder-lib/src/electron/ElectronFramework.ts Fixed
Comment thread packages/app-builder-lib/src/macPackager.ts Fixed
Comment thread packages/app-builder-lib/src/macPackager.ts Fixed
Comment thread packages/app-builder-lib/src/macPackager.ts Fixed
Comment thread packages/app-builder-lib/src/platformPackager.ts Fixed
Comment thread packages/app-builder-lib/src/platformPackager.ts Fixed
Comment thread packages/app-builder-lib/src/util/electronGet.ts Fixed
Comment thread packages/app-builder-lib/src/util/electronGet.ts Fixed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses CodeQL-driven hardening in build tooling, mainly around path resolution, subprocess environment handling, debug logging redaction, Squirrel Windows executable naming, and Yarn Berry patch dependency parsing.

Changes:

  • Resolves several generated or tool-facing paths to absolute paths before signing, packaging, or extraction.
  • Redacts request headers from HTTP debug logs and adjusts child-process environment filtering behavior.
  • Sanitizes Squirrel Windows executable names and fixes Yarn Berry patch version extraction.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/electron-builder-squirrel-windows/src/SquirrelWindowsTarget.ts Sanitizes the Squirrel executable name used in installer metadata and stub generation.
packages/builder-util/src/util.ts Changes non-Windows default child-process env handling to strip sensitive inherited variables.
packages/builder-util-runtime/src/httpExecutor.ts Omits request headers from request/response debug logging.
packages/app-builder-lib/src/util/packageMetadata.ts Tightens regex extraction for Yarn Berry patch dependency versions.
packages/app-builder-lib/src/util/electronGet.ts Resolves temporary 7z extraction output directory before invoking 7z.
packages/app-builder-lib/src/platformPackager.ts Resolves app output and resource paths to absolute paths.
packages/app-builder-lib/src/macPackager.ts Resolves signing and MAS artifact paths before use.
packages/app-builder-lib/src/electron/ElectronFramework.ts Resolves custom Electron zip extraction output directory before invoking 7z.
.changeset/sweet-worlds-study.md Adds patch changeset entries for affected packages.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/builder-util/src/util.ts
Comment thread packages/app-builder-lib/src/macPackager.ts Fixed
Comment thread packages/app-builder-lib/src/platformPackager.ts Fixed
Comment thread packages/app-builder-lib/src/platformPackager.ts Fixed
Comment thread packages/app-builder-lib/src/macPackager.ts Dismissed
Comment thread packages/app-builder-lib/src/macPackager.ts Fixed
Comment thread packages/builder-util/src/util.ts Fixed
Comment thread packages/app-builder-lib/src/platformPackager.ts Fixed
Comment thread packages/app-builder-lib/src/electron/ElectronFramework.ts Fixed
Comment thread packages/app-builder-lib/src/util/electronGet.ts Fixed
Comment thread packages/app-builder-lib/src/electron/ElectronFramework.ts Fixed
* Replaced multiple uses of `path.join` with `path.resolve` throughout `macPackager.ts`, `platformPackager.ts`, `ElectronFramework.ts`, and `electronGet.ts` to ensure all file and directory paths are absolute, reducing the risk of path traversal or misplacement bugs.
* Updated `getProcessEnv` in `util.ts` to strip sensitive environment variables from child process environments on non-Windows platforms, preventing accidental leakage of credentials to subprocesses. On Windows, the previous behavior is retained to avoid breaking critical system tools.
* Fixed a regular expression in `packageMetadata.ts` to correctly extract versions from Yarn Berry patch syntax, preventing incorrect parsing.
* Added `sanitizeFileName` to ensure the Squirrel Windows target executable name is valid, and updated references to use the sanitized name.
* Improved debug logging in `httpExecutor.ts` by omitting request and response headers from logs.
Add SAFE_7ZA_OUTPUT_PATH_RE and validate7zaOutputPath() to builder-util.

The regex ^[^\x00-\x1F\x7F-][^\x00-\x1F\x7F]*$ is an allowlist that:
- Rejects empty paths (nothing to pass to -oDir)
- Rejects paths starting with "-" (7za would misparse as a new switch)
- Rejects control characters 0x00-0x1F and DEL 0x7F (C-level truncation)
- Allows spaces, quotes, shell metacharacters — all safe with execFile array args

The !regex.test → throw structure is the pattern CodeQL recognises as a
taint-clearing sanitizer, so both 7za call sites no longer need standalone
// codeql suppression comments for the argument construction line.

Replaces the previous verbose .includes() blocklist in electronGet.ts which
incorrectly rejected valid paths containing spaces or quote characters.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Comment thread packages/app-builder-lib/src/electron/ElectronFramework.ts Fixed
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Comment thread packages/electron-builder-squirrel-windows/src/SquirrelWindowsTarget.ts Dismissed
…OutputPath

Replace the separate validate7zaOutputPath + -o${path} template literal pattern
with a single to7zaOutputSwitch(p) that validates and returns the complete
-o<dir> token in one call.

Call sites now pass the token directly as an argv element:
  exec(cmd7za, ["x", "-bd", file, to7zaOutputSwitch(sanitizeDirPath(dir)), "-y"])

No template literal at the call site means CodeQL sees no string concatenation
from user input into the exec argument — the taint is cleared inside
to7zaOutputSwitch before the -o prefix is prepended.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Comment thread packages/builder-util/src/util.ts Fixed
mmaietta and others added 3 commits May 29, 2026 14:58
… constructed from library input'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
… constructed from library input'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
… constructed from library input'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Comment thread packages/builder-util/src/util.ts Dismissed
Comment thread packages/builder-util/src/util.ts Dismissed
… constructed from library input'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Comment thread packages/electron-builder-squirrel-windows/src/SquirrelWindowsTarget.ts Dismissed
… constructed from library input'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@mmaietta mmaietta merged commit 4866737 into master May 30, 2026
45 checks passed
@mmaietta mmaietta deleted the fix/codeql branch May 30, 2026 00:44
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.

3 participants