DoDiODev opened a new issue, #9417:
URL: https://github.com/apache/devlake/issues/9417
### Search before asking
- [x] I had searched in the issues and found no similar issues.
### What happened
`PATCH
/plugins/{plugin}/connections/{connectionId}/scope-configs/{scopeConfigId}`
does not check that the scope config belongs to `{connectionId}`. Instead,
`DsScopeConfigApiHelper.Patch` copies the `connectionId` from the URL into
the
request body before saving:
https://github.com/apache/devlake/blob/652d7da93/backend/helpers/pluginhelper/api/ds_scope_config_api_helper.go#L82-L90
```go
func (connApi *DsScopeConfigApiHelper[C, S, SC]) Patch(input
*plugin.ApiResourceInput) (out *plugin.ApiResourceOutput, err errors.Error) {
// fix connectionId
connectionId, err := extractConnectionId(input)
...
input.Body["connectionId"] = connectionId
return connApi.ModelApiHelper.Patch(input)
}
```
So a PATCH with a mismatching connection ID returns `200` and silently
reassigns the scope config to the other connection. Afterwards:
- the scope config no longer shows up under its own connection in Config UI
(`GET .../connections/{own}/scope-configs` no longer lists it),
- it shows up under the foreign connection instead,
- scopes of the original connection still reference it via `scope_config_id`,
so data collection keeps working and the problem goes unnoticed.
We hit this with the Jira plugin while updating several scope configs via
the API with a copy-pasted URL: all of them ended up under one connection.
### What do you expect to happen
PATCH should not change the owning connection. If the scope config does not
belong to the connection in the URL, the API should respond with `404`
(or `400`). Alternatively, `connectionId` should be ignored on PATCH.
### How to reproduce
1. Create two connections of the same plugin, e.g. Jira connection `1` and
`2`.
2. Create a scope config under connection `1` (say id `5`).
3. Run
```bash
curl -X PATCH
http://localhost:8080/plugins/jira/connections/2/scope-configs/5 \
-H 'Content-Type: application/json' -d '{}'
```
4. Response is `200` and contains `"connectionId": 2`.
5. `GET /plugins/jira/connections/1/scope-configs` no longer lists id `5`;
`GET /plugins/jira/connections/2/scope-configs` does.
### Anything else
Happens every time. It affects every plugin that uses
`DsScopeConfigApiHelper`,
not only Jira. Found on PostgreSQL, but the behaviour is database
independent.
### Version
`main` @ `652d7da93`
### Are you willing to submit PR?
- [ ] Yes I am willing to submit a PR!
### Code of Conduct
- [x] I agree to follow this project's Code of Conduct
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]