Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid regex injection in filter parameters #491

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,37 @@ public FetchFilterPredicate(String name, FetchFilter filter, Function<String, F>
if (operator.equals("like")) {
// throws ClassCastException if this class is constructed with an incorrect operandParser (API bug)
String firstOperand = (String) firstOperand();
likePattern = Pattern.compile(firstOperand
.replace(".", "\\.")
.replace("*", ".*")
.replace("?", "."));
StringBuilder pattern = new StringBuilder();
StringBuilder quoted = new StringBuilder();
Runnable appendQuoted = () -> {
if (quoted.length() > 0) {
pattern.append(Pattern.quote(quoted.toString()));
quoted.setLength(0);
}
};

firstOperand.chars().forEach(c -> {
switch (c) {
case '.':
appendQuoted.run();
pattern.append("\\.");
break;
case '*':
appendQuoted.run();
pattern.append(".*");
break;
case '?':
appendQuoted.run();
pattern.append(".");
break;
default:
quoted.append((char) c);
break;
}
});

appendQuoted.run();
likePattern = Pattern.compile(pattern.toString());
} else {
likePattern = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void trustClusterCertificate(Map<String, Object> cfg) {
TrustManager[] trustAllCerts = {this};

try {
SSLContext sc = SSLContext.getInstance("TLS");
SSLContext sc = SSLContext.getInstance("TLSv1.2");
sc.init(null, trustAllCerts, new SecureRandom());
SSLSocketFactory factory = sc.getSocketFactory();
String bootstrap = (String) cfg.get(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG);
Expand Down