Skip to content

fix(plugins): reject a scope config PATCH that targets a foreign connection - #9445

Open
Goldloli wants to merge 1 commit into
apache:mainfrom
Goldloli:fix-scope-config-patch-ownership
Open

Goldloli wants to merge 1 commit into
apache:mainfrom
Goldloli:fix-scope-config-patch-ownership

Conversation

@Goldloli

Copy link
Copy Markdown
Contributor

Summary

DsScopeConfigApiHelper.Patch copied the connectionId from the URL into the request body and then saved the scope config. The scope config itself is looked up by its own primary key only, so a PATCH sent through another connection's URL returned 200 and silently reassigned the scope config to that connection.

This PR verifies the ownership before writing anything and returns 404 when the scope config belongs to a different connection, which matches what the issue asks for. The request body is still forced to the URL's connectionId, so a PATCH cannot change the owning connection.

Does this close any open issues?

Closes #9417

Screenshots

No UI change.

Other Information

Change — backend/helpers/pluginhelper/api/ds_scope_config_api_helper.go

// before: the body was forced to the URL connection and saved
input.Body["connectionId"] = connectionId
return connApi.ModelApiHelper.Patch(input)

// after: verify ownership first
scopeConfig, err = connApi.FindByPk(input)
if (*scopeConfig).ScopeConfigConnectionId() != connectionId {
    return nil, errors.NotFound.New(...)
}
input.Body["connectionId"] = connectionId
return connApi.ModelApiHelper.Patch(input)

The check is generic, so it covers every plugin that routes PATCH .../connections/:connectionId/scope-configs/:scopeConfigId through DsScopeConfigApiHelper.

Tests — new backend/helpers/pluginhelper/api/ds_scope_config_api_helper_test.go

  • TestPatchScopeConfigRejectsForeignConnection: a scope config owned by connection 1, PATCHed through connection 2, now fails with NotFound; the stored record keeps its connection and name and no Update reaches the database.
  • TestPatchScopeConfigAcceptsOwningConnection: the same PATCH through the owning connection still updates the record.

Verification

$ go test ./helpers/pluginhelper/api/ -count=1
ok  	github.com/apache/devlake/helpers/pluginhelper/api	3.920s

$ go vet ./helpers/pluginhelper/api/
(no output)

$ golangci-lint run ./helpers/pluginhelper/api/
0 issues

Re-running the two new tests against the pre-fix Patch makes TestPatchScopeConfigRejectsForeignConnection fail as expected (err is nil and the record is written), so the test does exercise the reported behaviour. go test ./helpers/... additionally fails in helpers/e2ehelper, which panics in NewDataFlowTester before any of this code runs; it needs a MySQL instance and fails the same way on a clean checkout of main.

I did not add an e2e case: the existing TestUpdateScopeConfig in backend/test/e2e/remote/python_plugin_test.go always PATCHes through the owning connection, so its expectations are unchanged.

…ection

Patch copied the connectionId from the URL into the request body and saved it,
so PATCHing a scope config through another connection's URL returned 200 and
silently moved the scope config to that connection. Verify the ownership first
and return 404 when the scope config belongs to a different connection.

Signed-off-by: Goldloli <39011904+Goldloli@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant

⌂ Proxy