This is an automated email from the ASF dual-hosted git repository.
lizhimins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git
The following commit(s) were added to refs/heads/master by this push:
new 949283c1a fix(acl): bound the username and rule principal to their
columns (#6809)
949283c1a is described below
commit 949283c1a558dc3abaeabf48c03305f1320b1d90
Author: Apulupie <[email protected]>
AuthorDate: Fri Nov 27 12:45:02 2026 +0800
fix(acl): bound the username and rule principal to their columns (#6809)
---
.../rocketmq/studio/instance/acl/AclService.java | 25 ++++++++
.../studio/instance/acl/AclServiceTest.java | 68 ++++++++++++++++++++++
2 files changed, 93 insertions(+)
diff --git
a/server/src/main/java/org/apache/rocketmq/studio/instance/acl/AclService.java
b/server/src/main/java/org/apache/rocketmq/studio/instance/acl/AclService.java
index 93241438f..4dcef3fdb 100644
---
a/server/src/main/java/org/apache/rocketmq/studio/instance/acl/AclService.java
+++
b/server/src/main/java/org/apache/rocketmq/studio/instance/acl/AclService.java
@@ -25,6 +25,7 @@ import org.apache.rocketmq.remoting.protocol.body.UserInfo;
import org.apache.rocketmq.tools.admin.DefaultMQAdminExt;
import org.apache.rocketmq.studio.common.domain.PageResult;
import org.apache.rocketmq.studio.common.exception.BusinessException;
+import org.apache.rocketmq.studio.common.util.TextBounds;
import org.apache.rocketmq.studio.common.util.Pagination;
import org.apache.rocketmq.studio.common.domain.enums.InstanceVendor;
import org.apache.rocketmq.studio.common.util.CredentialUtils;
@@ -59,6 +60,11 @@ import java.util.Properties;
public class AclService {
private static final SecureRandom CREDENTIAL_RANDOM = new SecureRandom();
+ /**
+ * Width of the ACL identity columns the write paths store their text in:
{@code
+ * rmq_acl_user.username} and {@code rmq_acl_rule.principal} are both
{@code VARCHAR(128)}.
+ */
+ static final int MAX_ACL_IDENTITY_CODE_POINTS = 128;
private static final int DEFAULT_RULE_PAGE_SIZE = 20;
private static final int MAX_PAGE_SIZE = 100;
/** Broker ACL 2.0 subjects are prefixed with {@code User:}; the store
uses {@code user:}. */
@@ -140,6 +146,7 @@ public class AclService {
if (!StringUtils.hasText(rule.getPrincipal())) {
throw new BusinessException(400, "ACL principal is required");
}
+ requireIdentityWithinColumn(rule.getPrincipal(), "principal");
if (!StringUtils.hasText(rule.getResource())) {
throw new BusinessException(400, "ACL resource is required");
}
@@ -182,6 +189,7 @@ public class AclService {
if (isTencentInstance(instanceId)) {
return tencentAclService.updateRule(instanceId, rule);
}
+ requireIdentityWithinColumn(rule.getPrincipal(), "principal");
if (rule.getId() == null) {
throw new BusinessException(400, "ACL rule id is required");
}
@@ -264,6 +272,7 @@ public class AclService {
if (!StringUtils.hasText(user.getUsername())) {
throw new BusinessException(400, "ACL username is required");
}
+ requireIdentityWithinColumn(user.getUsername(), "username");
user.setAccessKey(randomCredentialToken());
user.setSecretKey(randomCredentialToken());
user.setGmtCreate(LocalDateTime.now());
@@ -279,6 +288,7 @@ public class AclService {
if (isTencentInstance(instanceId)) {
return tencentAclService.updateUser(instanceId,
user.toAclUserVO());
}
+ requireIdentityWithinColumn(user.getUsername(), "username");
if (!StringUtils.hasText(user.getId())) {
throw new BusinessException(400, "ACL user id is required");
}
@@ -682,6 +692,21 @@ public class AclService {
* ACL rather than the Apache broker auth module). When the broker version
cannot be resolved
* the guard is permissive and lets the operation through to avoid false
positives.
*/
+ /**
+ * Bounds an ACL identity to the width of the column that stores it.
Letting a longer value
+ * through does not store it: MySQL rejects the write, so the caller would
receive a 500 from
+ * the persistence layer instead of the validation error the surrounding
paths already return.
+ * Counted in code points, the unit MySQL counts a {@code varchar} in, and
applied here rather
+ * than only on the request DTOs because the tool handlers build these
values in code and never
+ * pass through bean validation.
+ */
+ private static void requireIdentityWithinColumn(String value, String
fieldName) {
+ if (TextBounds.codePointCount(value) > MAX_ACL_IDENTITY_CODE_POINTS) {
+ throw new BusinessException(400,
+ fieldName + " must not exceed " +
MAX_ACL_IDENTITY_CODE_POINTS + " characters");
+ }
+ }
+
private void requireAcl2Supported(String instanceId) {
if (isTencentInstance(instanceId)) {
return;
diff --git
a/server/src/test/java/org/apache/rocketmq/studio/instance/acl/AclServiceTest.java
b/server/src/test/java/org/apache/rocketmq/studio/instance/acl/AclServiceTest.java
index dd5287d60..da12f1d5f 100644
---
a/server/src/test/java/org/apache/rocketmq/studio/instance/acl/AclServiceTest.java
+++
b/server/src/test/java/org/apache/rocketmq/studio/instance/acl/AclServiceTest.java
@@ -1644,4 +1644,72 @@ class AclServiceTest {
verify(admin, never()).createUser(any(), any());
verify(admin, never()).updateAcl(any(), any(AclInfo.class));
}
+
+ @Test
+ void createUserShouldRejectAUsernameThatCannotFitItsColumnTest() {
+ String tooLong = "u".repeat(129);
+
+ assertThatThrownBy(() -> aclService.createUser(
+ AclUserVO.builder().username(tooLong).build(), null))
+ .isInstanceOfSatisfying(BusinessException.class, exception -> {
+ assertThat(exception.getCode()).isEqualTo(400);
+ assertThat(exception.getMessage())
+ .isEqualTo("username must not exceed 128
characters");
+ });
+
+ // The column counts characters, not UTF-16 units, so 128 code points
still fit even when
+ // they are surrogate pairs; the guard is counted in code points for
that reason.
+ String astral = "\uD83D\uDE00".repeat(128);
+ when(aclRepository.saveUser(any(AclUserVO.class)))
+ .thenAnswer(invocation -> invocation.getArgument(0));
+
assertThat(aclService.createUser(AclUserVO.builder().username(astral).build(),
null)
+ .getUsername()).isEqualTo(astral);
+ }
+
+ @Test
+ void updateUserShouldRejectAUsernameThatCannotFitItsColumnTest() {
+ UpdateAclUserDTO request = new UpdateAclUserDTO();
+ request.setId("1");
+ request.setUsername("u".repeat(129));
+
+ assertThatThrownBy(() -> aclService.updateUser(request, null))
+ .isInstanceOfSatisfying(BusinessException.class, exception -> {
+ assertThat(exception.getCode()).isEqualTo(400);
+ assertThat(exception.getMessage())
+ .isEqualTo("username must not exceed 128
characters");
+ });
+ verify(aclRepository, never()).replaceUser(any(AclUserVO.class));
+ }
+
+ @Test
+ void createRuleShouldRejectAPrincipalThatCannotFitItsColumnTest() {
+ AclRuleVO input = AclRuleVO.builder()
+ .principal("p".repeat(129))
+ .resource("topic-1")
+ .build();
+
+ assertThatThrownBy(() -> aclService.createRule(input, null))
+ .isInstanceOfSatisfying(BusinessException.class, exception -> {
+ assertThat(exception.getCode()).isEqualTo(400);
+ assertThat(exception.getMessage())
+ .isEqualTo("principal must not exceed 128
characters");
+ });
+ }
+
+ @Test
+ void updateRuleShouldRejectAPrincipalThatCannotFitItsColumnTest() {
+ AclRuleVO input = AclRuleVO.builder()
+ .id(1L)
+ .principal("p".repeat(129))
+ .resource("topic-1")
+ .build();
+
+ assertThatThrownBy(() -> aclService.updateRule(input, null))
+ .isInstanceOfSatisfying(BusinessException.class, exception -> {
+ assertThat(exception.getCode()).isEqualTo(400);
+ assertThat(exception.getMessage())
+ .isEqualTo("principal must not exceed 128
characters");
+ });
+ verifyNoInteractions(aclRepository);
+ }
}