Skip to content

CI and script hygiene: pass head_ref via env, remove Invoke-Expression from utils.ps1 #3118

Closed

Description

@UBPClaw

Summary

Two small hygiene fixes in the CI workflows and build scripts. Neither is exploitable today, but both are easy to get wrong later.

1. Pass github.head_ref through env: in workflows

build.yml, tests.yml and codeql.yml paste the PR branch name straight into a PowerShell double-quoted string:

$headRef = "${{ github.head_ref }}"

Git branch names may contain $(...), which PowerShell evaluates inside double quotes. These workflows run on pull_request, so fork PRs get a read-only token and already run their own scripts, so nothing is gained today. It would become a real injection if any of them moved to pull_request_target or gained secrets. GitHub's recommended pattern:

env:
  HEAD_REF: ${{ github.head_ref }}
run: |
  $headRef = $env:HEAD_REF

2. Replace Invoke-Expression in scripts/utils.ps1

Extract-Archive, Create-Archive, Digest-Hash and Get-VersionStr build command strings and run them with Invoke-Expression (utils.ps1#L73, #L84, #L108, #L149-L152). The name values from sources.json (or a custom -SourcesPath) end up in those strings, so a name containing $(...) would run as code. The same names are also passed to Remove-Item -Recurse -Force, so a name like ..\.. would delete outside vendor/.

Suggested changes:

  • Call the tools directly, e.g. & 7z x -y "-o$target" $source.
  • Validate name against something like ^[A-Za-z0-9._-]+$ in build.ps1.

Activity

  1. self-assigned this
    on Nov 10, 2026
  2. DRSDavidSoft commented on Nov 10, 2026

    @DRSDavidSoft
    Contributor

    Completed on the current line in #3135, merged at 4489efd.

    The earlier #3134 already moved HEAD_REF through the environment in all three workflows. The remaining build helpers now call native tools directly with argument arrays, validate vendor names before vendor backups/deletions, use literal archive/hash paths, preserve failed extraction inputs, and return an explicit SHA-256 digest. The 27 regression cases pass on PowerShell 5.1 and 7, as do all nine actual synthetic package variants; CI build, tests and CodeQL passed.

    The selective 1.x backport is merged in #3139 and published in stable 1.3.26, keeping the 1.x package names. #3131 is completed. Posted by Codex, David's AI assistant, with his authorization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions