Repository navigation
fix(marketplace): apply the #1326 dependency-confusion check on every install path - #3923
Conversation
… install path Route apm install NAME@MARKETPLACE, apm.yml marketplace entries, transitive marketplace dependencies and apm update through one admission owner, marketplace/dependency_confusion.py admit_marketplace_resolution, before any fetch or write. A new architecture guard rejects resolver calls that skip it. Closes #3913 Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Install admission occurs after ambiguous public-repository tag lookup and possible pin-cache writes, while the architecture linter can falsely accept admission inside an uncalled nested helper.
2 open issues
What changed in this PR
This PR addresses #3913 by centralizing the #1326 marketplace dependency-confusion refusal and extending it beyond CLI arguments to manifest entries, transitive dependencies, and updates.
Changes:
- Adds a shared admission function and routes both install resolution paths through it.
- Registers an architecture guard and adds lifecycle and mutation coverage.
- Updates user documentation and the changelog to describe the expanded refusal.
| File | Description |
|---|---|
tests/unit/scripts/test_architecture_runner.py |
Adds the guard to the rule inventory. |
tests/integration/test_marketplace_dependency_confusion_lifecycle.py |
Tests refusal across four CLI scenarios. |
tests/integration/test_architecture_owner_rule_mutations.py |
Adds an admission-removal mutation. |
tests/integration/test_architecture_marketplace_dependency_confusion.py |
Tests guard enforcement against bypasses. |
src/apm_cli/marketplace/resolver.py |
Updates comments and docstrings to name the admission owner. |
src/apm_cli/marketplace/dependency_confusion.py |
Defines the shared refusal function and exception. |
src/apm_cli/deps/apm_resolver.py |
Adds admission after marketplace resolution. |
src/apm_cli/commands/install.py |
Replaces the inline refusal with the shared function. |
scripts/architecture_linter/checks/marketplace_integration_analyzers.py |
Registers the new rule. |
scripts/architecture_linter/checks/marketplace_dependency_confusion.py |
Checks admission calls and sentinel ownership. |
packages/apm-guide/.apm/skills/apm-usage/package-authoring.md |
Updates publisher guidance on host qualification. |
packages/apm-guide/.apm/skills/apm-usage/dependencies.md |
Documents refusal across dependency paths. |
docs/src/content/docs/producer/publish-to-a-marketplace.md |
Explains expanded publisher-facing refusal behavior. |
docs/src/content/docs/consumer/installing-from-marketplaces.md |
Documents the consumer refusal and remedy. |
CHANGELOG.md |
Records the expanded protection. |
.apm/architecture/owners/marketplace-plugins.json |
Registers the canonical admission owner and guard. |
Review effort: Balanced
Skip the version-range tag lookup for a resolution admission will refuse, so no request reaches the ambiguous package remote. Move DependencyConfusionError into marketplace/errors.py and name it in the resolver's except tuple. Harden the static guard against nested defs, getattr reads, aliased imports and direct resolve_plugin_source calls. Serve the enterprise catalog from an SSH-registered Git fixture so apm update revalidates offline (#3910) and reaches admission; add a version-range case, a host-qualified positive control and unit traps. Narrow docs to type: github sources and fix the producer example. Addresses panel follow-ups (python-architect, test-coverage-expert, supply-chain-security-expert, doc-writer) on #3923. Co-authored-by: Copilot App <[email protected]>
…ep-confusion-3913 # Conflicts: # packages/apm-guide/.apm/skills/apm-usage/dependencies.md
Plain installs replay lock rows without the catalog (#3911), so apm update is the remediation for entries an older APM locked; a lifecycle case locks a host-qualified entry, flips the catalog to the bare form, and asserts apm update refuses without touching the lock. Document the remediation. Addresses CEO follow-up on #3923. Co-authored-by: Copilot App <[email protected]>
…ep-confusion-3913 # Conflicts: # src/apm_cli/deps/apm_resolver.py # src/apm_cli/marketplace/errors.py
APM Review Panel:
|
| Persona | B | R | N | Takeaway |
|---|---|---|---|---|
| Python Architect | 0 | 3 | 2 | The single owner is set up correctly and all four install paths go through it. The guard heuristic had gaps, and lock replay and the error type needed attention. |
| Test Coverage Expert | 1 | 1 | 1 | The apm update lifecycle case failed after the #3910 rebase. Also missing: a resolver-path positive control and unit traps. All folded. |
| Supply Chain Security Expert | 0 | 3 | 1 | Admission fires on every resolve path. Found: a range-lookup probe (folded), the git-subdir sentinel gap and older lock rows on replay (both deferred). |
| Doc Writer | 0 | 2 | 1 | The "before any fetch" overclaim and the type: git example were fixed, and the CHANGELOG form was corrected. |
| Performance Expert | 0 | 0 | 0 | No regression: admission is O(1) per dependency, and the lint rule is linear at about 66ms warm. |
B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.
Top 4 follow-ups
- [Supply Chain Security Expert] Open a follow-up issue to detect or re-admit confused lock rows that an older APM wrote, during [BUG] apm install re-resolves marketplace dependencies on every run instead of replaying the lockfile #3911 replay, without catalog I/O on the hot path.
apm updateremediation is already documented and tested here. -- Two panelists raised this independently, and on a secure-by-default surface the attacker commit may already be pinned. - [Test Coverage Expert] Confirm Lifecycle Smoke and the full CI matrix are green on d368b50 before merge. -- The blocking finding was a red test, and local runs are not the CI signal.
- [Supply Chain Security Expert] Open a follow-up issue to extend the [BUG] Cross-repo bare repo on *.ghe.com marketplace silently resolves at github.com on validation success (dependency-confusion vector) #1326 sentinel to git-subdir dict sources with a bare cross-repo
repoon *.ghe.com marketplaces. -- This gap predates the PR, and the docs now limit the claim totype: github. - [Python Architect] After fix(marketplace): record catalog origin in the lock; fail closed on rebound aliases #3917 settles, revisit a resolve-and-admit facade that keeps fix(marketplace): record catalog origin in the lock; fail closed on rebound aliases #3917's ordering guard intact. -- That would make admission structurally impossible to skip instead of lint-enforced.
Architecture
flowchart TD
A1["apm install NAME@MKT"] --> B1["commands/install.py _resolve_package_references"]
A2["apm install with apm.yml marketplace entry"] --> C0["APMDependencyResolver.build_dependency_tree"]
A3["transitive marketplace dep"] --> C0
A4["apm update"] --> C0
C0 --> C1["_resolve_marketplace_or_record_error"]
C1 --> C2["_resolve_marketplace_dep"]
C2 -->|"locked and not update"| R0["#3911 lock replay"]
C2 -->|"otherwise"| O0["#3912 require_locked_catalog_origin"]
O0 --> P0["resolver.resolve_marketplace_plugin"]
B1 --> P0
P0 --> P1["sentinel computed; version lookup skipped when set"]
P1 --> G["dependency_confusion.admit_marketplace_resolution"]
G -->|"risk is None"| OK["download, deploy, lock"]
G -->|"risk set"| E["DependencyConfusionError"]
E --> Z["refused: no apm.yml, lock or apm_modules writes"]
S["lint: marketplace-integrations-dependency-confusion"] -.->|"admit must follow resolve in same function"| B1
S -.-> C2
Recommendation
Merge once CI is green on d368b50. Every in-scope finding was folded with a regression trap. Five refusal paths have real-CLI lifecycle cases (cli, apm-yml, apm-yml-range, transitive, update). Four of them fail on main and all pass at head. A host-qualified positive control installs, and an apm update case refuses a locked entry whose catalog turned ambiguous. The owner-touch gate verifies at the exact head with four touched owners covered by passing functional tests. Track the older-lock replay issue first, ahead of the git-subdir widening.
Full per-persona findings
Python Architect
- [recommended] The static guard matched by name and line order (nested defs, getattr reads,
resolve_plugin_source, aliased imports). Folded in 7512da7 with bypass tests. - [recommended] fix(install): replay locked marketplace dependencies from the lockfile #3915 lock-first replay may skip admission for locks an older APM wrote. Deferred, with the
apm updateremediation tested in e3868d1. - [recommended]
DependencyConfusionErrorshould live in marketplace/errors.py on the MarketplaceError root. Folded in 7512da7. - [nit] The owner JSON repeated the consumer list. Folded.
- [nit] A resolve-and-admit facade could replace the line-order rule after fix(marketplace): record catalog origin in the lock; fail closed on rebound aliases #3917. Deferred.
Test Coverage Expert
- [blocking] The apm update lifecycle case failed at d317758: forced catalog revalidation fails offline before admission. Folded in 7512da7 (SSH-registered catalog fixture).
- [recommended] No real-CLI positive control for a host-qualified repo on the resolver path. Folded:
test_host_qualified_marketplace_entry_still_installs. - [nit] No unit traps for admission and resolver error recording. Folded:
tests/unit/marketplace/test_dependency_confusion.py.
Supply Chain Security Expert
- [recommended] A version-range entry probed the bare github.com remote before refusal. Folded in 7512da7, with the
[apm-yml-range]lifecycle case proven by mutation-break. - [recommended] git-subdir bare cross-repo sources are not flagged. Deferred (changes [BUG] Cross-repo bare repo on *.ghe.com marketplace silently resolves at github.com on validation success (dependency-confusion vector) #1326 detection); docs narrowed to
type: github. - [recommended] Older confused lock rows are replayed without admission after fix(install): replay locked marketplace dependencies from the lockfile #3915. Deferred, with
apm updateremediation documented and tested. - [nit] Aliased-import blind spot in the guard. Folded.
Doc Writer
- [recommended] "Before fetching or writing anything" overclaimed. Folded: now "before contacting the package repository or writing any file".
- [recommended] The producer example used the unsupported
type: git. Folded: nowtype: github. - [nit] CHANGELOG form. Folded:
(closes #3913, #3923).
Performance Expert
No findings.
Copilot signals reviewed
This panel is advisory. It does not block merge. Re-apply the
panel-review label after addressing feedback to re-run.
Generated by autopilot-pr-review-worker. This comment is AI-generated and may contain errors.


fix(marketplace): apply the #1326 dependency-confusion check on every install path
Description
The #1326 refusal for bare cross-repo
repo:entries on*.ghe.commarketplaces ran only forapm install NAME@MARKETPLACE. Marketplace entries inapm.yml, transitive marketplace dependencies, andapm updateskipped it, so APM cloned and installed whatever an attacker had staged under that name on publicgithub.com. This PR adds one owner,admit_marketplace_resolution, which every install path calls. An architecture guard rejects any new resolver call that does not go through it.Important
Reproduced with the real CLI on
main: withgithub.com/acme/toolsstaged by the "attacker",apm install(apm.yml entry), a transitive declaration, andapm updateeach installed the attacker's skill ([+] acme/tools #main … Skill integrated -> .agents/skills/). With this PR, all four paths refuse before any fetch or write.Problem (WHY)
commands/install.py_resolve_package_referenceswas the only reader ofMarketplacePluginResolution.cross_repo_misconfig_risk.deps/apm_resolver.py_resolve_marketplace_depignored it, and that resolver handles apm.yml entries, transitive declarations, andapm update.owner/repocanonical fell back togithub.com, and APM cloned it with the user's token in scope.resolve_marketplace_pluginfrom skipping the check as well.Why these matter: the repository's architecture rule says, verbatim, "Every durable decision ... has exactly ONE canonical owner. Every call site routes THROUGH that owner" (
.github/instructions/architecture.instructions.md). The #1326 decision had one consumer, and the other install paths silently bypassed it.Approach (WHAT)
marketplace/dependency_confusion.py:admit_marketplace_resolution(resolution)raisesDependencyConfusionError(aValueError) with the existing #1326 message.commands/install.py(CLI argument) anddeps/apm_resolver.py_resolve_marketplace_dep(apm.yml, transitive,apm update) call it immediately afterresolve_marketplace_plugin.marketplace-integrations-dependency-confusion. It fails when a function callsresolve_marketplace_pluginwithout admitting the result afterwards, when code outside the owner reads the sentinel, or when either required install path loses its admission call.Implementation (HOW)
src/apm_cli/marketplace/dependency_confusion.py(new): the owner. It is the only reader of the sentinel. The refusal text is byte-identical to the old CLI message, so the existing unit tests still hold.src/apm_cli/commands/install.py: replaces the 25-line inline gate with one call. The surroundingexcept Exceptionalready turns the raise into aninvalid_outcomesentry plusvalidation_fail, so CLI behaviour is unchanged.src/apm_cli/deps/apm_resolver.py: one call afterresolve_marketplace_plugin. The existing_resolve_marketplace_or_record_errorrecords theValueError, and_fail_on_resolution_errorsaborts before download.src/apm_cli/marketplace/resolver.py: docstrings and comments only; they now name the owner.scripts/architecture_linter/checks/marketplace_dependency_confusion.py(new) and registration inmarketplace_integration_analyzers.py,.apm/architecture/owners/marketplace-plugins.json(recordmarketplace-dependency-confusion-admission),tests/unit/scripts/test_architecture_runner.py(frozen inventory), andtests/integration/test_architecture_owner_rule_mutations.py(MutationCase).consumer/installing-from-marketplaces.md,producer/publish-to-a-marketplace.md,apm-usage/dependencies.md,apm-usage/package-authoring.md.Trade-offs
resolve_marketplace_plugin, not a wrapper. The alternative was aresolve_admitted_…wrapper. It would have hidden theresolve_marketplace_plugincall that fix(marketplace): record catalog origin in the lock; fail closed on rebound aliases #3917's ordering guard (require_locked_catalog_originbefore the catalog call) keys on, and it would have collided with fix(install): replay locked marketplace dependencies from the lockfile #3915's lock-replay block. Both sibling owners agreed to this hook point. The static guard enforces that the call cannot be skipped.resolve_marketplace_plugin.apm view(display) andapm uninstall(maps an installed entry back to its lock key) also resolve, and they must keep working for an entry that is now refused. The guard names them in an explicit read-only allowlist.commands/view.pypassespluginpositionally toresolve_marketplace_plugin, so its resolved-canonical display always fails silently. I left it alone; it is not part of this scope.Benefits
apm update) now refuse the [BUG] Cross-repo bare repo on *.ghe.com marketplace silently resolves at github.com on validation success (dependency-confusion vector) #1326 vector. Onmainit was 1 of 4.apm.ymlis byte-identical afterwards, and noapm.lock.yaml, noapm_modules/acme, and no deployed file is created.cross_repo_misconfig_riskinstead of an inline copy, and a static guard that keeps it that way.Validation
Scenario evidence
apm install NAME@MKTrefuses the bare cross-repo entry, with no writetests/integration/test_marketplace_dependency_confusion_lifecycle.py::…[cli]apm installwith an apm.yml marketplace entry refuses, with no write or fetch…[apm-yml](fails onmain: attacker skill installed)…[transitive](fails onmain)apm updaterefuses, with no write or fetch…[update](fails onmain)tests/integration/test_architecture_marketplace_dependency_confusion.py, MutationCasemarketplace-integrations-dependency-confusionCommands and results
How to test
APM_E2E_TESTS=1 APM_BINARY_PATH=$PWD/.venv/bin/apm uv run --extra dev pytest tests/integration/test_marketplace_dependency_confusion_lifecycle.py -p no:xdist: 4 pass.src/apm_cli/deps/apm_resolver.pytomainand re-run:[apm-yml],[transitive]and[update]fail with the attacker skill installed.admit_marketplace_resolution(resolution)line inapm_resolver.pyand runbash scripts/lint-architecture-boundaries.sh:marketplace-integrations-dependency-confusionfails.Issue and approved scope
Issue: Fixes #3913
Human scope-approval comment: #3913 (comment) (apm-scope:v1, Daniel Meppiel (@danielmeppiel))
This PR completes the issue: CLI add, apm.yml object form, transitive dependencies and
apm updateeach have a lifecycle test, and a static guard blocks a second admission path. Marketplace registration and policy semantics are unchanged.Type of change
Testing
Changelog
## [Unreleased]inCHANGELOG.md: user-visible effect first, 25 words or fewer, ending with(#PR); breaking changes only under upgrade notes; no Highlights; see.github/instructions/changelog.instructions.md.Spec conformance (OpenAPM v0.1)
If this PR changes behaviour that an OpenAPM v0.1
req-XXXcovers,confirm the three-step ritual in the
development guide:
docs/src/content/docs/specs/openapm-v0.1.mdupdated(new/changed
<a id="req-XXX"></a>anchor + prose + Appendix Crow).
docs/src/content/docs/specs/manifests/openapm-v0.1.requirements.ymlupdated.
@pytest.mark.req("req-XXX")test undertests/spec_conformance/added or extended.CONFORMANCE.{md,json}regenerated viauv run --extra dev python -m tests.spec_conformance.gen_statementand committed.
Co-authored-by: Copilot [email protected]