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 591383179 fix(model): keep the data source and ACL 2.0 credentials out 
of toString (#6123)
591383179 is described below

commit 5913831796f83620a2512f2fd0643bd50fcba66d
Author: Apulupie <[email protected]>
AuthorDate: Fri Nov 27 12:52:09 2026 +0800

    fix(model): keep the data source and ACL 2.0 credentials out of toString 
(#6123)
---
 .../rocketmq/studio/model/Acl2PolicyContext.java   |  3 ++
 .../studio/model/MetricsDataSourceConfig.java      |  3 ++
 .../CredentialModelToStringRedactionTest.java      | 59 ++++++++++++++++++++++
 3 files changed, 65 insertions(+)

diff --git 
a/server/src/main/java/org/apache/rocketmq/studio/model/Acl2PolicyContext.java 
b/server/src/main/java/org/apache/rocketmq/studio/model/Acl2PolicyContext.java
index 1e0dcbb4c..b4510e512 100644
--- 
a/server/src/main/java/org/apache/rocketmq/studio/model/Acl2PolicyContext.java
+++ 
b/server/src/main/java/org/apache/rocketmq/studio/model/Acl2PolicyContext.java
@@ -20,6 +20,7 @@ import lombok.AccessLevel;
 import lombok.Data;
 import lombok.Getter;
 import lombok.Setter;
+import lombok.ToString;
 import java.util.Date;
 import java.util.List;
 
@@ -39,9 +40,11 @@ public class Acl2PolicyContext {
     // ========== Base Fields (Compatible with ACL 1.0) ==========
 
     /** Access key (user identifier) */
+    @ToString.Exclude
     private String accessKey;
 
     /** Secret key for authentication */
+    @ToString.Exclude
     private String secretKey;
 
     /** Whether this is an admin user */
diff --git 
a/server/src/main/java/org/apache/rocketmq/studio/model/MetricsDataSourceConfig.java
 
b/server/src/main/java/org/apache/rocketmq/studio/model/MetricsDataSourceConfig.java
index da45e74ee..ef1c3ec50 100644
--- 
a/server/src/main/java/org/apache/rocketmq/studio/model/MetricsDataSourceConfig.java
+++ 
b/server/src/main/java/org/apache/rocketmq/studio/model/MetricsDataSourceConfig.java
@@ -17,6 +17,7 @@
 package org.apache.rocketmq.studio.model;
 
 import lombok.Data;
+import lombok.ToString;
 import java.io.Serializable;
 import java.util.Map;
 
@@ -58,11 +59,13 @@ public class MetricsDataSourceConfig implements 
Serializable {
     /**
      * Password for basic authentication (encrypted in storage).
      */
+    @ToString.Exclude
     private String password;
 
     /**
      * Bearer token for bearer authentication.
      */
+    @ToString.Exclude
     private String bearerToken;
 
     /**
diff --git 
a/server/src/test/java/org/apache/rocketmq/studio/model/CredentialModelToStringRedactionTest.java
 
b/server/src/test/java/org/apache/rocketmq/studio/model/CredentialModelToStringRedactionTest.java
new file mode 100644
index 000000000..698403504
--- /dev/null
+++ 
b/server/src/test/java/org/apache/rocketmq/studio/model/CredentialModelToStringRedactionTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.rocketmq.studio.model;
+
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * The credential-bearing models of this package. A Lombok {@code @Data} class 
prints every field in
+ * its generated {@code toString()}, so any log line, exception message or 
diagnostic dump that
+ * renders one of them writes the credential to disk. {@code 
MetricsDataSourceQueryRequest} already
+ * excludes its password and bearer token, and the certificate redaction fix 
(#4555) named these two
+ * classes as the remaining follow-up.
+ */
+class CredentialModelToStringRedactionTest {
+
+    private static final String SECRET = "sensitive-secret-material";
+
+    @Test
+    void dataSourceConfigToStringShouldExcludeTheCredentialsTest() {
+        MetricsDataSourceConfig config = new MetricsDataSourceConfig();
+        config.setName("prometheus-prod");
+        config.setUrl("http://prometheus:9090";);
+        config.setPassword(SECRET);
+        config.setBearerToken(SECRET);
+
+        assertThat(config.toString())
+                .contains("prometheus-prod")
+                .contains("http://prometheus:9090";)
+                .doesNotContain(SECRET);
+    }
+
+    @Test
+    void acl2PolicyContextToStringShouldExcludeTheCredentialsTest() {
+        Acl2PolicyContext context = new Acl2PolicyContext();
+        context.setAccessKey(SECRET);
+        context.setSecretKey(SECRET);
+        context.setPolicyName("order-service-policy");
+
+        assertThat(context.toString())
+                .contains("order-service-policy")
+                .doesNotContain(SECRET);
+    }
+}

Reply via email to