Skip to content

Commit 3711181

Browse files
committed
Escape and quote rule names when searching for elastalert metadata.
1 parent 1fb0537 commit 3711181

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

src/handlers/metadata/get.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,43 @@ import config from '../../common/config';
22
import { getClient } from '../../common/elasticsearch_client';
33

44

5+
function escapeLuceneSyntax(str) {
6+
return [].map
7+
.call(str, char => {
8+
if (
9+
char === '/' ||
10+
char === '+' ||
11+
char === '-' ||
12+
char === '&' ||
13+
char === '|' ||
14+
char === '!' ||
15+
char === '(' ||
16+
char === ')' ||
17+
char === '{' ||
18+
char === '}' ||
19+
char === '[' ||
20+
char === ']' ||
21+
char === '^' ||
22+
char === '"' ||
23+
char === '~' ||
24+
char === '*' ||
25+
char === '?' ||
26+
char === ':' ||
27+
char === '\\'
28+
) {
29+
return `\\${char}`;
30+
}
31+
return char;
32+
})
33+
.join('');
34+
}
35+
536
function getQueryString(request) {
637
if (request.params.type === 'elastalert_error') {
738
return '*:*';
839
}
940
else {
10-
return `rule_name:${request.query.rule_name || '*'}`;
41+
return `rule_name:"${escapeLuceneSyntax(request.query.rule_name) || '*'}"`;
1142
}
1243
}
1344

0 commit comments

Comments
 (0)