Skip to content

Commit afdd000

Browse files
authored
Validate SLM policy ids strictly (#45998)
This uses strict validation for SLM policy ids, similar to what we use for index names. Resolves #45997
1 parent 947fccb commit afdd000

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/slm/SnapshotLifecyclePolicy.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,9 @@ public ActionRequestValidationException validate() {
128128
ActionRequestValidationException err = new ActionRequestValidationException();
129129

130130
// ID validation
131-
if (id.contains(",")) {
132-
err.addValidationError("invalid policy id [" + id + "]: must not contain ','");
133-
}
134-
if (id.contains(" ")) {
135-
err.addValidationError("invalid policy id [" + id + "]: must not contain spaces");
131+
if (Strings.validFileName(id) == false) {
132+
err.addValidationError("invalid policy id [" + id + "]: must not contain the following characters " +
133+
Strings.INVALID_FILENAME_CHARS);
136134
}
137135
if (id.charAt(0) == '_') {
138136
err.addValidationError("invalid policy id [" + id + "]: must not start with '_'");

x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SnapshotLifecyclePolicyTests.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ public void testValidation() {
5656

5757
ValidationException e = policy.validate();
5858
assertThat(e.validationErrors(),
59-
containsInAnyOrder("invalid policy id [a,b]: must not contain ','",
59+
containsInAnyOrder(
60+
"invalid policy id [a,b]: must not contain the following characters [ , \", *, \\, <, |, ,, >, /, ?]",
6061
"invalid snapshot name [<my, snapshot-{now/M}>]: must not contain contain" +
6162
" the following characters [ , \", *, \\, <, |, ,, >, /, ?]",
6263
"invalid repository name [ ]: cannot be empty",

0 commit comments

Comments
 (0)