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(recordings): disallow labels with whitespace #867

Merged
merged 3 commits into from
Mar 18, 2022
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
12 changes: 12 additions & 0 deletions src/main/java/io/cryostat/recordings/RecordingMetadataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Future;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import io.cryostat.core.log.Logger;
import io.cryostat.core.sys.FileSystem;
Expand Down Expand Up @@ -159,6 +161,16 @@ public Map<String, String> parseRecordingLabels(String labels) throws IllegalArg
if (parsedLabels == null) {
throw new IllegalArgumentException(labels);
}
Pattern noWhitespace = Pattern.compile("^(\\S)+$");

for (var label : parsedLabels.entrySet()) {
Matcher keyMatcher = noWhitespace.matcher(label.getKey());
Matcher valueMatcher = noWhitespace.matcher(label.getValue());

if (!keyMatcher.matches() || !valueMatcher.matches()) {
throw new IllegalArgumentException("Labels must not contain whitespace");
}
}
return parsedLabels;
} catch (JsonSyntaxException e) {
throw new IllegalArgumentException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ void shouldParseAndStoreLabelsInRecordingLabelsMap() throws Exception {
strings = {
"12345",
"thisIsNotJson",
"{\"this label\":\"contains whitespace\"}",
"{\"thislabel\":\"contains\twhitespace\"}",
})
void shouldThrowOnInvalidLabels(String labels) throws Exception {
Class<? extends Exception> expected;
Expand Down
2 changes: 1 addition & 1 deletion web-client