Fix REST endpoint /set allowing clients to set serverOnlyFields#402
Merged
Fix REST endpoint /set allowing clients to set serverOnlyFields#402
Conversation
The REST /set handler stripped server-only field values from client input only on UPDATES. When inserting a new document, the client doc was passed straight to RxCollection.insert(), letting clients persist arbitrary values into fields documented as server-only. Add stripServerOnlyFieldsMonad and use it in the insert branch of /set so the server-only contract holds for both inserts and updates.
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.
This PR contains:
Describe the problem you have without this PR
The REST endpoint
/setoperation was allowing clients to populateserverOnlyFieldswhen inserting NEW documents. While updates to existing documents already stripped client-supplied values for these fields, the insert path passed the client document directly toRxCollection.insert()without filtering. This allowed clients to persist arbitrary values into fields documented as server-only, violating the security contract.Changes Made
New helper function (
stripServerOnlyFieldsMonadinsrc/plugins/server/helper.ts):removeServerOnlyFieldsMonad, it doesn't assign undefined to RxDB internal meta fields, making it safe forRxCollection.insert()Updated REST endpoint handler (
src/plugins/server/endpoint-rest.ts):stripServerOnlyFieldsMonadfunction/setAdded test coverage (
test/unit/endpoint-rest.test.ts):serverOnlyFieldswhen creating new documents via/sethumanDefaultschema wherelastNameis optional to validate the security fixUpdated CHANGELOG.md with bug fix description
Test Plan
The added unit test
'should not allow clients to set serverOnlyFields when inserting NEW documents via /set'covers this fix by:https://claude.ai/code/session_017a16qgJ3hi4Zap9dJF46nx