Skip to content

fix: every PHP# download and image is verified, and the release pipeline runs only pinned code - #203

Merged
heyJordanParker merged 5 commits into
masterfrom
chore/distribution-safety
Oct 25, 2026
Merged

heyJordanParker merged 5 commits into
masterfrom
chore/distribution-safety

Conversation

@heyJordanParker

@heyJordanParker heyJordanParker commented Oct 24, 2026 •

Copy link
Copy Markdown
Owner

Closes #86.

The 0.5.0 safety audit found code we ship running unverified on users' machines and servers. This PR verifies every mago download and pins every image and third-party action the release pipeline runs.

Gaps and fixes

The mago-sharp Composer wrapper ran a downloaded binary with no integrity check. release.yml writes mago-<version>-sha256sums.txt into the release. Its composer job downloads every published asset and checks it, and the published sums file, against the SHA-256s the run wrote. Only then does it push the heyJordanParker/mago-sharp tag: the split of sharp/mago plus a commit that adds those SHA-256s as composer/sha256sums.txt. extract_archive refuses an archive whose SHA-256 differs. Its error names the expected and the actual hash, and it deletes the archive. sharp.yml's COMPOSER job pushes only branches of the mirror.

The wrapper's stream-wrapper path sent GITHUB_TOKEN to the redirect's host. The new DownloadTest redirects 127.0.0.1 to localhost. Before this PR, localhost received Bearer <token> from download_with_fopen, and none from curl (libcurl 8.18.0). download_with_fopen now follows each redirect itself, and only the first request carries the token. download_with_curl sets CURLOPT_UNRESTRICTED_AUTH to false explicitly, with a comment that curl 7.58.0 and later already drop the header. mago self-update's ureq 3.4.1 drops it too: its redirect_auth_headers defaults to Never.

install.sh and mago self-update installed with no verification. Both now verify the archive before they extract it. With gh, they verify its build attestation, signed by release.yml. Without gh, they check it against mago-<version>-sha256sums.txt, refuse a mismatch with both hashes, and say that full provenance needs gh. install.sh --no-verify is still the only opt-out. A release that publishes no sums file, 0.5.0 and earlier, updates only with gh.

Third-party actions were pinned to tags or branches. Every third-party uses: in .github/workflows and .github/actions names a 40-character SHA with its release as a comment. sharp.yml, release.yml, mago.yml, base-images.yml and fuzz.yml use one version of each action: actions/checkout v7.0.1, actions/cache v6.1.0, actions/upload-artifact v7.0.2 and actions/download-artifact v8.0.2. The upstream php-src workflows keep upstream's versions. .github/dependabot.yml moves the SHAs weekly, with a 7-day cooldown, grouping minor and patch updates and leaving each major update its own pull request. sharp.yml's new WORKFLOWS job fails on a third-party uses: without a full SHA, so an unpinned action can't come back. Every workflow and job holds the least permissions it uses.

The runtime images took their base by tag. Both Dockerfiles pin BASE_IMAGE by digest as ${REGISTRY}/debian:trixie-slim@sha256:…, and frankenphp.Dockerfile pins GOLANG_IMAGE too. REGISTRY defaults to ECR Public, and CI sets it to ghcr.io/heyjordanparker. base-images.yml's PIN job is the one thing that moves the digests. When a copy has a new digest, it pushes a branch named from the new digests, never moves a branch it pushed, and opens or updates one issue that names the old and new digests and links the compare view. An Agent opens the pull request from that issue, so its CI runs. PIN holds only contents: write and issues: write, so "Allow GitHub Actions to create and approve pull requests" stays off.

No image was CVE-scanned. aquasecurity/trivy-action v0.36.0 (ed142fd0) runs Trivy v0.76.1 and fails on a critical or high CVE that a fixed package resolves. PHP_EXTENSIONS scans each image it builds. IMAGE scans each platform's pushed digest on its own runner before it uploads the digest, so IMAGE_TAGS tags only scanned images, linux/arm64 included. On 2026-03-19, attackers force-pushed 76 of trivy-action's 77 tags to malware (GHSA-69fq-xp46-6x23). v0.35.0 and later are immutable releases, v0.36.0 pins its own setup-trivy by SHA, and Trivy 0.71.1 and later fix GHSA-mcj4-mphf-j9ff. The first scan found HIGH CVE-2026-78669 in FrankenPHP v1.13.0's golang.org/x/net v0.59.0, so the image and sharp/bin/hosts both build FrankenPHP v1.13.1.

#86: the IMAGE job pulled moby/buildkit from Docker Hub anonymously. docker/github-builder is replaced by our own steps. IMAGE builds each Dockerfile on a runner of each platform's own architecture. Each build logs in to ghcr.io first, then sets up Buildx with ghcr.io/heyjordanparker/buildkit:v0.34.1 at a pinned digest. It builds the tagged commit by SHA and pushes by digest, with BuildKit's mode=max provenance and an SBOM from ghcr.io/heyjordanparker/buildkit-syft-scanner:1.12.0. IMAGE_TAGS tags the two platform images as <version> and <version>-frankenphp, and attests the image with actions/attest-build-provenance (push-to-registry). frankenphp.Dockerfile has no # syntax= line, whose frontend BuildKit pulls from Docker Hub with no login. A comment says so where it was, and WORKFLOWS fails on one under sharp/docker.

The FrankenPHP image downloaded its sources by tag and URL. frankenphp.Dockerfile fetches FrankenPHP v1.13.1 by the commit its tag names, 99d4e119, and checks the e-dant/watcher 0.14.5 archive and the install-php-extensions 2.12.0 script against pinned SHA-256s. The script's SHA-256 is the digest GitHub records for that release asset.

mago's fuzz targets never ran. The new sharp_parser target parses its input with parse_file_with_dialect in Dialect::Sharp. fuzz.yml runs lexer, parser and sharp_parser every day for 10 minutes each, on nightly-2026-10-13, with -timeout=10. It keeps each target's corpus in a cache between runs, seeds sharp_parser from the 521 .sharp files under Zend/tests/sharp too, and checks the committed fuzz Cargo.lock. It fails on a crash and uploads the crashing input.

CI never ran actionlint. WORKFLOWS installs actionlint v1.7.12 from its release archive at a pinned SHA-256 and runs it over every workflow. .github/actionlint.yaml names php-src's gentoo and ppc64 runner labels, and leaves out php-src's composite actions' missing description. It also leaves out the shellcheck notes of php-src's test-suite.yml and real-time-benchmark.yml, kept as php-src writes them so they merge. sharp.yml's five shellcheck notes are fixed with shellcheck disable comments that say why each word splits.

splitsh-lite installs from one composite action, .github/actions/splitsh-lite. re-actors/alls-green's comment names v1.3.0, the tag its SHA is, and dwieeb/needs-reply moves to its new name, imhoffd/needs-reply, at the same SHA.

Needs the Architect

  • Two new ghcr.io packages. This PR's base-images.yml run creates ghcr.io/heyjordanparker/buildkit and ghcr.io/heyjordanparker/buildkit-syft-scanner. IMAGE logs in before it pulls them, so they work private.
  • Signing changes. docker/github-builder signed its attestation manifests with cosign. The new jobs attest with GitHub's Sigstore instead, the same way the mago archives are attested. The SBOM is new: the 0.5.0 image carried none.
  • PIN leaves one branch per digest set. A merged pull request deletes its branch only if the repository deletes head branches on merge.

Verification run locally

  • Composer wrapper: phpunit --configuration composer/phpunit.xml: 142 tests OK. Against the real v0.5.0 release, a pinned 0000… failed with has SHA-256 35f75d71…, and heyjordanparker/mago-sharp pins 0000… for it, and nothing was extracted. The real hash printed mago 0.5.0.
  • Token across a redirect: before, download_with_fopen sent Bearer <token> to localhost. After, first host: Bearer redirect-test-token, redirect host: none for both paths.
  • install.sh without gh: a matching archive installed, and a tampered one failed with CHECKSUM VERIFICATION FAILED, naming both hashes.
  • mago self-update: cargo test -p mago --bin mago: 110 passed, among them a_tampered_archive_is_refused_with_its_sha256_and_the_one_the_sums_file_names. With gh, self-update --tag 0.4.2 printed Attestation verified. and the binary printed mago 0.4.2. Without gh, it refused, because 0.4.2 publishes no mago-0.4.2-sha256sums.txt, and the binary still printed mago 0.5.0.
  • PIN: its two run: scripts, read from base-images.yml, ran in a Debian container against a local origin, the real skopeo and a stand-in gh. The first run pushed base-images/debian-trixie-slim-62bd423aeee9-golang-1.27-trixie-fbb7ae40b62f and created the issue. The second found the branch, left it at the same commit, and edited issue 7. The real gh issue list --search 'in:title "…"' --jq 'map(select(.title == env.TITLE))…' found issue The release image job still pulls moby/buildkit anonymously from Docker Hub #86 by its exact title.
  • Published-asset check: the composer job's step passed on matching assets, and failed on a replaced asset and on a different sums file.
  • Pin check: it printed .github/workflows/mago.yml:343: uses: actions/checkout@v7 with one unpinned uses:, and nothing on this branch. The # syntax= check printed the line added to frankenphp.Dockerfile, and nothing on this branch.
  • actionlint: actionlint v1.7.12 with Ubuntu 24.04's shellcheck 0.9.0 exited 0 over every workflow.
  • Trivy's platform: TRIVY_PLATFORM=linux/arm64 scanned the arm64 image of the 0.5.0 index, attestations and all, and linux/amd64 the amd64 one.
  • Images: frankenphp.Dockerfile built from this commit's tree with --build-arg REGISTRY=ghcr.io/heyjordanparker. The build fetched frankenphp.git#99d4e119…, printed /tmp/watcher.tar.gz: OK and /usr/local/bin/install-php-extensions: OK, and the image printed FrankenPHP 1.13.1 PHP 8.5.12. Trivy v0.76.1 found 0 fixable critical or high CVEs in its Debian packages and its frankenphp binary, and the default command served HTTP 200. The fpm Dockerfile changed only in a comment, and it built at the pinned digest on 4c984e0.
  • Fuzzing: cargo fuzz run sharp_parser … -- -max_total_time=60 -timeout=10 -seed_inputs=@… on nightly-2026-10-13: Done 55016 runs in 61 second(s), with no crash. The seed list alone loaded seed corpus: files: 520.

Annotated file tree

.github/
├── actionlint.yaml                     new: php-src's runner labels and the rules its own files skip
├── dependabot.yml                      new: github-actions SHAs stay current, minor+patch grouped, majors alone
├── actions/
│   ├── splitsh-lite/action.yml         new: installs splitsh-lite v1.0.1 at a pinned SHA-256
│   ├── ccache/action.yml               hendrikmuhs/ccache-action pinned
│   ├── freebsd/action.yml              vmactions/freebsd-vm pinned
│   └── solaris/action.yml              vmactions/solaris-vm pinned
└── workflows/
    ├── base-images.yml                 copies BuildKit and its SBOM scanner; PIN pushes a branch per digest set
    │                                   and opens or updates one issue
    ├── fuzz.yml                        new: lexer, parser, sharp_parser daily on a dated nightly, corpus cached
    ├── release.yml                     sums asset; composer job checks the published assets, then pushes the tag
    ├── sharp.yml                       Trivy in PHP_EXTENSIONS and IMAGE; IMAGE + IMAGE_TAGS replace
    │                                   github-builder; WORKFLOWS: pin check, syntax check, actionlint
    ├── mago.yml                        SHA pins, one version per action, permissions
    ├── close-needs-feedback.yml        imhoffd/needs-reply
    ├── nightly-results.yml             permissions: {}
    ├── windows-builds.yml              permissions: {}
    └── 10 more workflows               SHA pins only
docs/architecture/mago.md               the mirror's tags come from release.yml; install.sh and self-update verify
sharp/
├── README.md                           CI section: sums file, composer check, IMAGE scan, PIN issue, WORKFLOWS
├── bin/hosts                           FrankenPHP v1.13.1, in a folder per release
├── docker/
│   ├── Dockerfile                      comment: v1.13.1
│   └── runtime/
│       ├── Dockerfile                  REGISTRY; BASE_IMAGE pinned by digest
│       └── frankenphp.Dockerfile       REGISTRY; bases pinned by digest; FrankenPHP by commit SHA; watcher and
│                                       install-php-extensions checked by SHA-256; why no syntax line
└── mago/
    ├── Cargo.toml, Cargo.lock          sha2 for self-update
    ├── Justfile                        fuzz-sharp-parser
    ├── src/commands/self_update.rs     verify_archive: gh attestation, else the release's sums file
    ├── composer/
    │   ├── phpunit.xml                 the "Mago Composer wrapper" suite
    │   ├── src/internal.php            get_archive_checksum, extract_archive checks SHA-256,
    │   │                               download_with_fopen sends the token to the first host only
    │   └── tests/Internal/
    │       ├── DownloadTest.php        new: where the token goes across a redirect
    │       └── ExtractArchiveTest.php  new: a mismatching archive is refused with both hashes
    ├── crates/syntax/fuzz/
    │   ├── Cargo.toml                  sharp_parser target
    │   ├── Cargo.lock                  new: committed
    │   ├── .gitignore                  no longer ignores Cargo.lock
    │   ├── corpus/sharp_parser/.gitkeep
    │   └── fuzz_targets/sharp_parser.rs  new: parse_file_with_dialect in Dialect::Sharp
    ├── docs/content/{en,fr,zh}/guide/
    │   ├── installation.md             checksum fallback and the wrapper's pinned SHA-256
    │   └── upgrading.md                how self-update verifies
    └── scripts/install.sh              checksum verification without gh

…ine runs only pinned code

The 0.5.0 safety audit found code we ship running on users' machines and servers unverified:
- The mago-sharp Composer wrapper extracted and ran the mago archive it downloaded with no
  integrity check.
- Its stream-wrapper download path sent GITHUB_TOKEN to the redirect's host. curl already drops
  it.
- install.sh installed with no verification when gh was missing.
- Every third-party action re-resolved a tag or a branch on each run, in workflows that hold
  contents: write, id-token: write, packages: write and two deploy keys.
- The runtime images took their Debian and Go bases by tag, so a new base arrived silently.
- No image was CVE-scanned.
- The IMAGE job pulled moby/buildkit from Docker Hub anonymously (#86).
- mago's fuzz targets never ran, and none parsed PHP#.

The release pins every binary, and every image and action is pinned:
- release.yml writes mago-<version>-sha256sums.txt into the release. Its new composer job
  pushes the mirror's tag as the split of sharp/mago plus composer/sha256sums.txt. The wrapper
  refuses an archive whose SHA-256 differs, and names both hashes.
- The stream-wrapper path follows redirects itself and sends the token only with the first
  request. The curl path sets CURLOPT_UNRESTRICTED_AUTH false explicitly.
- install.sh verifies the attestation with gh, or else the SHA-256 in the release's sums file,
  and says that full provenance needs gh.
- Every third-party action is pinned to a commit SHA with its version as a comment, and
  Dependabot moves them. release.yml's jobs hold only the permissions each needs.
- The Dockerfiles pin their bases by digest under a REGISTRY that CI sets to ghcr.io. The new
  PIN job in base-images.yml opens the pull request that moves the digests. base-images.yml
  also copies moby/buildkit and docker/buildkit-syft-scanner.
- PHP_EXTENSIONS scans each runtime image with Trivy, and fails on a fixable critical or high
  CVE.
- IMAGE builds with our own Buildx steps from those copies after the login, keeps provenance
  and adds SBOM attestations, and IMAGE_TAGS attests the tagged image.
- fuzz.yml runs the lexer, parser and the new sharp_parser target for 10 minutes each every day,
  and uploads a crashing input.

Closes #86.

.github/
├── dependabot.yml                  new: github-actions SHAs stay current
├── actions/{ccache,freebsd,solaris}/action.yml   SHA pins
└── workflows/
    ├── base-images.yml             copies BuildKit and its SBOM scanner; PIN moves digests
    ├── fuzz.yml                    new: daily syntax fuzzing
    ├── release.yml                 sha256sums asset, composer job, least permissions
    ├── sharp.yml                   Trivy scan, own Buildx IMAGE + IMAGE_TAGS, no tag split
    └── 14 other workflows          SHA pins, empty permissions where none are needed
sharp/
├── docker/runtime/{Dockerfile,frankenphp.Dockerfile}   REGISTRY, digest-pinned bases
└── mago/
    ├── composer/src/internal.php   checksum check, token sent only to the first host
    ├── composer/tests/Internal/    new: DownloadTest, ExtractArchiveTest
    ├── crates/syntax/fuzz/         new sharp_parser target
    ├── scripts/install.sh          checksum verification without gh
    └── docs/…/installation.md      en, fr, zh describe the new verification
The scan PHP_EXTENSIONS now runs failed on the FrankenPHP image. FrankenPHP v1.13.0's
frankenphp binary links golang.org/x/net v0.59.0, with HIGH CVE-2026-78669 (an HTTP/2
SETTINGS-frame denial of service), fixed in v0.60.0.

The image builds FrankenPHP v1.13.1, which takes golang.org/x/net v0.61.0 and keeps v1.13.0's
Go 1.27 and e-dant/watcher pins. sharp/bin/hosts still builds v1.13.0 for HOSTS.

sharp/
├── README.md                              the runtime image names v1.13.1
└── docker/runtime/frankenphp.Dockerfile   FrankenPHP v1.13.1
@heyJordanParker

Copy link
Copy Markdown
Owner Author

Review verdict on 4c984e0: changes required

The core design holds. The wrapper checks its pinned hash before download and deletes a mismatch, install.sh verifies the attestation or the sums file, every third-party pin matches its version comment (all 28 peeled and checked), the release jobs each hold only the permissions they use, and the Trivy gate fails on fixable critical and high CVEs with every scanner piece pinned. Three findings remain, plus debt to clean in the same round.

1. The images IMAGE publishes are never scanned

PHP_EXTENSIONS scans one amd64 build at merge time. IMAGE rebuilds both platforms at tag time, running apt-get again, and pushes by digest with no scan. So the linux/arm64 image is never scanned, and a fixable CVE published between merge and tag ships. Scan each pushed digest in IMAGE, on its native runner, with the same pinned trivy-action and settings, before the digest upload, so IMAGE_TAGS tags only scanned digests.

2. PIN's daily force-push would strand an open PR

Beyond the redesign queued on the task (branch plus issue, no PR from GITHUB_TOKEN), PIN force-pushes base-images/digests daily. Once a PR is open from it, the next push moves the PR's head with GITHUB_TOKEN, which starts no workflow, so the required check waits forever. Push one branch per digest set, named from the digests, and update the issue to name the newest. PIN needs contents: write and issues: write only.

3. Prove the mirror tag's hashes match what users download

The release compares asset names, not contents. Before the composer job pushes the mago-sharp tag, download the published assets and run sha256sum -c against mago-$VERSION-sha256sums.txt, so a mismatch fails before any tag exists.

Debt, in the same round

  • splitsh-lite is downloaded with its SHA-256 in both sharp.yml and release.yml. Move it into one composite action under .github/actions/, as the repository's other composite actions are.
  • One version per action in our workflows. sharp.yml, release.yml, mago.yml, base-images.yml and fuzz.yml use the newest major of actions/checkout, actions/cache and actions/upload-artifact. The upstream php-src workflows keep upstream's versions, since they merge from php-src. Group Dependabot's minor and patch updates, and leave each major update its own PR.
  • Pin comments: re-actors/alls-green names v1.3.0, the tag its SHA is. dwieeb/needs-reply moves to its new name, imhoffd/needs-reply.
  • Fuzzing: seed sharp_parser from the .sharp files under Zend/tests/sharp, keep each target's corpus between runs with a cache, commit the fuzz crate's Cargo.lock, pin a dated nightly, and pass -timeout=10. The target calls parse_file_with_dialect with Dialect::Sharp instead of relying on the file name.
  • # syntax=docker/dockerfile:1 was removed because it pulls from Docker Hub without a login. Say so in a comment where it was, and make the pin check fail on a # syntax= line under sharp/docker, so an upstream merge can't bring it back.

…ue, and every download is verified

- IMAGE scans each pushed digest with the pinned trivy-action on its own platform's runner before the digest is
  uploaded, so IMAGE_TAGS tags only scanned images.
- base-images.yml's PIN pushes one branch per digest set, named from the digests, never moves a pushed branch, and
  opens or updates one issue that names the old and new digests and links the compare view. It holds contents: write
  and issues: write only, so "Allow GitHub Actions to create and approve pull requests" stays off.
- release.yml's composer job downloads the published assets and checks them and the published sums file against the
  SHA-256s the run wrote before it pushes the mago-sharp tag.
- mago self-update verifies the downloaded archive before extracting it: its build attestation with gh, else its
  SHA-256 against the release's sums file, refusing a mismatch with both hashes.
- frankenphp.Dockerfile fetches FrankenPHP v1.13.1 by commit SHA and checks the e-dant/watcher archive and the
  install-php-extensions script against pinned SHA-256s. sharp/bin/hosts builds v1.13.1 too, in a folder per release.
- sharp.yml's new WORKFLOWS job fails on a third-party uses: without a 40-character SHA, on a # syntax= line under
  sharp/docker, and on any actionlint finding. .github/actionlint.yaml names php-src's runner labels and leaves out
  php-src's composite actions' missing descriptions and its two workflows' shellcheck notes.
- splitsh-lite installs from one composite action, .github/actions/splitsh-lite.
- sharp.yml, release.yml, mago.yml, base-images.yml and fuzz.yml use actions/checkout v7.0.1, actions/cache v6.1.0,
  actions/upload-artifact v7.0.2 and actions/download-artifact v8.0.2. Dependabot groups minor and patch updates and
  leaves each major update its own pull request.
- re-actors/alls-green's pin comment names v1.3.0, and dwieeb/needs-reply moves to imhoffd/needs-reply.
- The sharp_parser fuzz target calls parse_file_with_dialect with Dialect::Sharp, and fuzz.yml seeds it from the .sharp
  files under Zend/tests/sharp, keeps each target's corpus in a cache, runs nightly-2026-10-13 with -timeout=10, and
  checks the committed fuzz Cargo.lock.
@heyJordanParker
heyJordanParker merged commit 91a94a4 into master Oct 25, 2026
35 checks passed
@heyJordanParker
heyJordanParker deleted the chore/distribution-safety branch October 25, 2026 07:58
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.

The release image job still pulls moby/buildkit anonymously from Docker Hub

1 participant