Skip to content

fix(marketplace): apply the #1326 dependency-confusion check on every install path - #3923

Merged
Daniel Meppiel (danielmeppiel) merged 6 commits into
mainfrom
danielmeppiel-fix-marketplace-dep-confusion-3913
Nov 19, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 6 commits into
mainfrom
danielmeppiel-fix-marketplace-dep-confusion-3913

Conversation

@danielmeppiel

Copy link
Copy Markdown
Collaborator

fix(marketplace): apply the #1326 dependency-confusion check on every install path

Description

The #1326 refusal for bare cross-repo repo: entries on *.ghe.com marketplaces ran only for apm install NAME@MARKETPLACE. Marketplace entries in apm.yml, transitive marketplace dependencies, and apm update skipped it, so APM cloned and installed whatever an attacker had staged under that name on public github.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: with github.com/acme/tools staged by the "attacker", apm install (apm.yml entry), a transitive declaration, and apm update each 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_references was the only reader of MarketplacePluginResolution.cross_repo_misconfig_risk. deps/apm_resolver.py _resolve_marketplace_dep ignored it, and that resolver handles apm.yml entries, transitive declarations, and apm update.
  • On those paths, the bare owner/repo canonical fell back to github.com, and APM cloned it with the user's token in scope.
  • [!] Nothing stopped a fourth caller of resolve_marketplace_plugin from 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)

# Fix
1 New owner marketplace/dependency_confusion.py: admit_marketplace_resolution(resolution) raises DependencyConfusionError (a ValueError) with the existing #1326 message.
2 commands/install.py (CLI argument) and deps/apm_resolver.py _resolve_marketplace_dep (apm.yml, transitive, apm update) call it immediately after resolve_marketplace_plugin.
3 New architecture rule marketplace-integrations-dependency-confusion. It fails when a function calls resolve_marketplace_plugin without admitting the result afterwards, when code outside the owner reads the sentinel, or when either required install path loses its admission call.
4 Docs and the apm-usage skill state that the refusal covers every consumer path.

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 surrounding except Exception already turns the raise into an invalid_outcomes entry plus validation_fail, so CLI behaviour is unchanged.
  • src/apm_cli/deps/apm_resolver.py: one call after resolve_marketplace_plugin. The existing _resolve_marketplace_or_record_error records the ValueError, and _fail_on_resolution_errors aborts 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 in marketplace_integration_analyzers.py, .apm/architecture/owners/marketplace-plugins.json (record marketplace-dependency-confusion-admission), tests/unit/scripts/test_architecture_runner.py (frozen inventory), and tests/integration/test_architecture_owner_rule_mutations.py (MutationCase).
  • Docs: consumer/installing-from-marketplaces.md, producer/publish-to-a-marketplace.md, apm-usage/dependencies.md, apm-usage/package-authoring.md.

Trade-offs

  • Admission as a separate call after resolve_marketplace_plugin, not a wrapper. The alternative was a resolve_admitted_… wrapper. It would have hidden the resolve_marketplace_plugin call that fix(marketplace): record catalog origin in the lock; fail closed on rebound aliases #3917's ordering guard (require_locked_catalog_origin before 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.
  • The check is not inside resolve_marketplace_plugin. apm view (display) and apm 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.
  • Lock replay (fix(install): replay locked marketplace dependencies from the lockfile #3915) skips admission. A replayed row was admitted when it was locked. Lock rows written by an older APM before this fix are not re-checked; that is out of scope.
  • Pre-existing: commands/view.py passes plugin positionally to resolve_marketplace_plugin, so its resolved-canonical display always fails silently. I left it alone; it is not part of this scope.

Benefits

  1. 4 of 4 consumer paths (CLI argument, apm.yml entry, transitive, 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. On main it was 1 of 4.
  2. The refusal happens before any write: apm.yml is byte-identical afterwards, and no apm.lock.yaml, no apm_modules/acme, and no deployed file is created.
  3. One reader of cross_repo_misconfig_risk instead of an inline copy, and a static guard that keeps it that way.
  4. No new manifest or lockfile fields and no spec change. CLI wording is unchanged.

Validation

Scenario evidence

Scenario Principle Test
apm install NAME@MKT refuses the bare cross-repo entry, with no write Secure by default tests/integration/test_marketplace_dependency_confusion_lifecycle.py::…[cli]
apm install with an apm.yml marketplace entry refuses, with no write or fetch Secure by default …[apm-yml] (fails on main: attacker skill installed)
Transitive marketplace declaration refuses, with no write or fetch Secure by default …[transitive] (fails on main)
apm update refuses, with no write or fetch Secure by default, Governed by policy …[update] (fails on main)
A new resolver call site cannot skip admission Governed by policy tests/integration/test_architecture_marketplace_dependency_confusion.py, MutationCase marketplace-integrations-dependency-confusion
Commands and results
# Lifecycle, real CLI binary (APM_E2E_TESTS=1 APM_BINARY_PATH=.venv/bin/apm)
pytest tests/integration/test_marketplace_dependency_confusion_lifecycle.py -p no:xdist
4 passed in 5.10s
# same tests with src/ reverted to main
3 failed, 1 passed  (apm-yml, transitive, update: "[+] acme/tools #main ... Skill integrated")

pytest tests/integration/test_architecture_marketplace_dependency_confusion.py tests/unit/scripts/test_architecture_runner.py \
  tests/unit/commands/test_install_resolve_refs.py tests/unit/marketplace tests/integration/test_ghe_marketplace_install_e2e.py \
  tests/integration/test_wave8_copilot_resolver_coverage.py tests/integration/test_wave7_policy_registry_coverage.py -n 8
2355 passed in 206.42s

pytest tests/integration/test_architecture_owner_rule_mutations.py -k "dependency-confusion or covers_every_registry or case_order or report_nothing_before"
6 passed in 60.66s

pytest tests/unit/deps tests/unit/install tests/unit/commands -n 8
6920 passed, 7 failed -- all 7 in tests/unit/install/test_unix_install_ownership.py, which tests install.sh (not touched here); left to CI

# CI-mirror lint (ruff 0.15.12, matches uv.lock)
ruff check src/ tests/ scripts/lint_architecture_boundaries.py scripts/architecture_linter/ scripts/windows_native_symlink_probe_entry.py   -> All checks passed!
ruff format --check (same paths)                                                                   -> 2424 files already formatted
pylint R0801 (src/apm_cli/ + scripts)                                                              -> 10.00/10
bash scripts/lint-auth-signals.sh                                                                  -> [+] auth-signal lint clean
bash scripts/lint-architecture-boundaries.sh                                                       -> exit 0
BASE_REF=origin/main bash tests/spec_conformance/mode_b_detector.sh                                -> 1 substantive added line (< 20); OK

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.
  • Revert src/apm_cli/deps/apm_resolver.py to main and re-run: [apm-yml], [transitive] and [update] fail with the attacker skill installed.
  • Delete the admit_marketplace_resolution(resolution) line in apm_resolver.py and run bash scripts/lint-architecture-boundaries.sh: marketplace-integrations-dependency-confusion fails.

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 update each have a lifecycle test, and a static guard blocks a second admission path. Marketplace registration and policy semantics are unchanged.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass (installer-script suite left to CI; see Validation)
  • Added tests for new functionality (if applicable)

Changelog

  • One line in one section under ## [Unreleased] in CHANGELOG.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.
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

If this PR changes behaviour that an OpenAPM v0.1 req-XXX covers,
confirm the three-step ritual in the
development guide:

  • Spec edit: docs/src/content/docs/specs/openapm-v0.1.md updated
    (new/changed <a id="req-XXX"></a> anchor + prose + Appendix C
    row).
  • Manifest edit: docs/src/content/docs/specs/manifests/openapm-v0.1.requirements.yml
    updated.
  • Test edit: a @pytest.mark.req("req-XXX") test under
    tests/spec_conformance/ added or extended.
  • CONFORMANCE.{md,json} regenerated via
    uv run --extra dev python -m tests.spec_conformance.gen_statement
    and committed.
  • N/A -- this PR does not change OpenAPM-observable behaviour.

Co-authored-by: Copilot [email protected]

… 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]>
@danielmeppiel Daniel Meppiel (danielmeppiel) added this to the 0.37.0 milestone Nov 19, 2026
Copilot AI balanced review requested due to automatic review settings November 19, 2026 12:59

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

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

Comment thread src/apm_cli/deps/apm_resolver.py Resolved
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
@danielmeppiel

Copy link
Copy Markdown
Collaborator Author

APM Review Panel: ship_with_followups

Closes the #1326 dependency-confusion bypass. Every marketplace install path (CLI add, apm.yml, transitive, apm update) now goes through one admission gate, with a lint guard against a second path.

panel-mode=full; personas=python-architect,test-coverage-expert,supply-chain-security-expert (adhoc: PR closes a dependency-confusion vector),doc-writer,performance-expert,apm-ceo

cc Sergio Sisternes (@sergio-sisternes-epam) -- a fresh advisory pass is ready for your review.

This is a secure-by-default fix with a real exploit behind it. On main, the real-CLI repro installed an attacker skill staged at a bare github.com/acme/tools through three of the four paths: the apm.yml entry, a transitive dependency and apm update. Only CLI add refused it. The PR gives the check one owner (admit_marketplace_resolution), sends every path through it, and adds a static guard so a new path cannot skip it. Panelists agreed on the design and disagreed only on how complete the proof was and how broad the claims were.

The strongest signal was a test-coverage finding: the apm update lifecycle case failed at d317758 after the rebase on #3910. Strict catalog revalidation failed offline before admission ran. This was folded. The fixture now registers the enterprise catalog over ssh://[email protected] through a local Git rewrite, so update reaches admission offline. The other folds:

  • Version ranges: a range entry no longer runs a tag lookup against the bare remote before the refusal (supply-chain, plus Copilot inline (a)).
  • Guard: the static guard now rejects nested-def admissions, getattr or string reads of the sentinel, aliased imports and direct resolve_plugin_source calls (architect, plus Copilot inline (b)).
  • Error type: DependencyConfusionError now sits on the MarketplaceError root and is named in the resolver's except tuple.
  • Docs: they now state only what the code guarantees, and the producer example uses type: github.

Three items were deferred as out of scope. Widening the sentinel to git-subdir changes what #1326 detects, not where it applies. A resolve-and-admit facade would move the call that #3917's ordering guard keys on. Re-checking lock rows written by an older APM during #3911 replay would need the catalog I/O that #3915 removed. That last gap carries the most residual risk, so it was partly folded: apm update re-resolves through admission, and a new lifecycle case proves it refuses a locked entry whose catalog row has since turned ambiguous. The consumer docs now name apm update as the fix.

Dissent. Nobody disputed the design. python-architect and supply-chain-security-expert both rated lock replay of older confused rows as recommended. The CEO accepts the deferral on scope, because replay is not resolution, and it is the top follow-up.

Aligned with: Secure by default (one owner, refusal before the package remote is contacted or any file is written, mutation-tested guard); governed by policy (a static guard enforces the same check on every path); portable by manifest (no new manifest or lockfile fields, no spec change); pragmatic (apm update is a one-command fix for older locks).

Panel summary

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

  1. [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 update remediation 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.
  2. [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.
  3. [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 repo on *.ghe.com marketplaces. -- This gap predates the PR, and the docs now limit the claim to type: github.
  4. [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
Loading

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

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

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: now type: github.
  • [nit] CHANGELOG form. Folded: (closes #3913, #3923).

Performance Expert

No findings.

Copilot signals reviewed

  • LEGIT: version-range tag lookup before admission (PRRT_kwDOPyZEpc65f-Of). Folded in 7512da7.
  • LEGIT: nested-def admission satisfied the guard (PRRT_kwDOPyZEpc65f-PJ). Folded in 7512da7.

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.

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.

[BUG] #1326 dependency-confusion check is skipped for marketplace entries in apm.yml and transitive marketplace dependencies

2 participants