Skip to content

Publish PR builds from validated, extracted files - #65550

Merged
Jake Bailey (jakebailey) merged 5 commits into
microsoft:mainfrom
jakebailey:pr-build-extracted-validation
Nov 17, 2026
Merged

Jake Bailey (jakebailey) merged 5 commits into
microsoft:mainfrom
jakebailey:pr-build-extracted-validation

Conversation

@jakebailey

Copy link
Copy Markdown
Member

This is a bit belt-and-suspenders as we only pack this on trusted PRs, but these are not unreasonable as a matter of correctness.

The PR build validator inspected each tarball through GNU tar, but npm
publish read the original tarball with its own tar parser, and the two
do not always agree on an archive's contents. Reading paths from the
human-readable tar listing was also fragile, for example with owner
names that contain spaces.

Extract each tarball once, validate the extracted files, and publish
that directory so that npm publishes exactly the files that were
validated.
Rejecting a fixed list of fields still allowed others that npm acts on
during installation, such as "directories": { "bin": ... }. Allow only
the fields the packages use.
set -e does not see the exit status of a process substitution, so the
step kept running after a validation failure and stopped only later
because no packages were listed.
npm publish parses some paths, such as those containing "@" and ":", as
git URLs. Name the extraction directories by index instead.
Loose equality accepted values such as a null bin, and the version
pattern accepted leading zeros, which npm removes when publishing.
@github-project-automation github-project-automation Bot moved this from Not started to Needs merge in PR Backlog Nov 17, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The publish workflow can accept a platform package whose npm pack rules exclude the compiler, resulting in a broken published package.

1 open issue
What changed in this PR

Hardens PR-build publishing by validating extracted package directories and publishing from those directories instead of downloaded tarballs.

Changes:

  • Extract archives into an empty staging directory and validate file types, package metadata, and version formats.
  • Restrict manifest fields to an explicit allowlist.
  • Stop publishing on validation failures and disable npm lifecycle scripts.
File Description
tools/​scripts/​validate-pr-build.mjs Extracts and validates package trees, then outputs directories in publish order.
.github/​workflows/​pr-build.yml Stages extracted packages, propagates validation failures, and publishes directories with scripts disabled.

Review effort: Balanced

Comment on lines +251 to 253
for packageDir in "${toPublish[@]}"; do
npm publish "$packageDir" --access public --tag pr --ignore-scripts
done

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No, all this can break is to make the published thing broken, not contain anything weird.

And again, this is belt and suspenders, if we are running this, we already trust it

@jakebailey
Jake Bailey (jakebailey) added this pull request to the merge queue Nov 17, 2026
Merged via the queue into microsoft:main with commit c823de7 Nov 17, 2026
61 of 63 checks passed
@jakebailey
Jake Bailey (jakebailey) deleted the pr-build-extracted-validation branch November 17, 2026 20:00
@github-project-automation github-project-automation Bot moved this from Needs merge to Done in PR Backlog Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants