Skip to content

fix(wpm): reject cached-index source injection + index hash ledger; loopback proxy fallback opt-in (issues #1176 #1177) - #1179

Merged
caomengxuan666 merged 1 commit into
mainfrom
fix/1176-1177-wpm-supply-chain
Oct 13, 2026
Merged

caomengxuan666 merged 1 commit into
mainfrom
fix/1176-1177-wpm-supply-chain

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #1176
Closes #1177

#1176 (P1) — cached-index sources no longer trusted, index ledger added

merged_sources folded the sources array declared inside the cached index into the candidate set (wpm.cpp:318-352), so one poisoned fetch persistently injected new download locations; the injected index also carries the artifact sha256 values, so the poison was fully self-consistent. Candidate sources are now the built-in registry + user_sources only (merged_sources(root), wpm.cpp:318-338); new mirrors must come from the user (wpm source add / config) or the shipped built-in registry.

wpm index update additionally keeps a supply-chain ledger (wpm.cpp:3336-3361):

#1177 (P2) — loopback proxy fallback is opt-in

After a direct-connection failure wpm probed 127.0.0.1:7897/7890/7891/7892/7893/10808/10809 by default (wpm.cpp:1228-1240/1325-1341); an unprivileged local process listening there could serve both index and artifacts past the index's own sha256 checks. Now:

  • loopback_fallback_allowed(root) reads allow_loopback_fallback from .wpm/config.json, default false (wpm.cpp:1229-1239);
  • http_get lost its silent default-on argument — every call site (artifact download, manifest fetch, index fetch) states the policy explicitly;
  • explicit --proxy / proxy env vars remain the trusted paths, semantics unchanged.

Compatibility matrix

Scenario Before After
Default user, no config direct → (dead) loopback probing direct → urlmon fallback; no loopback probing
wpm source add / user_sources mirrors merged unchanged, still merged and prioritized
preferred_source pin / --source / wpm source use tried first, fallback preserved unchanged
region=cn auto selection + probe regional reorder unchanged (ordering only; never consults cache-declared sources)
--proxy / env proxy users forced proxy, no loopback probe unchanged
Config allow_loopback_fallback: true n/a loopback probing as before (opt-in)
Sources declared in a fetched index merged + persisted (poisonable) ignored
Poisoned mirror swaps index content on non-preferred source silent warning + hash recorded

Tests (tests/unit/wpm, 58/58 pass; 4 new)

  • wpm_rejects_sources_declared_in_cached_index — self-consistent poison (index + matching artifact sha256 over file://, offline) smuggled only via the cached index: source list excludes it, index update fetches from the legitimate source, install evil-tool exits 1 and nothing lands in usr/bin.
  • wpm_index_update_records_hash_and_warns_on_nonpreferred_change — ledger seeded on first update; preferred source dies, mirror serves changed content → warning + new hash + last_success_source; same-hash refresh stays quiet.
  • wpm_index_update_json_records_index_sha256 — 64-hex index_sha256 in the --json payload.
  • wpm_loopback_proxy_fallback_off_by_default_opt_in_via_config — dead artifact URL: default output contains no loopback proxy trace; with allow_loopback_fallback: true the probe trace appears.

Verified: scripts/build-with-vs.ps1 (Debug, x64) builds clean; ctest -R wpm 58/58; clang-format run over the tree (only this PR's files carry changes). CHANGELOG + DOCS/en/wpm_guide.md updated.

…back proxy fallback opt-in (issues #1176, #1177)

#1176 (P1): merged_sources folded sources declared inside the CACHED index
into the candidate set, so one poisoned fetch persistently injected new
download locations whose artifacts self-consistently passed the index's own
sha256 checks. Candidate sources are now the built-in registry plus
user_sources only; mirrors must come from the user (wpm source add /
config) or the shipped built-in registry. update_index additionally keeps a
supply-chain ledger: last_success_source (already recorded) plus the
SHA-256 of the persisted index (last_index_sha256), prints a warning when
the index content changes while being served from a non-preferred source,
and the --json payload carries index_sha256.

#1177 (P2): after a direct-connection failure wpm probed loopback proxy
ports 127.0.0.1:7897/7890/7891/7892/7893/10808/10809 by default; any
unprivileged local process listening there could serve both index and
artifacts. The probe is now opt-in via allow_loopback_fallback=true in
.wpm/config.json (default false); http_get lost its default-on argument so
every call site states the policy explicitly. --proxy and proxy environment
variables remain the trusted paths and are unchanged.

Compatibility: explicitly configured user_sources / preferred_source /
--proxy / region=cn auto-selection all keep working (ordering and fallback
semantics untouched; only cache-declared sources stopped being trusted).

Regression tests (tests/unit/wpm): self-consistent poisoned cache index
rejected end-to-end (source list, index update, install), ledger + warning
on non-preferred content change + quiet same-hash refresh, index_sha256 in
the --json payload, loopback probing absent by default and present when
opted in. wpm group: 58/58 pass.

Note: per AGENTS.md the new i18n keys (command.wpm.warn.index_changed_nonpreferred)
need a follow-up catalog sync in unixwin/winuxcmd-i18n; English fallbacks
land here first.
@caomengxuan666
caomengxuan666 merged commit e1de365 into main Oct 13, 2026
8 checks passed
caomengxuan666 added a commit that referenced this pull request Oct 13, 2026
…on (#1180)

- seq: 64 KiB chunked stdout + integral to_chars fast path, measured
  332ms -> ~45ms on 100k lines, byte stream unchanged (#1173).
- du, sed: POSIX drive-form operands resolve through the shared operand
  boundary like grep/wc/head/find (#1174).
- Retitle [Unreleased] to [1.1.7] (date slot left for the release
  commit). The #1176/#1177 wpm supply-chain entries were already
  recorded by #1179 itself.
@caomengxuan666
caomengxuan666 deleted the fix/1176-1177-wpm-supply-chain branch October 14, 2026 04:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant