Fix database mssql mode deadlocks#6127
Conversation
- transform value to "per second" value with cache
| foreach my $row (@{$query_result}) { | ||
| next if (defined($self->{option_results}->{filter_database}) && $self->{option_results}->{filter_database} ne '' | ||
| && $$row[0] !~ /$self->{option_results}->{filter_database}/); | ||
| next if (defined($self->{option_results}->{filter_instance}) && $self->{option_results}->{filter_instance} ne '' |
There was a problem hiding this comment.
User-provided filter_instance is directly interpolated into a regex ($$row[0] !~ /$self->{option_results}->{filter_instance}/), enabling regex injection or ReDoS. Validate or escape (e.g., quotemeta) filter_instance before use.
Details
✨ AI Reasoning
The code now uses the CLI option filter_instance (defaulting to '_Total' but still user-controlled) directly inside a Perl regex match: $$row[0] !~ /$self->{option_results}->{filter_instance}/. Interpolating unvalidated user input into a regex can lead to regex injection, syntax errors, or ReDoS issues. This was introduced by the PR when replacing filter_database with filter_instance and should be flagged. The problematic expression appears in the newly added filtering logic in both changed files.
🔧 How do I fix it?
Use parameterized queries with placeholders, array-based command execution (no shell interpretation), or properly escaped arguments using vetted libraries. Avoid dynamic queries/commands built with user input concatenation.
Reply @AikidoSec feedback: [FEEDBACK] to get better review comments in the future.
Reply @AikidoSec ignore: [REASON] to ignore this issue.
More info
| foreach my $row (@{$query_result}) { | ||
| next if (defined($self->{option_results}->{filter_database}) && $self->{option_results}->{filter_database} ne '' | ||
| && $$row[0] !~ /$self->{option_results}->{filter_database}/); | ||
| next if (defined($self->{option_results}->{filter_instance}) && $self->{option_results}->{filter_instance} ne '' |
There was a problem hiding this comment.
User-provided filter_instance is directly interpolated into a regex ($$row[0] !~ /$self->{option_results}->{filter_instance}/), enabling regex injection or ReDoS. Validate or escape (e.g., quotemeta) filter_instance before use.
Details
✨ AI Reasoning
In lockswaits.pm the PR added the same direct regex interpolation using the CLI-provided filter_instance option: $$row[0] !~ /$self->{option_results}->{filter_instance}/. This introduces the same risk of regex injection or denial-of-service via crafted patterns. The change replaced the previous filter_database usage, so this new usage should be reviewed.
🔧 How do I fix it?
Use parameterized queries with placeholders, array-based command execution (no shell interpretation), or properly escaped arguments using vetted libraries. Avoid dynamic queries/commands built with user input concatenation.
Reply @AikidoSec feedback: [FEEDBACK] to get better review comments in the future.
Reply @AikidoSec ignore: [REASON] to ignore this issue.
More info
…m/i-Vertix/centreon-plugins into fix-database-mssql-mode-deadlocks
| && $$row[0] !~ /$self->{option_results}->{filter_database}/); | ||
| my $instance = $$row[0]; | ||
| $instance =~ s/^\s+|\s+$//g; | ||
| if (defined($self->{option_results}->{filter_instance}) && $self->{option_results}->{filter_instance} ne '' |
There was a problem hiding this comment.
User-provided filter_instance is used directly in a regex (/.../), enabling regex injection or ReDoS. Validate or escape the pattern before using it, or use a safe comparison method.
Details
✨ AI Reasoning
The deadlocks mode changes mirror the lockswaits changes: option_results.filter_instance is matched via a regex built from user-supplied input without escaping/validation. This can lead to regex injection or performance denial-of-service via catastrophic backtracking. The risk stems from newly added code that uses the raw option value in a regex match.
🔧 How do I fix it?
Use parameterized queries with placeholders, array-based command execution (no shell interpretation), or properly escaped arguments using vetted libraries. Avoid dynamic queries/commands built with user input concatenation.
Reply @AikidoSec feedback: [FEEDBACK] to get better review comments in the future.
Reply @AikidoSec ignore: [REASON] to ignore this issue.
More info
|
Hi @rmorandell-pgum, |
Community contributors
Description
According to my analysis, the mode for database::mssql::mode::lockswaits and database::mssql::mode::deadlocks is incorrectly designed.
Here is the Microsoft documentation about this performance counters.
In my case the query of the plugin executed on the MSSQL Server looks like this.
There is always a “_Total”. So, the filter should be –filter-instance instead of –filter-database and the default value should be “_Total” which is the total of all other single instances.
This gives us the difference from the last measurement.
Type of change
How this pull request can be tested ?
Checklist
Summary by Aikido
⚡ Enhancements
More info