shenyu icon indicating copy to clipboard operation
shenyu copied to clipboard

[BUG] Discovery upstream batch deletion is not scoped to a namespace

Open sunnysabor opened this issue 3 weeks ago • 0 comments

Current behavior

The Admin endpoint DELETE /discovery-upstream/batch accepts only a list of upstream IDs. DiscoveryUpstreamServiceImpl.delete(ids) resolves rows with selectByIds(ids) and removes them with deleteByIds(ids); neither query includes namespace_id or checks the namespace of the owning discovery handler. The service then refreshes the affected handlers, so the deletion immediately changes their published upstream snapshots.

Unlike the delete API, the model and listing path are namespace-aware: upstream rows store namespace_id, and listAllDataByNamespaceId(namespaceId) filters on it. The batch-delete API therefore cannot enforce the namespace boundary represented by those rows. A caller operating in one namespace who submits an upstream ID from another namespace can delete that other namespace's endpoint entry.

Reproduction

  1. Create upstream rows in namespaces A and B, each associated with its own discovery handler.
  2. In a request made while working in namespace A, call DELETE /discovery-upstream/batch with the ID of the row from B.
  3. The service selects and deletes the B row by ID, then calls fetchAll for B's handler; B's published upstream list changes.

The endpoint currently has no namespace parameter with which to scope the request.

Expected behavior

Scope batch deletion to the active/request namespace and verify that each ID belongs to both that namespace and its owning handler before deletion. IDs outside the namespace should be rejected or ignored without changing another namespace's upstream snapshot. Preserve the existing post-delete synchronization for rows that are validly deleted.

Source references

  • shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/DiscoveryUpstreamController.java: deleteDiscoveryUpstream accepts only List<String> ids.
  • shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryUpstreamServiceImpl.java: delete calls selectByIds and deleteByIds, then refreshes each affected handler.
  • shenyu-admin/src/main/resources/mappers/discovery-upstream-sqlmap.xml: both mapper statements filter by ID only; selectByNamespaceId exists separately.

This is a source-confirmed issue; I did not modify a live database or run an HTTP deployment. It affects a different resource and endpoint than selector deletion in #6826.

sunnysabor avatar Nov 08 '26 09:11 sunnysabor