Skip to content

security: a write at a path above admin.passwordHash replaces it — the rewrite drops the console's protected-value comparison #1352

Done

Description

@chappie-daemon

PATCH /admin/settings refuses a change whose path is write-protected, but not one whose path contains a protected value. Writing the parent path replaces admin.passwordHash, which is exactly what main's console refuses.

Reached through the MCP settings_set tool too: it calls the same patch_settings::apply, so a token holding only the write scope can rewrite the admin credential.

Measured

On cb22d716 (rewrite/main), through TestServer in crates/nostream-admin:

PATCH /admin/settings {"path": "admin", "value": {"passwordHash": "scrypt$probe-min"}}
-> 200 {"ok":true,"path":"admin","reload":"hot-reload","value":{"passwordHash":"***"}}
settings.yaml before: scrypt:BwcHBwcH…:r5daXU05…
settings.yaml after:  scrypt$probe-min

One change, no other fields. The echo redacts the value (***), so the response looks correct while the write lands.

Why

  • patch_settings.rs:108 tests is_write_protected_settings_path(&change.path), which is path == "admin.passwordHash" || path.ends_with(".passwordHash") — the change path only.
  • validate.rs:578 deliberately exempts passwordHash from the unknown-key check under admin (if rendered == "admin" && key == "passwordHash" { continue }), so the value validates.
  • apply_changes then calls set_by_path with admin, which replaces the whole subtree, hash included.

main guards this by intent, not by path: patch-settings-controller.ts:92-100 compares the protected values before and after the change (changedWriteProtectedSettingsPaths(protectedBefore, nextUserSettings)) and refuses when any of them moved. Its comment names this exact case — "replacing admin, which holds admin.passwordHash". The Rust port kept the request-path guard and dropped the document comparison.

Impact

An admin-console session can rewrite the credential it authenticated with, and — the sharper one — an MCP token scoped to write (server.rs:53) can do it without any console session, turning settings-write access into admin-console control. #1022 lists the console's write protection as a control; the rewrite's own guard reads as if it holds it.

Fix direction

Port the comparison: collect the write-protected paths and their values from the stored user document before the change and from the merged document after it, and refuse with Path is write-protected when any differs — added or removed ones included. That covers admin, deeper containers and any future protected path at once, instead of enumerating ancestors. A Rust collect_write_protected_settings + changed_write_protected_settings_paths, and one test asserting the measured case answers 400 and leaves the stored hash unchanged.

Happy to take it if wanted.

Activity

  1. added
    security
    rewrite
    rust
    on Dec 2, 2026
  2. added a commit that references this issue on Dec 2, 2026
    77e882a
  3. chappie-daemon commented on Dec 2, 2026

    @chappie-daemon
    CollaboratorAuthor

    Landed in 77e882ac as #1353.

    The guard now reads what is protected from the stored user document and from the document as it would be saved, and refuses any write that moves one, as main's console does (changedWriteProtectedSettingsPaths, patch-settings-controller.ts:92-100). It covers a value that is added or removed as well as one that changes, and walks lists, so a write above any protected path is caught rather than the admin case alone.

    Measured: before, {"path":"admin","value":{"passwordHash":"scrypt$probe"}} answered 200 and the stored hash became that value, through both PATCH /admin/settings and the MCP settings_set tool. After, the same change answers 400 Path is write-protected, settings.yaml keeps the old hash and nothing is queued to the outbox.

    Suites: nostream-config 14, nostream-admin 6, nostream-mcp 24, all passing; fmt and clippy -D warnings clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    rewriterustsecurity

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions