[BUG] Discovery upstream writes can mismatch handler and namespace ownership
Current behavior
DiscoveryUpstreamDTO validates that namespaceId and discoveryHandlerId each exist, but does not validate that they belong together. The write paths preserve this mismatch:
DiscoveryUpstreamServiceImpl.create()inserts the DTO-derived row and callsfetchAll(discoveryHandlerId).createOrUpdateBatch()inserts/updates DTO-derived rows and refreshes each supplied handler.updateBatch(handlerId, ...)deletes the current rows for that handler, then overwrites each DTO's handler ID with the path ID while retaining the submittednamespaceId.
fetchAll() loads upstream rows by handler ID and publishes them through the selector/proxy-selector associated with that handler. In contrast, listAllDataByNamespaceId() filters rows using the stored upstream namespace_id. A mismatched row can therefore be shown under namespace B while being synchronized as part of namespace A's handler. The batch replacement path can also remove the handler's existing rows before persisting rows tagged with the wrong namespace.
Reproduction
- Create namespaces A and B, and a discovery handler bound to a selector in A.
- Call
PUT /discovery-upstream/{handlerA}with a valid upstream DTO whosenamespaceIdis B (all required fields and IDs are valid). - Observe that the row is stored with
discovery_handler_id=handlerAandnamespace_id=B; the service then callsfetchAll(handlerA)and sends the handler's upstream snapshot to A's selector. - Querying upstreams by namespace B also returns that row.
The same inconsistent association can be created through POST /discovery-upstream and POST /discovery-upstream/batch.
Expected behavior
The namespace must be derived from or checked against the namespace that owns the discovery handler's selector/proxy selector. Reject a mismatched write before deleting or inserting any upstream rows, and keep the persisted namespace consistent with the handler used for synchronization.
Source references
shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/DiscoveryUpstreamDTO.java: independent existence checks fornamespaceIdanddiscoveryHandlerId.shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryUpstreamServiceImpl.java:create,createOrUpdateBatch,updateBatch, andfetchAll.shenyu-admin/src/main/resources/mappers/discovery-upstream-sqlmap.xml: inserts persistnamespace_id; upstream lookup for synchronization is bydiscovery_handler_id.
This is a source-confirmed issue; I did not modify a live database or run an HTTP deployment. DiscoveryUpstreamServiceTest passes 49 tests but currently has no mismatched handler/namespace case.