I'm using a pretty vanilla spring-boot-starter-data-rest
setup and enabled the PATCH
method. All is working, but I have a security concern and wonder what's the recommended way of mitigating it.
The problem is that PATCH
path
s allow reachable entities to be updated from a different endpoint. So, suppose I have a comments
endpoint and an article
endpoint. Each comment has a to-one association with its article. A user that has permission to edit a comment could then do something like this:
PATCH http://some.domain.foo/api/comments/1234
Content-Type: application/json-patch+json
[
{ "op": "replace", "path": "/article/title", "value": "foobar2" }
]
and thereby change the title of the article !!
Clearly this ain't good.
In this case, for other parts of the API the association to the "article" needs to be traversable. But it must be read-only.
So... how do I accomplish this in Spring?
Intercept the request? Implement a handler method? Write my own Controller from scratch ?
Thanks!