This is an automated email from the ASF dual-hosted git repository.
zihaoxiang pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
The following commit(s) were added to refs/heads/dev by this push:
new 4c264fd692 [Chore] Mask token in api log (#17656)
4c264fd692 is described below
commit 4c264fd6924598282521600267fb3505bf043372
Author: Wenjun Ruan <[email protected]>
AuthorDate: Thu Nov 13 10:36:23 2025 +0800
[Chore] Mask token in api log (#17656)
---
.../api/interceptor/RateLimitInterceptor.java | 13 +++----
.../dolphinscheduler/common/utils/MaskUtils.java | 41 ++++++++++++++++++++++
.../common/utils/MaskUtilsTest.java | 40 +++++++++++++++++++++
3 files changed, 88 insertions(+), 6 deletions(-)
diff --git
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/interceptor/RateLimitInterceptor.java
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/interceptor/RateLimitInterceptor.java
index 1f0ec80ac8..1484250115 100644
---
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/interceptor/RateLimitInterceptor.java
+++
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/interceptor/RateLimitInterceptor.java
@@ -18,6 +18,7 @@
package org.apache.dolphinscheduler.api.interceptor;
import org.apache.dolphinscheduler.api.configuration.ApiConfig;
+import org.apache.dolphinscheduler.common.utils.MaskUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
@@ -75,13 +76,13 @@ public class RateLimitInterceptor implements
HandlerInterceptor {
Object handler) throws ExecutionException {
// tenant-level rate limit
if (trafficConfiguration.isTenantSwitch()) {
- String token = request.getHeader("token");
- if (!StringUtils.isEmpty(token)) {
- RateLimiter tenantRateLimiter =
tenantRateLimiterCache.get(token);
+ final String token = request.getHeader("token");
+ if (StringUtils.isNotEmpty(token)) {
+ final RateLimiter tenantRateLimiter =
tenantRateLimiterCache.get(token);
if (!tenantRateLimiter.tryAcquire()) {
response.setStatus(HttpStatus.TOO_MANY_REQUESTS.value());
- log.warn("Too many request, reach tenant rate limit,
current tenant:{} qps is {}", token,
- tenantRateLimiter.getRate());
+ log.warn("Too many request, reach tenant token: {} rate
limit, current tenant qps is {}",
+ MaskUtils.maskString(token, 6),
tenantRateLimiter.getRate());
return false;
}
}
@@ -90,7 +91,7 @@ public class RateLimitInterceptor implements
HandlerInterceptor {
if (trafficConfiguration.isGlobalSwitch()) {
if (!globalRateLimiter.tryAcquire()) {
response.setStatus(HttpStatus.TOO_MANY_REQUESTS.value());
- log.warn("Too many request, reach global rate limit, current
qps is {}",
+ log.warn("Too many request, reach global rate limit, current
global qps is {}",
globalRateLimiter.getRate());
return false;
}
diff --git
a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/MaskUtils.java
b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/MaskUtils.java
new file mode 100644
index 0000000000..692422e058
--- /dev/null
+++
b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/MaskUtils.java
@@ -0,0 +1,41 @@
+/*
+ * 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.dolphinscheduler.common.utils;
+
+public class MaskUtils {
+
+ private static final String MASK_STRING = "****";
+
+ public static String maskString(String str) {
+ return maskString(str, 0);
+ }
+
+ public static String maskString(String str, int maskStartIndex) {
+ if (str == null) {
+ return null;
+ }
+ if (maskStartIndex == 0) {
+ return MASK_STRING;
+ }
+ if (maskStartIndex >= str.length()) {
+ return str;
+ }
+ return str.substring(0, maskStartIndex) + MASK_STRING;
+ }
+
+}
diff --git
a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/MaskUtilsTest.java
b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/MaskUtilsTest.java
new file mode 100644
index 0000000000..e590c478fe
--- /dev/null
+++
b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/MaskUtilsTest.java
@@ -0,0 +1,40 @@
+/*
+ * 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.dolphinscheduler.common.utils;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.Test;
+
+class MaskUtilsTest {
+
+ @Test
+ void testMaskString() {
+ assertEquals("****", MaskUtils.maskString("sensitiveData"));
+ assertEquals("****", MaskUtils.maskString(""));
+ assertEquals(null, MaskUtils.maskString(null));
+ }
+
+ @Test
+ void testMaskStringWithStartIndex() {
+ assertEquals("****", MaskUtils.maskString("sensitiveData", 0));
+ assertEquals("se****", MaskUtils.maskString("sensitiveData", 2));
+ assertEquals("****", MaskUtils.maskString("", 0));
+ assertEquals(null, MaskUtils.maskString(null, 1));
+ }
+}