Skip to content

Commit

Permalink
[INLONG-8813][Manager] Replacing whitespace characters in MySQL JDBC …
Browse files Browse the repository at this point in the history
…URL (#8814)
  • Loading branch information
hnrainll committed Aug 30, 2023
1 parent 45b6e0d commit 49cbf96
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public class InlongConstants {

public static final String BLANK = " ";

public static final String EMPTY = "";

public static final String SLASH = "/";

public static final String COLON = ":";
Expand All @@ -64,8 +66,12 @@ public class InlongConstants {

public static final String QUESTION_MARK = "?";

public static final String AMPERSAND = "&";

public static final String NEW_LINE = "\n";

public static final String REGEX_WHITESPACE = "\\s";

public static final String ADMIN_USER = "admin";

public static final Integer AFFECTED_ONE_ROW = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public static String filterSensitive(String url) {
while (resultUrl.contains(InlongConstants.PERCENT)) {
resultUrl = URLDecoder.decode(resultUrl, "UTF-8");
}
resultUrl = resultUrl.replaceAll(InlongConstants.BLANK, "");
resultUrl = resultUrl.replaceAll(InlongConstants.REGEX_WHITESPACE, InlongConstants.EMPTY);

if (resultUrl.contains(InlongConstants.QUESTION_MARK)) {
StringBuilder builder = new StringBuilder();
Expand All @@ -241,19 +241,19 @@ public static String filterSensitive(String url) {

List<String> paramList = new ArrayList<>();
String queryString = StringUtils.substringAfter(resultUrl, InlongConstants.QUESTION_MARK);
for (String param : queryString.split("&")) {
String key = StringUtils.substringBefore(param, "=");
String value = StringUtils.substringAfter(param, "=");
for (String param : queryString.split(InlongConstants.AMPERSAND)) {
String key = StringUtils.substringBefore(param, InlongConstants.EQUAL);
String value = StringUtils.substringAfter(param, InlongConstants.EQUAL);

if (SENSITIVE_REMOVE_PARAM_MAP.contains(key) || SENSITIVE_REPLACE_PARAM_MAP.containsKey(key)) {
continue;
}

paramList.add(key + "=" + value);
paramList.add(key + InlongConstants.EQUAL + value);
}
SENSITIVE_REPLACE_PARAM_MAP.forEach((key, value) -> paramList.add(key + "=" + value));
SENSITIVE_REPLACE_PARAM_MAP.forEach((key, value) -> paramList.add(key + InlongConstants.EQUAL + value));

String params = StringUtils.join(paramList, "&");
String params = StringUtils.join(paramList, InlongConstants.AMPERSAND);
builder.append(params);
resultUrl = builder.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ public void testFilterSensitive() throws Exception {
Assertions.assertEquals(
"jdbc:mysql://127.0.0.1:3306?autoDeserialize=false&allowUrlInLocalInfile=false&allowLoadLocalInfile=false",
originUrl);

originUrl = MySQLSinkDTO.filterSensitive(
"jdbc:mysql://127.0.0.1:3306?autoDeserialize\t\t=%59%65%73&allowLoa\r\rdLocalInfile = yes&allowUrlInLocalInfil%65+\t=%74%72%75%45&allowLoadLocalInfileInPath\n=%2F");
Assertions.assertEquals(
"jdbc:mysql://127.0.0.1:3306?autoDeserialize=false&allowUrlInLocalInfile=false&allowLoadLocalInfile=false",
originUrl);
}

@Test
Expand Down

0 comments on commit 49cbf96

Please sign in to comment.