Skip to content

Commit beea424

Browse files
committed
fix(appsec): replace String#split with char loop in MultipartContentDecoder
String#split is forbidden (uses regex internally). Replace with an explicit char scan to find the first ; , or space after charset=.
1 parent 6f0a3ec commit beea424

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

internal-api/src/main/java/datadog/trace/api/http/MultipartContentDecoder.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,16 @@ public static Charset extractCharset(String contentType) {
2828
if (contentType == null) return null;
2929
int idx = contentType.toLowerCase(Locale.ROOT).indexOf("charset=");
3030
if (idx < 0) return null;
31-
String name = contentType.substring(idx + 8).split("[;, ]")[0].trim();
31+
int nameStart = idx + 8;
32+
int end = contentType.length();
33+
for (int i = nameStart; i < contentType.length(); i++) {
34+
char c = contentType.charAt(i);
35+
if (c == ';' || c == ',' || c == ' ') {
36+
end = i;
37+
break;
38+
}
39+
}
40+
String name = contentType.substring(nameStart, end).trim();
3241
if (name.length() > 1 && name.charAt(0) == '"' && name.charAt(name.length() - 1) == '"') {
3342
name = name.substring(1, name.length() - 1);
3443
}

0 commit comments

Comments
 (0)