Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix potential data inconsistency issue #3341

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ public ItemDTO update(@PathVariable("appId") String appId,
throw new NotFoundException("item not found for itemId " + itemId);
}

Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName);
// In case someone constructs an attack scenario
if (namespace == null || namespace.getId() != managedEntity.getNamespaceId()) {
throw new BadRequestException("Invalid request, item and namespace do not match!");
}

Item entity = BeanUtils.transform(Item.class, itemDTO);

ConfigChangeContentBuilder builder = new ConfigChangeContentBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void deleteItem(@PathVariable String appId, @PathVariable String env,
NamespaceDTO namespace = namespaceService.loadNamespaceBaseInfo(appId, Env.valueOf(env), clusterName, namespaceName);

// In case someone constructs an attack scenario
if (item.getNamespaceId() != namespace.getId()) {
if (namespace == null || item.getNamespaceId() != namespace.getId()) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

此处的namespace为空的判断是非必要的,因为在113行的loadNamespaceBaseInfo中的逻辑里已经对null做出了抛异常的处理。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right, but I assume it has no harm so we could leave it as is.

throw new BadRequestException("Invalid request, item and namespace do not match!");
}

Expand Down