Skip to content

fix(marketplace): origin-check every marketplace resolution entry point - #3976

Closed
Daniel Meppiel (danielmeppiel) wants to merge 2 commits into
mainfrom
danielmeppiel-origin-check-entry-points-3959
Closed

Daniel Meppiel (danielmeppiel) wants to merge 2 commits into
mainfrom
danielmeppiel-origin-check-entry-points-3959

Conversation

@danielmeppiel

Copy link
Copy Markdown
Collaborator

TL;DR

#3912 made apm update fail closed when a marketplace alias is rebound to another catalog, but three other entry points still resolved through the rebound alias unchecked. apm install <plugin>@<alias> (project and -g) appended a second entry and overwrote the deployed skill with the new catalog's bytes. apm outdated silently compared against the new catalog. Every marketplace resolution entry point now runs the #3912 origin check before any catalog I/O, and a static guard enumerates them.

Fixes #3959

Description

Reproduced on main a532989 with the real CLI (probes from the 0.37 red-team pass, now tests/integration/test_marketplace_origin_entry_points_lifecycle.py). After apm marketplace add <catalog-B> --name company:

  • apm install example-plugin@company exited 0, appended a second git: entry and lock row, and replaced the deployed skill with catalog B's. apm install --frozen then failed with "missing from apm.lock.yaml".
  • apm install -g example-plugin@company did the same at user scope.
  • apm outdated exited 0 and reported against catalog B.

Root cause. Only deps/apm_resolver.py::_resolve_marketplace_dep called require_locked_catalog_origin. The CLI intercept in commands/install.py::_resolve_package_references called resolve_marketplace_plugin and admit_marketplace_resolution but never the origin check. commands/outdated.py::_check_marketplace_ref fetched get_marketplace_by_name(dep.discovered_via) directly.

Issue and approved scope

Issue: Fixes #3959

Human scope-approval comment: #3959 (comment) (apm-scope:v1, approver and review contact Daniel Meppiel (@danielmeppiel); eligibility.cjs reports record-present).

Does this PR complete the issue? Yes. No new lock fields, no registration UX changes.

Type of change

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

Approach

Entry point Change
commands/install.py _resolve_package_references (CLI plugin@alias, project and -g) Calls require_locked_catalog_origin(alias, plugin, <scoped lockfile>) before resolve_marketplace_plugin. The conflict becomes a validation failure with the #3912 message; the command exits 1 before any manifest, lock or deployment write.
commands/outdated.py _check_marketplace_ref Calls the new row-level owner require_locked_row_origin(dep) before the catalog fetch. On a conflict the row shows origin-conflict (never compared against the new catalog), the #3912 message is printed, and the command exits 1.
commands/uninstall/engine.py registry fallback Same check; a conflict falls back to the apm.yml match, as other lookup failures already do.
deps/apm_resolver.py Unchanged (already checked).
commands/view.py _display_marketplace_plugin Listed exemption: a read-only display of what the alias names now; it never reads or writes apm.lock.yaml.

marketplace/catalog_origin.py stays the single owner. require_locked_catalog_origin now delegates per row to require_locked_row_origin, so both paths share one comparison.

Guard. marketplace-integrations-catalog-origin now holds an explicit _ORIGIN_ENTRY_POINTS table (path, function, origin check, first catalog call). Each entry must call its check before catalog I/O. Any resolve_marketplace_plugin call site outside the table or the exemption list is a violation, so a new entry point cannot ship unchecked.

Trade-offs

  • apm outdated now exits 1 on a rebind. The scope asks for fail-closed behaviour, and a 0 exit would let CI treat a silently switched catalog as healthy. The other rows still render; only the exit code and the error line change.
  • apm view plugin@alias is exempt. It answers "what does this alias name now?" and has no lock association to check against. The exemption is written into the guard with its reason, so it cannot grow silently.
  • The scoped lockfile is read inside the install intercept rather than passed in as a parameter, which keeps the install signature under the argument limit. get_apm_dir(scope) already follows --root and -g.

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality

Scenario evidence

# Scenario Principle(s) Test Type
1 After a rebind, apm install plugin@alias fails closed naming both origins; apm.yml, lock and deployed bytes unchanged Secure by default tests/integration/test_marketplace_origin_entry_points_lifecycle.py::test_rebound_alias_fails_closed_on_cli_install_and_outdated[project] (fails on main) e2e
2 Same at user scope (-g) Secure by default ...[global] (fails on main) e2e
3 apm outdated refuses to compare against the rebound catalog and exits 1 naming both origins Governed by policy same tests (outdated step) e2e
4 apm install --frozen keeps replaying the lock after the refused install Governed by policy same tests (frozen step) e2e
5 Row-level owner refuses a rebound alias and accepts legacy rows Secure by default tests/unit/marketplace/test_catalog_origin.py::test_row_level_check_refuses_a_rebound_alias_and_accepts_legacy_rows unit
6 Dropping the check from any entry point, or adding an unregistered resolver call, is a violation Governed by policy tests/integration/test_architecture_marketplace_locked_evidence.py::test_every_marketplace_entry_point_requires_the_origin_check, ::test_an_unregistered_marketplace_resolution_entry_point_is_a_violation component

Validation results will be added once the local and CI runs complete.

How to test

  • APM_E2E_TESTS=1 APM_BINARY_PATH=.venv/bin/apm uv run --extra dev pytest tests/integration/test_marketplace_origin_entry_points_lifecycle.py -p no:xdist

Changelog

  • One line under ## [Unreleased] in CHANGELOG.md (Fixed).
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

  • Spec edit
  • Manifest edit
  • Test edit
  • CONFORMANCE.{md,json} regenerated
  • N/A -- no OpenAPM-observable behaviour change (CLI safety check only).

Co-authored-by: Copilot [email protected]

#3912 made `apm update` fail closed on a rebound marketplace alias, but the
CLI `plugin@alias` install intercept (project and -g) and `apm outdated`
resolved through the rebound alias without the check: install appended a
second entry and overwrote the deployed skill from the new catalog, and
outdated silently compared against it.

- commands/install.py: the plugin@alias intercept calls
  require_locked_catalog_origin with the scoped lockfile before any
  catalog I/O; a rebind fails closed naming both origins.
- commands/outdated.py: rows go through the new row-level owner
  require_locked_row_origin; a rebind shows `origin-conflict`, prints the
  #3912 message and exits 1, without comparing against the new catalog.
- uninstall registry fallback checks the origin too.
- Guard: marketplace-integrations-catalog-origin lists every entry point
  (origin check before catalog I/O) and fails on any unregistered
  resolve_marketplace_plugin caller; `apm view` is a listed read-only
  exemption.

Closes #3959

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 19:08

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 origin check can be bypassed when only legacy apm.lock exists, and eager lockfile reads turn non-marketplace dry-run warnings into failures.

2 open issues
What changed in this PR

This PR extends the marketplace origin protection introduced for apm update to additional resolution paths, preventing a rebound alias from silently selecting another catalog.

Changes:

  • Adds shared origin checks to positional installs, outdated checks, and uninstall registry fallback.
  • Reports origin-conflict and exits with code 1 when apm outdated detects a rebound alias.
  • Adds architecture guards, regression coverage, and documentation for the expanded protection.
File Description
tests/​unit/​marketplace/​test_catalog_origin.py Tests row-level conflicts and legacy origin-less rows.
tests/​integration/​test_marketplace_origin_entry_points_lifecycle.py Covers project/global refusal and frozen replay.
tests/​integration/​test_architecture_marketplace_locked_evidence.py Tests missing checks and unregistered resolution paths.
src/​apm_cli/​marketplace/​catalog_origin.py Centralizes per-row origin validation.
src/​apm_cli/​deps/​outdated_row.py Adds diagnostic error storage.
src/​apm_cli/​commands/​uninstall/​engine.py Checks origin before registry fallback.
src/​apm_cli/​commands/​outdated.py Reports origin conflicts and returns failure.
src/​apm_cli/​commands/​install.py Reads scoped lock evidence before marketplace resolution.
scripts/​architecture_linter/​checks/​marketplace_locked_evidence.py Registers checked entry points and the view exemption.
packages/​apm-guide/​.apm/​skills/​apm-usage/​dependencies.md Documents expanded origin-check behavior.
packages/​apm-guide/​.apm/​skills/​apm-usage/​commands.md Documents outdated conflict status and exit code.
docs/​src/​content/​docs/​reference/​cli/​outdated.md Describes origin conflicts and failure conditions.
docs/​src/​content/​docs/​reference/​cli/​marketplace.md Clarifies commands affected by alias rebinding.
docs/​src/​content/​docs/​consumer/​installing-from-marketplaces.md Updates consumer guidance on rebound aliases.
CHANGELOG.md Records the user-visible safety fix.
.apm/​architecture/​owners/​marketplace-plugins.json Updates canonical ownership and consumer coverage.

Review effort: Balanced

Comment on lines +218 to +220
from ..core.scope import InstallScope, get_apm_dir

return LockFile.read(get_lockfile_path(get_apm_dir(scope or InstallScope.PROJECT)))
updated_packages_out=updated_packages,
protocol_pref=protocol_pref,
allow_protocol_fallback=allow_protocol_fallback,
existing_lockfile=_scoped_lockfile(scope),
@danielmeppiel

Copy link
Copy Markdown
Collaborator Author

Superseded by #3988 (the #3983 umbrella, 0.37 owner hardening). This branch's fix and tests were harvested into #3988, which routes the change through its canonical owner with a closed-world guard. Closing in favour of #3988.

Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 19, 2026
* fix(lockfile): stamp the running APM on every substantive lock write (#3962)

Harvested from #3977.

Co-authored-by: Copilot App <[email protected]>

* fix(bundle): warn when a bundle's lockfile was written by a newer APM (#3963)

Harvested from #3978.

Co-authored-by: Copilot App <[email protected]>

* fix(marketplace): origin-check every marketplace resolution entry point (#3959)

Harvested from #3976; the positional install reads the lock lazily.

Co-authored-by: Copilot App <[email protected]>

* fix(install): preview object-form marketplace dependencies in --dry-run (#3960)

Harvested from #3973.

Co-authored-by: Copilot App <[email protected]>

* fix(prune): keep object-form marketplace dependencies (#3960)

Harvested from #3974.

Co-authored-by: Copilot App <[email protected]>

* fix(install): retire a local bundle's MCP servers when a reinstall drops them (#3956)

Harvested from #3975.

Co-authored-by: Copilot App <[email protected]>

* fix(update,audit): honour the current executables decision after apm deny (#3958)

Harvested from #3981.

Co-authored-by: Copilot App <[email protected]>

* fix(approve): correct the remediation after apm deny; approve clears a same-store deny (#3957)

Harvested from #3979.

Co-authored-by: Copilot App <[email protected]>

* fix(approve): match package names exactly and refuse ambiguous names

A partial name could grant or deny execution for another package.

Co-authored-by: Copilot App <[email protected]>

* fix(pack): never ship APM-managed root .mcp.json servers (#3966)

Harvested from #3971.

Co-authored-by: Copilot App <[email protected]>

* fix(install): the trust owner reads the scope manifest, so -g honours executables: (#3954)

exec_trust_context_for_project takes the manifest file instead of deriving
apm.yml from a caller-chosen root; -g resolves APM_HOME/apm.yml through
core.scope.get_manifest_path. A closed-world guard registers every caller.
Supersedes #3969 and keeps its lifecycle test.

Co-authored-by: Copilot App <[email protected]>

* fix(deps): deps update and lock --update revalidate marketplaces (#3961)

Every caller of the shared install entry now runs inside a registered
catalog-freshness envelope; the guard is closed-world.

Co-authored-by: Copilot App <[email protected]>

* fix(lifecycle): lifecycle test --execute fires through the script gate

APM_NO_SCRIPTS, org executables.deny_all and project script trust now apply;
LifecycleScriptRunner is built only by build_runner_from_context, guarded
closed-world by the new lifecycle-script-firing-gate owner.

Co-authored-by: Copilot App <[email protected]>

* test(approve): exact and unambiguous approve/deny matching

Co-authored-by: Copilot App <[email protected]>

* fix(pack): root .mcp.json reads exclude APM-managed servers by default (#3966)

The only opt-out is a dependency's own authored .mcp.json; a closed-world
guard refuses any other.

Co-authored-by: Copilot App <[email protected]>

* test(architecture): a bundle reinstall must reconcile its owned MCP servers (#3956)

Co-authored-by: Copilot App <[email protected]>

* test(architecture): guard object-form lock-row mapping and exact approve matching

Co-authored-by: Copilot App <[email protected]>

* fix(update): read packages as replay does; skip the policy fetch when the gate was never on (#3958)

Harvested from #3981 (b4cface, cb015e6); the trust read uses the scope manifest.

Co-authored-by: Copilot App <[email protected]>

* fix(install): -g MCP admission reads trust from APM_HOME/apm.yml (#3954)

Harvested from #3969 (5c2cab2).

Co-authored-by: Copilot App <[email protected]>

* fix(targets): apm targets honours targets: in apm.yml (#3792)

Reads the manifest restriction through the same owner install uses.

Co-authored-by: Copilot App <[email protected]>

* fix(cli): user-facing text names current keys, targets and marketplaces

- compile's no-output hint names targets:, not the deprecated target:
- pack's mismatch hint no longer suggests the deprecated pack --target
- skip messages name executables.allow instead of allowExecutables
- origin and freshness errors say marketplace, not catalog
- generated apm.yml headers and unknown-target errors stop listing vscode
- config docs show default_client: copilot

Co-authored-by: Copilot App <[email protected]>

* docs(changelog): 0.37 owner hardening entries; ruff fixes

apm-spec-waiver: consistency fixes route callers through existing owners; no new or changed normative requirement

Co-authored-by: Copilot App <[email protected]>

* docs(changelog): reference #3988

apm-spec-waiver: consistency fixes route callers through existing owners; no new or changed normative requirement

Co-authored-by: Copilot App <[email protected]>

* fix(update): converge the mixed-type reconcile; pin probe boundaries

Harvested from #3981 (6cd7b3a, delta panel fold). Only a denied row
with mixed per-type verdicts reconciles, so common partial approvals keep
the no-change short-circuit; the probe catches only unreadable-package
errors instead of every exception. Tests pin when the probe fetches
policy, mixed detection on a two-type package, and every unavailable
policy outcome. Test calls pass the scope manifest path, per #3988's
trust-owner signature.

Refs #3958

apm-spec-waiver: consistency fixes route callers through existing owners; no new or changed normative requirement

Co-authored-by: danielmeppiel <[email protected]>
Co-authored-by: Copilot App <[email protected]>

* test: align tests with the 0.37 contracts this PR introduces

CI on 913336a was red on tests that encoded the pre-#3983 contracts:
- lifecycle test --execute now fires through the script gate, so the
  firing test trusts the project first and the old bypass trap now
  asserts untrusted scripts are withheld (mutation-break: restoring an
  ungated LifecycleScriptRunner fails it);
- codex native admission names executables.allow, not allowExecutables;
- a real LockFile.write stamps the running CLI (#3962), so the heal
  eligibility fixture pins the stamp it means to write;
- pack no longer ships servers apm install renders from apm.yml (#3966),
  so the bundle MCP retire test authors its server in .mcp.json.

Addresses merge-worker CI triage on #3988.

apm-spec-waiver: consistency fixes route callers through existing owners; no new or changed normative requirement

Co-authored-by: Copilot App <[email protected]>

* fix(uninstall): origin-check marketplace rows from the batch index

require_locked_catalog_origin rescanned lockfile.dependencies for every
package, breaking the uninstall single-traversal guarantee. The batch
index now also keys rows case-insensitively, and the registry fallback
checks each matched row through require_locked_row_origin before any
catalog I/O. Adds a rebound-alias regression test (mutation-break:
dropping the check lets the catalog be reached) and moves the origin
entry-point guard and its mutation case to the new call.

Refs #3959

apm-spec-waiver: consistency fixes route callers through existing owners; no new or changed normative requirement

Co-authored-by: Copilot App <[email protected]>

* fix(pack): warn when root .mcp.json servers APM manages are left out

A Claude plugin silently lost the MCP servers apm install renders from
apm.yml. Pack now names them and the remedy; the CHANGELOG moves the
#3966 line to upgrade notes with that migration, pack.md and apm-usage
say the same, and the unrelated #3931 line this PR dropped is restored.

Addresses panel follow-ups (supply-chain, doc-writer) on #3988.

apm-spec-waiver: consistency fixes route callers through existing owners; no new or changed normative requirement

Co-authored-by: Copilot App <[email protected]>

* fix: fold Copilot review on trust and origin owners

- install x@alias reads a legacy apm.lock for the origin check, through
  the read-only lockfile resolver, so a rebound alias fails closed before
  migration (Copilot on commands/install.py:220);
- the update probe reuses POLICY_RESOLUTION_FAILURE_OUTCOMES, so an
  incomplete policy chain also forces the guarded install path
  (Copilot on commands/update.py:148);
- apm approve clears a same-store deny stored under any spelling the
  deny ladder matches (URL, host, case), via canonical_exec_identity
  (Copilot on commands/approve.py:817).

Each fix has a regression test proven by mutation-break.

Refs #3957, #3958, #3959

apm-spec-waiver: consistency fixes route callers through existing owners; no new or changed normative requirement

Co-authored-by: Copilot App <[email protected]>

* fix(targets): singular target: all lists the install set as active

restriction() folds singular `target: all` to None (auto-detect), but
install expands it to the stable install set, so apm targets showed every
target inactive. Expand it through target_catalog.expand_all("install").
Regression test proven by mutation-break.

Addresses Copilot on commands/targets.py:32.

Refs #3792

apm-spec-waiver: consistency fixes route callers through existing owners; no new or changed normative requirement

Co-authored-by: Copilot App <[email protected]>

* perf: share one marketplace index across dry-run and prune lookups

locked_marketplace_row and locked_marketplace_form were called per
declaration without an index, so LockFile.get_dependency rebuilt the
marketplace index each time (O(M*N)). Both callers now build it once,
as the reachability walk already does.

Addresses Copilot on install/dry_run_plan.py:33 and install/orphans.py:46.

Refs #3960

apm-spec-waiver: consistency fixes route callers through existing owners; no new or changed normative requirement

Co-authored-by: Copilot App <[email protected]>

* test(architecture): track the shared marketplace index in mutation cases

The object-form mutation cases match the exact call text, which now
passes the shared marketplace index.

Co-authored-by: Copilot App <[email protected]>

* fix(pack): ship apm.yml MCP declarations; only root claims hide root entries

Red team qa-prA-5 and qa-prA-6 on #3988, both regressions against main:

- A Claude bundle and plugin.json dropped the producer's own apm.yml MCP
  servers: they were read only from the rendered root .mcp.json, which pack
  now withholds. collect_mcp_servers projects the root manifest's
  self-defined declarations from apm.yml values (never the rendered copy),
  through the existing credential stripping, so output is byte-identical
  before and after apm install. The pack warning remains only for
  APM-managed servers apm.yml does not define (a dependency's).
- apm_managed_mcp_names unioned lock claims from every runtime, so a
  Cursor-only claim on `docs` hid an authored root `docs` from Claude and
  Codex. Only claims whose runtime writes root .mcp.json count, read
  through the factory (ClientFactory.project_destination_is_root_mcp_json,
  side-effect free); unknown runtimes and unplaced aggregate names stay
  managed (conservative).

The new unit tests fail on e9d6c9d and pass here; the bundle-retire
lifecycle test is back to its apm.yml declaration; test_pack_mcp_ownership
asserts byte identity, no header or secret values and no reference to the
rendered file; the pack guard requires both owner rules, with a standalone
mutation test. CHANGELOG, pack.md and apm-usage updated.

apm-spec-waiver: consistency fixes route callers through existing owners; no new or changed normative requirement

Co-authored-by: Copilot App <[email protected]>

---------

Co-authored-by: danielmeppiel <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Takeshi Masukawa (takeaship) pushed a commit to takeaship/apm that referenced this pull request Nov 20, 2026
…nt (microsoft#3959)

Harvested from microsoft#3976; the positional install reads the lock lazily.

Co-authored-by: Copilot App <[email protected]>
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] apm install plugin@alias bypasses the marketplace origin check after an alias rebind

2 participants