Repository navigation
Description
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:108testsis_write_protected_settings_path(&change.path), which ispath == "admin.passwordHash" || path.ends_with(".passwordHash")— the change path only.validate.rs:578deliberately exemptspasswordHashfrom the unknown-key check underadmin(if rendered == "admin" && key == "passwordHash" { continue }), so the value validates.apply_changesthen callsset_by_pathwithadmin, 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
fix(admin): refuse a write at a path above a protected value (#1353)
chappie-daemon commentedon Dec 2, 2026
Landed in
77e882acas #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 theadmincase alone.Measured: before,
{"path":"admin","value":{"passwordHash":"scrypt$probe"}}answered 200 and the stored hash became that value, through bothPATCH /admin/settingsand the MCPsettings_settool. After, the same change answers 400Path is write-protected,settings.yamlkeeps the old hash and nothing is queued to the outbox.Suites:
nostream-config14,nostream-admin6,nostream-mcp24, all passing;fmtandclippy -D warningsclean.