Skip to content

Commit

Permalink
check for nasty characters in sort columns
Browse files Browse the repository at this point in the history
  • Loading branch information
sni committed Nov 7, 2024
1 parent 92b37e2 commit 0e70b92
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ next:
- add new endpoint /system/cmd/log
- add more availability endpoint ex. /hostgroup/.../availability
- add support for simple calculations in columns
- check for nasty characters in sort columns
- fix unknown columns when using icinga2 without lmd
- Business Process:
- fix saving empty file in case of full filesystem
Expand Down
7 changes: 5 additions & 2 deletions lib/Thruk/Controller/rest_v1.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,9 @@ sub _apply_sort {

$key = $alias_columns->{$key} if defined $alias_columns->{$key};

# check for nasty chars
die("sort key contains invalid characters") if($key =~ m/[`\$\(>]/mx);

# sort numeric
if( defined $data->[0]->{$key} and Thruk::Backend::Manager::looks_like_number($data->[0]->{$key}) ) {
if($order eq 'asc') {
Expand All @@ -1195,9 +1198,9 @@ sub _apply_sort {
# sort alphanumeric
else {
if($order eq 'asc') {
push @compares, '$a->{"'.$key.'"} cmp $b->{"'.$key.'"}';
push @compares, '$a->{\''.$key.'\'} cmp $b->{\''.$key.'\'}';
} else {
push @compares, '$b->{"'.$key.'"} cmp $a->{"'.$key.'"}';
push @compares, '$b->{\''.$key.'\'} cmp $a->{\''.$key.'\'}';
}
}
}
Expand Down

0 comments on commit 0e70b92

Please sign in to comment.