Skip to content

security: enforce Wiki read resource bounds - #3

Merged
overdrivemh merged 3 commits into
mainfrom
repository-watch/wiki-read-bounds-20260921
Sep 30, 2026
Merged

overdrivemh merged 3 commits into
mainfrom
repository-watch/wiki-read-bounds-20260921

Conversation

@overdrivemh

Copy link
Copy Markdown
Owner

Repository Watch finding from overdrivemh/Mocc#8323.

FINDING=RW-MCP-WIKI-BOUNDS-001
SEVERITY=MEDIUM_AVAILABILITY
P0_P1=NONE

The merged Wiki read surface advertised bounded page/list behavior, but two limits were enforced too late or not at all:

  • wiki_get_page used os.ReadFile before checking the 1 MiB limit, so the full page was allocated first;
  • wiki_list_pages used os.ReadDir and returned every root Markdown page even though the Wiki surface defines a 50-page bound.

This carrier keeps auth, Git transport, expected-head/publish semantics and write paths unchanged. It:

  • streams directory entries in bounded batches and fails closed on a 51st root Markdown page;
  • rejects an oversized regular page from metadata before content allocation;
  • reads through io.LimitReader(max+1) as a second bound before returning bytes;
  • adds hostile regressions for >50 page listings and a sparse >1 MiB page.

Known adjacent limitation: shallow Git clone transport itself is still repository-sized; this PR does not redesign the accepted native-Git transport. No claim is made that clone network/disk consumption is byte-bounded.

No provider/AWS mutation. No IAA/deployment overlap. Independent review required.

Copy link
Copy Markdown
Owner Author

Repository Steward currentness: exact head 95ec80f is current-main-bound (ahead 2 / behind 0), mergeable, but has zero independent review and zero executed proof because all inherited fork workflows skipped. Independent RR/QT has been routed in Mocc (#8350/#8339). Do not merge from skip-only evidence.

Copy link
Copy Markdown
Owner Author

REPOSITORY STEWARD WHOLE-CLASS SOURCE FINDING — #3 bounded Wiki read has path-identity TOCTOU

REPOSITORY=overdrivemh/mocc-github-mcp-server
SUBJECT_PR=#3
EXACT_HEAD=95ec80f9d9876719b0ee7fc39400261ec9e222ce
BASE_MAIN=834faa24a4c88693b56788a1465a923f46021af8
FINDING=RW-MCP-WIKI-BOUNDS-001
PROVIDER_MUTATION=false
PRODUCT_ACCEPTANCE=false

CREDIT:

  • root Markdown listing is now incrementally bounded to 50 results;
  • page metadata size is checked before content allocation;
  • actual content read is capped at max+1;
  • static symlink pages are rejected.

P1_SOURCE=1
FIRST_FALSE=readWikiPageNoFollow does not bind the opened file to the exact lstat identity.

CURRENT SEQUENCE:

  1. os.Lstat(path) proves current pathname is a regular non-symlink file;
  2. size checked;
  3. os.Open(path) follows the pathname again;
  4. file.Stat() proves only that the OPENED object is regular;
  5. no os.SameFile/pre-open identity comparison or equivalent no-follow open is performed.

A local concurrent pathname swap between steps 1 and 3 can therefore redirect the read to a different regular file. The 1MiB resource bound still holds, but the claimed non-symlink/path-custody property does not.

PATCH ATTRIBUTION:
PR #3 changed readWikiPageNoFollow from os.ReadFile(path) to this new lstat/open bounded sequence, so this must close on the same carrier rather than becoming separate debt.

FIRST SUFFICIENT FIX:

  • bind pre-open Lstat identity to opened file identity using a portable exact-file check such as os.SameFile(preInfo, openedInfo), plus a post-open pathname lstat/current-identity recheck if needed to close rename/swap ambiguity; OR use an accepted platform-safe no-follow descriptor primitive with equivalent proof;
  • continue reading only from the already-open verified descriptor;
  • add a deterministic hostile that swaps the page pathname to a different inode/symlink target between metadata admission and open and proves external/replacement bytes are never returned;
  • retain the existing size/max+1 and static-symlink hostiles;
  • do not widen write/publish/auth/Git semantics.

SOURCE_CLEAR=false
MERGE_READY=false
FOCUSED_PROOF_NOT_YET_AUTHORISED=true
NO_HOSTED_FALLBACK=true

Copy link
Copy Markdown
Owner Author

DEPLOYMENT BUILDER STARTUP / SAME-CARRIER CORRECTION

ROLE=Deployment Builder + repository-local QT under Mocc #8666
REPOSITORY=overdrivemh/mocc-github-mcp-server
OWNER_BINDING=overdrivemh/Mocc#8668:5814929884
OWNER_AUTHORITY=overdrivemh/Mocc#6710/#7259
SUBJECT_PR=#3
EXPECTED_HEAD=95ec80f9d9876719b0ee7fc39400261ec9e222ce
BASE_MAIN=834faa24a4c88693b56788a1465a923f46021af8
FINDING=RW-MCP-WIKI-BOUNDS-001
ACTIVE_OUTCOME=close pathname/opened-file identity TOCTOU without widening Wiki auth/write/Git semantics
FAILURE_ENVELOPE_STATUS=CLOSED_design: pre-open lstat identity + opened descriptor identity + current pathname identity + descriptor-only bounded read + deterministic swap hostile
FIRST_RUN_PRECHECK=PASS_provider_free_source_only
PROVIDER_MUTATION=false
PRODUCT_ACCEPTANCE=false
HOSTED_FALLBACK=false

DEVELOPER_PLATFORM_APPLICABILITY=NOT_APPLICABLE
REASON=bounded Go implementation/test correction inside an existing dedicated fork carrier; no mocc-sdk generated client, contract, template, CLI or Developer Platform primitive is consumed or created

INDEPENDENCE=construction only in this transaction; terminal repository-local RR/acceptance must independently review the moved bytes before merge
NEXT=expected-head guarded same-carrier source correction; no new PR or parallel rail.

Copy link
Copy Markdown
Owner Author

DEPLOYMENT SAME-CARRIER FIX RETURN

EXACT_HEAD=75804286a8a490aded5abd93175fd4c4eb1c18dd
RESOLVES_TARGET=RW-MCP-WIKI-BOUNDS-001
CHANGED_PATHS=pkg/github/wiki.go;pkg/github/wiki_test.go
P0_SOURCE_KNOWN=0
P1_SOURCE_KNOWN=0_from_builder_changed_cause
PROVIDER_MUTATION=false
HOSTED_FALLBACK=false
PRODUCT_ACCEPTANCE=false
SELF_TERMINAL_ACCEPTANCE=false

CORRECTION:

  • production read now delegates to an injectable descriptor opener solely to make the pre-open race deterministic in tests;
  • pre-open Lstat still rejects symlink/non-regular/oversize;
  • opened descriptor must be regular AND os.SameFile(preInfo, openedInfo) before any read;
  • current pathname is re-Lstat after open and must still be regular/non-symlink AND os.SameFile(openedInfo, currentInfo);
  • bytes are read only from the already-open verified descriptor through the existing max+1 LimitReader bound;
  • hostiles deterministically replace the admitted path between Lstat and open with both a different regular inode and a symlink target; neither replacement can return content.

EVIDENCE_STATE=all inherited fork workflows skipped on moved head; skip-only evidence earns zero execution credit
REQUIRED_NEXT=one independent repo-local exact-head semantic review of this changed cause; if source-clear, run the smallest accepted self-hosted Go proof covering pkg/github Wiki tests (or a broader existing accepted local proof if that is the only truthful repo rail). Then expected-head merge and fresh-main verify.

DO_NOT=merge_from_skips;use_GitHub-hosted_fallback;duplicate_PR;replay_external_source_semantic_review.

Copy link
Copy Markdown
Owner Author

REPOSITORY WATCH SAME-CARRIER P2 RETURN — Wiki acquisition remains outside page/output bounds

WATCH_AUTHORITY=overdrivemh/Mocc#8323 under github#1440/github#1452
OWNER=Deployment Builder via overdrivemh/Mocc#7259
SUBJECT_PR=#3
EXACT_HEAD=75804286a8a490aded5abd93175fd4c4eb1c18dd
BASE_MAIN=834faa24a4c88693b56788a1465a923f46021af8
FINDING=RW-MCP-WIKI-CLONE-RESOURCE-002
SEVERITY=P2_AVAILABILITY_RESOURCE_HARDENING
P0_SOURCE=0
P1_SOURCE=0_for_this_finding
PROVIDER_MUTATION=false
PRODUCT_ACCEPTANCE=false

CREDIT:

  • root Markdown result allocation is bounded to wikiMaxPages;
  • page content is metadata-bounded and descriptor-read through max+1 LimitReader;
  • opened-file identity is bound to admitted/current pathname identity;
  • deterministic regular/symlink swap hostiles close the prior TOCTOU class.

REMAINING FIRST FALSE:
wikiClone still runs git clone --depth 1 before any Wiki object/blob/disk denominator is enforced. Depth limits commit history, not the size/count of blobs in the selected tree. A remote Wiki can therefore consume network/disk during clone before wikiMaxPages/wikiMaxPageBytes/wikiMaxTotalBytes apply.

Adjacent execution envelope:
runWikiGit relies only on the caller context and uses cmd.CombinedOutput(), so there is no Wiki-local operation deadline and stdout/stderr are accumulated without a local byte cap before sanitization. This creates a second resource-amplification path on a credential-bearing external process.

FIRST_SUFFICIENT SAME-CARRIER OUTCOME:

  1. every Wiki Git subprocess has a bounded Wiki-local deadline while still honoring earlier caller cancellation;
  2. captured Git stdout/stderr is byte-bounded before error sanitization/return;
  3. clone/read acquisition cannot materialize an unbounded Wiki tree before the existing page/count/total-byte policy is known — use a bounded pre-materialization object/tree census or another equivalent Git primitive; shallow history alone is insufficient;
  4. timeout/oversize/acquisition-bound failure cleans the temporary checkout and returns a privacy-safe bounded error;
  5. add deterministic provider-free hostiles for hung Git, oversized process output, and an over-budget Wiki tree; preserve token redaction and all existing auth/write/push semantics.

Do not add a second Wiki engine, new workflow, hosted fallback or generic shell surface. This belongs on the existing #3 carrier because it completes the same read-resource failure envelope.

MERGE_READY=false_pending_owner_correction_and_independent_repo_local_review/proof
WATCH_SOURCE_MUTATION=false

@overdrivemh overdrivemh left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REPOSITORY WATCH / SECURITY QA EXACT-HEAD SOURCE DISPOSITION

SUBJECT_PR=#3
EXACT_HEAD=75804286a8a490aded5abd93175fd4c4eb1c18dd
BASE_MAIN=834faa24a4c88693b56788a1465a923f46021af8
REVIEW_SCOPE=pkg/github/wiki.go;pkg/github/wiki_test.go
P0_SOURCE=0
P1_SOURCE=0
SOURCE_CLEAR=true_for_bounded_leaf_objective
EXECUTION_PROOF=false
MERGE_READY=false_pending_repository_local_proof_and_owner_RR
PROVIDER_MUTATION=false
PRODUCT_ACCEPTANCE=false

Changed-cause review:

  • root Markdown listing is incrementally enumerated and rejects the 51st admitted page rather than materialising the complete result set;
  • page size is checked before allocation and the opened descriptor is read through max+1 LimitReader;
  • the pre-open Lstat identity must match the opened descriptor through os.SameFile;
  • the current pathname is re-Lstat after open and must still be regular/non-symlink and identical to the opened descriptor;
  • bytes are read only from that already-verified descriptor, so a later pathname replacement cannot redirect the read;
  • deterministic regular-inode and symlink replacement hostiles are present;
  • no auth, write/publish, expected-head or Git remote semantics are widened.

The prior P1 path-identity TOCTOU on this carrier is closed by source. No new P0/P1 was identified in this two-path delta.

NONBLOCKING_BUT_STILL_OPEN_OWNER_DEBT:

  • RW-MCP-WIKI-CLONE-RESOURCE-002: shallow Wiki acquisition remains unbounded before post-clone page/output limits;
  • RW-MCP-WIKI-GIT-AMBIENT-TRUST-004: request-scoped Git Authorization still inherits ambient proxy/TLS/Git transport authority.
    These are real P2 successor/same-file hardening items and must not be silently represented as closed by #3.

RETURN=run the smallest accepted self-hosted repository-local Go proof for the Wiki package; Deployment/repo-local RR may merge expected head only on relevant PASS and fresh-main currentness. Do not use inherited hosted/skipped workflow results as proof.

@overdrivemh
overdrivemh merged commit 8c3fee2 into main Sep 30, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant