You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 7ca4c18
Browse filesBrowse the repository at this point in the historyBrowse files
fix(admin): the settings API cannot change the admin password hash through a parent path (#1231)
## Description
`PATCH /admin/settings` refuses to write `admin.passwordHash`, but
`isWriteProtectedSettingsPath` is only applied to the **path of each
request**. A request for the path `admin` passes (`admin` exists in the
default settings schema and is not itself protected), and `setByPath`
replaces the whole `admin` object, `passwordHash` included. I reproduced
it on the real route: `PATCH /settings {"path": "admin", "value": {...,
"passwordHash": <another hash>}}` answered 200 and stored the new hash.
Removing the hash (an `admin` object without it) and a batch in which
one of several changes replaces `admin` did the same.
Anyone holding a valid admin session, or a copy of its token, could
therefore set a password hash they chose, or delete it, without knowing
the current password, and the change outlives the session. This is the
same family as the session work in #1145: an admin session was meant to
be revocable and should not be able to turn itself into a permanent
credential.
- new `collectWriteProtectedSettings` and
`changedWriteProtectedSettingsPaths` in
`src/utils/settings-redaction.ts` list every write-protected value in a
settings document, by path, and report the ones that differ between two
documents (replaced, added or removed);
- the controller takes the protected values of the stored user settings
before applying the changes, applies them, and refuses the whole request
with `Path is write-protected` for each protected path that would differ
in the document it is about to save. It runs inside the write lock, next
to the existing merged validation, and before anything is saved, audited
or notified, so a refused request changes nothing;
- the checks on the request paths stay as they were; this one is on top,
so it covers a parent path, several changes in one request and any path
that ends up writing a protected value.
Still allowed: changing any other admin setting, and replacing the
`admin` object when the hash in it is the stored one. A client that
sends back the redacted settings it read (the API shows `passwordHash`
as `***`) is refused, which is right: it would have saved `***` as the
hash.
Not changed here: restoring a settings backup restores the hash that
backup holds, as a restore is meant to.
## Related Issue
Partly addresses #1022 (finding F-013). That issue groups nine findings,
so this PR does not close it. F-040 (the audit entry on an anonymous
logout) is next.
## Motivation and Context
A credential the API says it protects should be protected whatever path
the request names.
## How Has This Been Tested?
## Screenshots (if appropriate):
## Types of changes
- [ ] Non-functional change (docs, style, minor refactor)
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
## Checklist:
- [x] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [x] I have read the **CONTRIBUTING** document.
- [x] I have added tests to cover my code changes.
- [x] I added a changeset, or this is docs-only and I added an empty
changeset.
- [x] All new and existing tests passed.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->
## Summary by CodeRabbit
* **Bug Fixes**
* Admin settings updates can no longer change or remove the password
hash, including through direct edits, replacement or removal of the
containing settings object, redacted placeholders, or batch updates.
* Rejected updates leave the stored password hash unchanged and do not
save other changes included in the same batch.
* Other admin settings can still be updated when the existing password
hash is retained, including when replacing the containing settings
object.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
fix(admin): the settings API cannot change the admin password hash through a parent path
6
+
7
+
`PATCH /admin/settings` refused a change to `admin.passwordHash`, but it only looked at the path of the request. A request for the path `admin` with a new `admin` object, alone or inside a batch of changes, replaced the object and so wrote or removed `admin.passwordHash` without being refused. Anyone holding a valid admin session, or a copy of its token, could set a password hash they chose, or delete it, without knowing the current password, and the change outlived the session. The API now compares every write-protected value in the settings it is about to save with the stored ones and refuses the whole request when one differs (changed, added or removed), whichever path or batch caused it. Replacing the `admin` object with the same hash in it, and changing any other admin setting, still work.
0 commit comments