Repository navigation
fix(security): read a wiki page file only through a row the viewer sees - #239
Open
philbert440 wants to merge 4 commits into
Open
philbert440 wants to merge 4 commits into
philbert440 wants to merge 4 commits into
Conversation
A viewer who cannot see a page row still reads the page file from the primary wiki through topic_page and the archive read, and remove_page deletes it. A visible row whose wiki scope the viewer cannot see reads the primary wiki file of the same local name. Refs #231.
page_home invented a primary-wiki home for any slug whose row the current scope could not see, and for a row whose wiki scope it could not see. The callers then read, archived, or removed the primary owner's file of that name. page_home now returns no home in both cases. topic_page falls back to the row, the archive read and recompile source return nothing, edit_page and remove_page touch nothing, and page placement refuses to write. remove_page also removes the file from the page's own wiki instead of the primary one. Recompile keeps a primary-wiki fallback for a row-less page under the maintenance scope only, where no row is hidden and the rebuilt page stays in the primary wiki. Page routing keeps its raw row lookup through page_place so its placement does not change. Fixes #231.
page_home now returns a home only for a row whose owner owns that home. A scoped row must belong to its scope's owner, or to the space for a space scope. A legacy row with no scope must belong to the primary wiki's owner: the configured owner, or else the owner of the primary scope row. A person whose primary owner is unknown gets no legacy file. Rows without a verified home serve their row text only. fold_wiki resolved nothing and used global keys as file names in the primary repository. A tidy fold of space pages could read, rewrite and delete primary files of the same name. It now resolves the parent's and each child's home first, folds by local names in the parent's own wiki, stores the parent row in its scope, and refuses a fold across wikis or of a child whose home it cannot verify. Topic sync under a person scope treated a slug as free when the row holding it was hidden, then read and committed whatever file had that local name in the target wiki. A fresh placement now refuses with a slug conflict when the file already exists, before reading or writing. page_place returns None for an invisible row, so wiki routing no longer cites a page the summary owner cannot see as a primary page. The recompile CLI queued primary wiki file names, which the worker read as global keys. It now resolves each file name to the key of the primary page that owns it, and skips a loose file whose name is another page's key. The worker recovers a rowless page only when no row holds the key, and writes it into the primary scope. Refs #231.
philbert440
force-pushed
the
fix/issue-231
branch
from
November 25, 2026 16:44
bd4e0fb to
58aa1d9
Compare
…didates The configured wiki owner took precedence over the owner recorded on the root scope. When the two disagreed, a legacy row of the configured owner read the root files of the recorded owner. RLS hides that root scope row from everyone but its owner, so the SQL check could not see the disagreement. legacy_owner now reads the recorded root owner under the maintenance scope (one fixed column) and compares it with the configured owner. If they disagree, no legacy row gets a file, and those rows serve their row text only. A new page under a person scope checked that its file was vacant by reading and parsing the file before the write synced the repository. An unparseable file returned a parse error instead of a slug conflict, and a file that the sync pulled in was overwritten. The write now goes through LockedRepository::create, which syncs and then checks that the destination path exists with symlink_metadata, without opening the file. The new page path no longer reads the existing file at all. Rowless recompile recovery accepted a missing root scope and stored an ownerless legacy row, which the worker rejects once an owner is configured. When the primary owner is known, recovery now establishes the primary scope for that owner first and stores the row in that scope with its owner. When the owner is contested, it skips the page and logs why. A single-user store with no owner recorded or configured keeps the legacy row, which the same home rule accepts under maintenance. Consolidation planned folds from every primary-wiki row, so one row with no verified home aborted the whole batch. wiki_topic_stats now applies the same home rule as fold execution (the shared homes query), logs the rows it skips, and plans folds only from verified pages. Refs #231.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
In 0.8.19 stable, a person on a shared Postgres hub must never read, write or delete another owner's wiki file. Owners, space members and maintenance must keep working. On Postgres, a viewer who could not see a page's row still read that page's file from the primary owner's wiki. #231 showed this for
topic_page. The same fallback also reached the archive read andremove_page, andremove_pagedeleted the file. Review rounds 1 and 2 found more paths that built a file path from a global key alone, or trusted an owner they had not verified.Fixes #231
Rule
Before any file access, the store resolves the page's home (scope directory and local name) from a row the caller can see. It also checks that the row's owner owns that home. If it cannot establish both, it serves the row text and opens no file, or it refuses.
Root cause
page_home(crates/memory-postgres/src/wiki_scope.rs) made up a home in the primary wiki (directory"", local name = slug) when the current scope could not see a row. It also mapped every legacy row (scope IS NULL) to the primary wiki without checking its owner. Other paths never called it.fold_wikiopened the primary repository and used global keys as file names. The recompile CLI queued file names from the primary wiki, but the worker read them as global keys.Fix
page_homereturns a home only for a visible row whose owner owns the home. A scoped row must belong to its scope's owner, or to the space for a space scope. A legacy row must belong to the primary wiki's owner.LegacyOwner, resolved byPostgresMemory::legacy_owner. It reads the owner recorded on the root scope and compares it with the configured wiki owner. If both exist and disagree, the owner is contested, and no legacy row gets a file (row text only). RLS hides a private root scope row from everyone but its owner, so this one read runs underScope::Maintenance. It reads one fixed column and takes no caller input. Each caller resolves it before it takes its own connection. If no owner is recorded or configured, only maintenance or an unscoped single-user store falls back to the primary wiki.page_homeand the consolidation stats share one query (with_homes), so planning and execution apply the same home rule.fold_wiki(tidy fold, consolidation) resolves the home of the parent and of each child before it touches git. It folds by local name in the parent's own wiki and stores the parent row in its scope. It refuses a fold across wikis, and it refuses a child whose home it cannot verify.wiki_topic_statsplans folds only from primary-wiki pages with a verified home. It logs the pages it skips, so one rejected page no longer aborts the consolidation batch.LockedRepository::create(crates/wiki-files), which syncs the repository under the writer lock and then checks whether the destination path exists withsymlink_metadata, without opening the file. If the path exists, the sync returnsSlugConflict. This matches thecreatesignature in fix(memory): stop the topic-page sweep from blanking a fresh entity page #236. When fix(memory): stop the topic-page sweep from blanking a fresh entity page #236 lands, keep onecreatewith this existence check. Maintenance keeps the old behavior of adopting an orphan file.page_placereturnsNonefor a row the caller cannot see.withinrejects that target, andoverlaidreturns no overlay for it.PostgresMemory::primary_page_key). It skips a loose file whose name is another page's key. The worker recovers a page with no row only when no row holds the key. When the primary owner is known, it first establishes that owner's primary scope (primary_scope) and stores the recovered row in that scope with its owner. When the owner is contested, it skips the page and logs why. A single-user store with no owner recorded or configured keeps the legacy row, which the same home rule accepts under maintenance (thewiki_boundedrecompile tests cover this).read_wiki_page,read_wiki_archive,topic_page,edit_pageandremove_pagekeep their round-1 behavior: with no home they serve the row only or touch nothing.SQLite is unchanged. A SQLite node serves one person.
Tests
crates/memory-postgres/tests/it/page_access.rsruns as the RLS probe role underScope::Viewer, with different prose in each row and its file:a_visible_row_in_a_hidden_scope_never_reads_the_primary_wiki: the space member gets exactly the row text, and the gateway-backed markdown must contain it. The owner gets the prose from her file.a_legacy_row_reads_the_primary_wiki_only_for_its_owner: coco's legacy row never serves phil'sdiary.md. Phil's shared legacy row still reads his file.a_legacy_row_never_reads_a_root_wiki_recorded_for_another_owner(round 2, S2): phil is the configured owner and sees his own legacy row. He gets the row text, not coco's root file.folding_space_pages_touches_only_the_space_wikianda_fold_across_wikis_is_refused.consolidation_skips_a_page_without_a_verified_home(round 2, S7): the plan leaves out coco's legacy row in the primary wiki, the valid fold runs, and the skipped row and its file stay.a_topic_sync_never_writes_over_a_file_it_has_no_row_for: the crew file and the crew repository HEAD stay unchanged.a_new_page_never_claims_an_unreadable_fileanda_new_page_never_claims_a_file_the_sync_brings_in(round 2, S3): a file that does not parse, and a file that only the repository sync pulls in from the upstream, both giveSlugConflictand stay unchanged.a_summary_cites_no_page_its_owner_cannot_see.a_recompile_targets_the_primary_wiki_page_by_its_file_name.a_restored_file_recovers_into_the_primary_owners_scopeanda_restored_file_is_skipped_while_the_primary_owner_is_contested(round 2, S5): on a database with no scopes andphilconfigured, recovery stores the row with scope and ownerphil, and phil reads the file. With the root recorded for coco andphilconfigured, recovery returns nothing and inserts no row.The six round-2 tests fail on the 58aa1d9 sources:
Proved with:
SQLX_OFFLINE=true CARGO_BUILD_JOBS=5 cargo xtask check --locked --no-nextest-list(GATE OK),cargo nextest run -j5 -p memory-postgres -p memory-sqlite -p mcp -p gateway -p rivethub -p cli -p workers --no-fail-fastagainst Postgres on a2446d3 (2124 passed, 1 skipped),cargo xtask commits origin/release/0.8.19-rc..HEAD(GATE OK), and the six round-2page_accesstests failing on the 58aa1d9 sources.