Skip to content

[Bug][Framework] PATCH scope-configs silently moves a scope config to the connection in the URL #9417

Open

Description

@DoDiODev

Search before asking

  • 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

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
    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

  • I agree to follow this project's Code of Conduct

Activity

  1. RyoKusnadi commented on Nov 20, 2026

    @RyoKusnadi
    Contributor

    Hi @DoDiODev @klesh, can I do it?

    How I plan to do it:

    1. In backend/helpers/pluginhelper/api/ds_scope_config_api_helper.go, DsScopeConfigApiHelper.Patch writes the URL's connectionId into the body before patching, so the row moves to that connection. I'd load the scope config first and compare its ScopeConfigConnectionId() with the URL's connection id.
    2. On a mismatch, return a not-found error and leave the row alone. Drop the input.Body["connectionId"] = connectionId line so a PATCH can't change the owner.
    3. GetDetail, Delete and GetProjectsByScopeConfig in the same helper also look up by scope config id only, so I'd add the same check there to keep them consistent.
    4. Post stays as it is (it sets the connection id on a new row).
    5. Tests in the same package with mockdal: PATCH with the wrong connection gets 404 and nothing is written, PATCH with the right connection still updates (must not change), GET and DELETE with the wrong connection get 404.

    404 vs 400 for the mismatch is up to you, I'd go with 404.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ Proxy