-
Notifications
You must be signed in to change notification settings - Fork 194
Description
Because of the nature of patch (a list of operations to be applied), you need to validate that these operations are valid and you don't receive an unwanted operation.
For example suppose you are implementing a change password. This change password requires two things, the new password, the old password and the answer to a personal question. So json patch could be something like:
[
{ "op": "test", "path": "/password", "value": "myencryptedpassword" },
{ "op": "test", "path": "/answer", "value": "myanswer" }
{ "op": "replace", "path": "/password", "value": "newpassword" }
]
But of course nobody can avoid that someone send this:
[
{ "op": "replace", "path": "/username", "value": "hahaIhavechangedyourname" }
{ "op": "test", "path": "/password", "value": "myencryptedpassword" },
{ "op": "test", "path": "/answer", "value": "myanswer" }
{ "op": "replace", "path": "/password", "value": "newpassword" }
]
To avoid this a new method could me implemented called for example validate which can receive a "functional interface" to be implemented which have a method called validate
with a parameter which is a list of operations to be done (list of { "op": "replace", "path": "/username", "value": "hahaIhavechangedyourname" }
). In this way before applying the changes, the developer may be free to call validate
or not. What I mean is that validate method could be executed automatically or not. Also we can overload JsonPatch.fromJson
method setting the "functional interface" so then automatically validate method will be called automatically before executing apply.
I think it has a lot of sense allowing this kind of operations in sake of security.
WDYT?