From 9d27e566a1b9b14fd7e61a0b4eeec1c4e4dc335a Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 23 Dec 2016 11:33:30 +0100 Subject: [PATCH] + hardened encoding soap-content detected --- .../apps/protocols/http/mode/soapcontent.pm | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/centreon-plugins/apps/protocols/http/mode/soapcontent.pm b/centreon-plugins/apps/protocols/http/mode/soapcontent.pm index 6b16b75d9..9b7743626 100644 --- a/centreon-plugins/apps/protocols/http/mode/soapcontent.pm +++ b/centreon-plugins/apps/protocols/http/mode/soapcontent.pm @@ -159,10 +159,30 @@ sub display_output { } } +sub check_encoding { + my ($self, %options) = @_; + + my $charset; + my $headers = $self->{http}->get_header(); + my $content_type = $headers->header('Content-Type'); + if (defined($content_type) && $content_type =~ /charset\s*=\s*(\S+)/i) { + $charset = $1; + } + + if ($self->{soap_response} =~ /<\?xml(.*?)\?>/ms) { + if ($1 !~ /encoding=/ && defined($charset)) { + $self->{soap_response} =~ s/<\?xml(.*?)\?>/<\?xml$1 encoding="$charset"\?>/ms + } + } elsif (defined($charset)) { + $self->{soap_response} = '' . "\n" . $self->{soap_response}; + } +} + sub lookup { my ($self, %options) = @_; my ($xpath, $nodeset); + $self->check_encoding(); eval { $xpath = XML::XPath->new(xml => $self->{soap_response}); };