SbloodyS commented on code in PR #18397:
URL:
https://github.com/apache/dolphinscheduler/pull/18397#discussion_r3569672355
##########
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/log/SensitiveDataConverter.java:
##########
@@ -37,6 +37,18 @@ public class SensitiveDataConverter extends MessageConverter
{
private static Pattern multilinePattern;
private static final Set<String> maskPatterns = new HashSet<>();
+ private static final String KNOWN_SENSITIVE_CONFIGURATION_KEY_REGEX =
+
"(?:password|access[._-]?key(?:[._-]?(?:id|secret))?|secret[._-]?access[._-]?key|secret[._-]?key)";
+
+ private static final Pattern QUOTED_SENSITIVE_CONFIGURATION_PATTERN =
Pattern.compile(
Review Comment:
`.*?` does not distinguish an escaped quote from the actual string
terminator.
eg, given valid JSON:
```
{"password":"abc\"VISIBLE_SUFFIX","bucket":"ds"}
```
result output:
```
{"password":"******\"VISIBLE_SUFFIX","bucket":"ds"}
```
##########
dolphinscheduler-task-plugin/dolphinscheduler-task-dinky/src/test/java/org/apache/dolphinscheduler/plugin/task/dinky/DinkyLogSanitizerTest.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * 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.plugin.task.dinky;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
+import org.apache.dolphinscheduler.plugin.task.api.model.Property;
+
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.jupiter.api.Test;
+
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+
+class DinkyLogSanitizerTest {
+
+ @Test
+ void testSummarizeVariablesDoesNotExposeValues() {
+ Map<String, String> variables = new HashMap<>();
+ variables.put("accessKeyId", "AKIA_TEST");
+ variables.put("accessKeySecret", "SECRET_TEST");
+ variables.put("businessDate", "2026-07-06");
+
+ String summary = DinkyLogSanitizer.summarizeVariables(variables);
+
+ assertTrue(summary.contains("size=3"));
+ assertTrue(summary.contains("accessKeyId"));
+ assertTrue(summary.contains("accessKeySecret"));
+ assertTrue(summary.contains("businessDate"));
+ assertFalse(summary.contains("AKIA_TEST"));
+ assertFalse(summary.contains("SECRET_TEST"));
+ assertFalse(summary.contains("2026-07-06"));
+ }
+
+ @Test
+ void testSummarizeParametersDoesNotExposeLocalParamValues() {
+ DinkyParameters parameters = new DinkyParameters();
+ parameters.setAddress("http://dinky:8888");
+ parameters.setTaskId("1001");
+ parameters.setOnline(true);
+ parameters.setLocalParams(Arrays.asList(
+ new Property("accessKeyId", null, null, "AKIA_TEST"),
+ new Property("businessDate", null, null, "2026-07-06")));
+
+ String summary = DinkyLogSanitizer.summarizeParameters(parameters);
+
+ assertTrue(summary.contains("address=http://dinky:8888"));
+ assertTrue(summary.contains("taskId=1001"));
+ assertTrue(summary.contains("online=true"));
+ assertTrue(summary.contains("localParamKeys=[accessKeyId,
businessDate]"));
+ assertFalse(summary.contains("AKIA_TEST"));
+ assertFalse(summary.contains("2026-07-06"));
+ }
+
+ @Test
+ void testSanitizeMessageMasksSensitiveValues() {
+ String message =
"{\"accessKeyId\":\"AKIA_TEST\",\"accessKeySecret\":\"SECRET_TEST\"}";
+
+ String sanitized = DinkyLogSanitizer.sanitizeMessage(message);
+
+ assertTrue(sanitized.contains("accessKeyId"));
+ assertTrue(sanitized.contains("accessKeySecret"));
+ assertFalse(sanitized.contains("AKIA_TEST"));
+ assertFalse(sanitized.contains("SECRET_TEST"));
+ }
+
+ @Test
+ void testSanitizeMessageMasksSensitiveValuesInJsonNodeMessage() {
+ String message =
"{\"accessKeyId\":\"AKIA_TEST\",\"accessKeySecret\":\"SECRET_TEST\"}";
+
+ String sanitized =
DinkyLogSanitizer.sanitizeMessage(JsonNodeFactory.instance.textNode(message));
+
+ assertTrue(sanitized.contains("accessKeyId"));
+ assertTrue(sanitized.contains("accessKeySecret"));
+ assertFalse(sanitized.contains("AKIA_TEST"));
+ assertFalse(sanitized.contains("SECRET_TEST"));
+ }
+
+ @Test
+ void testParseMalformedResponseReturnsNullWithoutExposingRawResponse()
throws Exception {
Review Comment:
This only asserts that the return value is null; it does not capture or
inspect any log event. The test would also pass with the old implementation
even if the raw response were written through the exception log.
##########
dolphinscheduler-task-plugin/dolphinscheduler-task-dinky/src/main/java/org/apache/dolphinscheduler/plugin/task/dinky/DinkyTask.java:
##########
@@ -404,7 +402,8 @@ private JsonNode parse(String res) {
try {
result = mapper.readTree(res);
} catch (JsonProcessingException e) {
- log.error("dinky task submit failed with error", e);
+ log.error("dinky task response parse failed, responseLength: {},
errorType: {}",
Review Comment:
The parse error should fail explicitly.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]