forked from foundry-rs/foundry
-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
dependenciesPull requests that update a dependency filePull requests that update a dependency filedocumentationImprovements or additions to documentationImprovements or additions to documentationduplicateThis issue or pull request already existsThis issue or pull request already existsenhancementNew feature or requestNew feature or requestgithub_actionsPull requests that update GitHub Actions codePull requests that update GitHub Actions codegood first issueGood for newcomersGood for newcomersrustPull requests that update rust codePull requests that update rust code
Description
Reviewer's Guide
Strengthens npm publish GitHub Actions workflow against artifact poisoning by enforcing artifact path containment within the isolated artifact directory and cross-checking artifact package.json metadata with the source package before publishing.
Sequence diagram for npm publish workflow artifact validation
sequenceDiagram
actor Developer
participant GitHubRunner
participant WorkflowJob
participant ArtifactStore
participant ArtifactDir
participant NpmRegistry
Developer->>GitHubRunner: Push tag / trigger release
GitHubRunner->>WorkflowJob: Start npm publish job
WorkflowJob->>ArtifactStore: Download build artifact
ArtifactStore-->>ArtifactDir: Extract to isolated temp directory ARTIFACT_DIR
WorkflowJob->>ArtifactDir: Compute EXPECTED_ARTIFACT_PATH
WorkflowJob->>ArtifactDir: realpath EXPECTED_ARTIFACT_PATH -> ABS_ARTIFACT_PATH
WorkflowJob->>ArtifactDir: realpath ARTIFACT_DIR -> ABS_ARTIFACT_ROOT
WorkflowJob->>WorkflowJob: Check ABS_ARTIFACT_PATH under ABS_ARTIFACT_ROOT
alt Artifact path escapes root
WorkflowJob-->>Developer: Fail job (artifact path outside isolated root)
else Artifact contained
WorkflowJob->>WorkflowJob: Verify PACKAGE_DIR and EXPECTED_ARTIFACT_PATH exist
WorkflowJob->>ArtifactDir: Check for EXPECTED_ARTIFACT_PATH/package.json
alt package.json present in artifact
WorkflowJob->>WorkflowJob: Extract SRC_NAME, SRC_VERSION from PACKAGE_DIR/package.json
WorkflowJob->>WorkflowJob: Extract ART_NAME, ART_VERSION from EXPECTED_ARTIFACT_PATH/package.json
WorkflowJob->>WorkflowJob: Compare names and versions
alt Name or version mismatch
WorkflowJob-->>Developer: Fail job (refuse to publish)
else Metadata matches
WorkflowJob->>NpmRegistry: Run publish.mjs with PACKAGE_DIR
NpmRegistry-->>WorkflowJob: Publish result
end
else No artifact package.json
WorkflowJob->>NpmRegistry: Run publish.mjs with PACKAGE_DIR
NpmRegistry-->>WorkflowJob: Publish result
end
end
WorkflowJob-->>Developer: Report publish success or failure
Flow diagram for artifact path and package.json validation before npm publish
flowchart TD
start([Start publish step])
compute_paths[Compute EXPECTED_ARTIFACT_PATH and ARTIFACT_DIR]
realpath_paths[Resolve ABS_ARTIFACT_PATH and ABS_ARTIFACT_ROOT with realpath]
check_containment{Is ABS_ARTIFACT_PATH under ABS_ARTIFACT_ROOT?}
fail_escape[[Fail: artifact path outside isolated artifact root]]
check_package_dir{Does PACKAGE_DIR exist and contain package.json?}
fail_package_dir[[Fail: invalid PACKAGE_DIR or missing package.json]]
check_artifact_dir{Does EXPECTED_ARTIFACT_PATH exist and is directory?}
fail_artifact_dir[[Fail: artifact directory missing]]
has_artifact_pkg{Does EXPECTED_ARTIFACT_PATH/package.json exist?}
use_jq{Is jq available?}
parse_with_jq[Parse name and version from both package.json files using jq]
parse_with_grep[Parse name and version from both package.json files using grep/sed]
compare_names{SRC_NAME and ART_NAME both set and differ?}
fail_name[[Fail: artifact package name does not match source]]
compare_versions{SRC_VERSION and ART_VERSION both set and differ?}
fail_version[[Fail: artifact package version does not match source]]
publish[Run bun ./scripts/publish.mjs PACKAGE_DIR]
end_step([End step])
start --> compute_paths --> realpath_paths --> check_containment
check_containment -- No --> fail_escape --> end_step
check_containment -- Yes --> check_package_dir
check_package_dir -- No --> fail_package_dir --> end_step
check_package_dir -- Yes --> check_artifact_dir
check_artifact_dir -- No --> fail_artifact_dir --> end_step
check_artifact_dir -- Yes --> has_artifact_pkg
has_artifact_pkg -- No --> publish --> end_step
has_artifact_pkg -- Yes --> use_jq
use_jq -- Yes --> parse_with_jq --> compare_names
use_jq -- No --> parse_with_grep --> compare_names
compare_names -- Yes --> fail_name --> end_step
compare_names -- No --> compare_versions
compare_versions -- Yes --> fail_version --> end_step
compare_versions -- No --> publish --> end_step
File-Level Changes
| Change | Details | Files |
|---|---|---|
| Add realpath-based containment check to ensure the resolved artifact directory cannot escape the isolated artifacts root before publishing. |
|
.github/workflows/npm.yml |
| Validate artifact package.json name and version against the source package.json prior to running the publish script. |
|
.github/workflows/npm.yml |
Tips and commands
Interacting with Sourcery
- Trigger a new review: Comment
@sourcery-ai reviewon the pull request. - Continue discussions: Reply directly to Sourcery's review comments.
- Generate a GitHub issue from a review comment: Ask Sourcery to create an
issue from a review comment by replying to it. You can also reply to a
review comment with@sourcery-ai issueto create an issue from it. - Generate a pull request title: Write
@sourcery-aianywhere in the pull
request title to generate a title at any time. You can also comment
@sourcery-ai titleon the pull request to (re-)generate the title at any time. - Generate a pull request summary: Write
@sourcery-ai summaryanywhere in
the pull request body to generate a PR summary at any time exactly where you
want it. You can also comment@sourcery-ai summaryon the pull request to
(re-)generate the summary at any time. - Generate reviewer's guide: Comment
@sourcery-ai guideon the pull
request to (re-)generate the reviewer's guide at any time. - Resolve all Sourcery comments: Comment
@sourcery-ai resolveon the
pull request to resolve all Sourcery comments. Useful if you've already
addressed all the comments and don't want to see them anymore. - Dismiss all Sourcery reviews: Comment
@sourcery-ai dismisson the pull
request to dismiss all existing Sourcery reviews. Especially useful if you
want to start fresh with a new review - don't forget to comment
@sourcery-ai reviewto trigger a new review!
Customizing Your Experience
Access your dashboard to:
- Enable or disable review features such as the Sourcery-generated pull request
summary, the reviewer's guide, and others. - Change the review language.
- Add, remove or edit custom review instructions.
- Adjust other review settings.
Getting Help
- Contact our support team for questions or feedback.
- Visit our documentation for detailed guides and information.
- Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.
Originally posted by @sourcery-ai[bot] in #373 (comment)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
dependenciesPull requests that update a dependency filePull requests that update a dependency filedocumentationImprovements or additions to documentationImprovements or additions to documentationduplicateThis issue or pull request already existsThis issue or pull request already existsenhancementNew feature or requestNew feature or requestgithub_actionsPull requests that update GitHub Actions codePull requests that update GitHub Actions codegood first issueGood for newcomersGood for newcomersrustPull requests that update rust codePull requests that update rust code
Projects
Status
Backlog
Status
Todo