From faff09a392119eba60a63d5b366e7dbbfefedb4c Mon Sep 17 00:00:00 2001 From: Eduardo Theiji Date: Tue, 6 Sep 2022 18:12:21 -0300 Subject: [PATCH 1/5] Fixed crashes on some SOAP 1.2 requests when using GetBufferedInputStream (#1759) --- .../Extensions/SoapRequest.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Elastic.Apm.AspNetFullFramework/Extensions/SoapRequest.cs b/src/Elastic.Apm.AspNetFullFramework/Extensions/SoapRequest.cs index d3ce8d929..03685531f 100644 --- a/src/Elastic.Apm.AspNetFullFramework/Extensions/SoapRequest.cs +++ b/src/Elastic.Apm.AspNetFullFramework/Extensions/SoapRequest.cs @@ -116,6 +116,14 @@ internal static string GetSoap12ActionFromInputStream(Stream stream) //If that's the case we don't need to care about them here. They will flow somewhere else. return null; } + finally + { + var streamReader = new StreamReader(stream); + streamReader.ReadToEnd(); + if (stream.CanSeek) + stream.Seek(0, SeekOrigin.Begin); //StreamReader doesn't have the Seek method, stream does. + streamReader.ReadToEnd(); // This now works + } } } } From 16a1a281a6a12748431a343fef8bd9341fdf1730 Mon Sep 17 00:00:00 2001 From: Eduardo Theiji Date: Thu, 8 Sep 2022 13:52:35 -0300 Subject: [PATCH 2/5] add a reproducer/test --- .../Soap/SoapRequestTests.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/Elastic.Apm.AspNetFullFramework.Tests/Soap/SoapRequestTests.cs b/test/Elastic.Apm.AspNetFullFramework.Tests/Soap/SoapRequestTests.cs index 8885a971c..c31a247e0 100644 --- a/test/Elastic.Apm.AspNetFullFramework.Tests/Soap/SoapRequestTests.cs +++ b/test/Elastic.Apm.AspNetFullFramework.Tests/Soap/SoapRequestTests.cs @@ -31,7 +31,8 @@ public async Task Name_Should_Should_Not_Throw_Exception_When_Asmx_Soap12_Reques var pathData = SampleAppUrlPaths.CallSoapServiceProtocolV12; var action = "Input"; - var input = @"This is the input"; + var input = string.Join("", Enumerable.Repeat(@"This is the input.", 300)); + var request = new HttpRequestMessage(HttpMethod.Post, pathData.Uri) { Content = new StringContent($@" From fe639a0cee39dab39067f0be855e82d6687ff033 Mon Sep 17 00:00:00 2001 From: Eduardo Theiji Yshimaro Date: Mon, 12 Sep 2022 13:19:17 -0300 Subject: [PATCH 3/5] updated PR as suggested --- .../Extensions/SoapRequest.cs | 12 ++++++------ .../Soap/SoapRequestTests.cs | 6 ++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Elastic.Apm.AspNetFullFramework/Extensions/SoapRequest.cs b/src/Elastic.Apm.AspNetFullFramework/Extensions/SoapRequest.cs index 03685531f..88aaf0991 100644 --- a/src/Elastic.Apm.AspNetFullFramework/Extensions/SoapRequest.cs +++ b/src/Elastic.Apm.AspNetFullFramework/Extensions/SoapRequest.cs @@ -84,8 +84,12 @@ private static bool IsSoap12Action(NameValueCollection headers) internal static string GetSoap12ActionFromInputStream(Stream stream) { + StreamReader streamReader = null; + try { + streamReader = new StreamReader(stream); + var settings = new XmlReaderSettings { IgnoreProcessingInstructions = true, @@ -93,7 +97,7 @@ internal static string GetSoap12ActionFromInputStream(Stream stream) IgnoreWhitespace = true }; - using var reader = XmlReader.Create(stream, settings); + using var reader = XmlReader.Create(streamReader, settings); reader.MoveToContent(); if (reader.LocalName != "Envelope") return null; @@ -118,11 +122,7 @@ internal static string GetSoap12ActionFromInputStream(Stream stream) } finally { - var streamReader = new StreamReader(stream); - streamReader.ReadToEnd(); - if (stream.CanSeek) - stream.Seek(0, SeekOrigin.Begin); //StreamReader doesn't have the Seek method, stream does. - streamReader.ReadToEnd(); // This now works + streamReader?.ReadToEnd(); } } } diff --git a/test/Elastic.Apm.AspNetFullFramework.Tests/Soap/SoapRequestTests.cs b/test/Elastic.Apm.AspNetFullFramework.Tests/Soap/SoapRequestTests.cs index c31a247e0..bcb63f13c 100644 --- a/test/Elastic.Apm.AspNetFullFramework.Tests/Soap/SoapRequestTests.cs +++ b/test/Elastic.Apm.AspNetFullFramework.Tests/Soap/SoapRequestTests.cs @@ -26,12 +26,14 @@ public SoapRequestTests(ITestOutputHelper xUnitOutputHelper) /// to parse the parameters for the web method. /// [AspNetFullFrameworkFact] - public async Task Name_Should_Should_Not_Throw_Exception_When_Asmx_Soap12_Request() + [InlineData(false)] + [InlineData(true)] + public async Task Name_Should_Should_Not_Throw_Exception_When_Asmx_Soap12_Request(bool useLargePayload) { var pathData = SampleAppUrlPaths.CallSoapServiceProtocolV12; var action = "Input"; - var input = string.Join("", Enumerable.Repeat(@"This is the input.", 300)); + var input = useLargePayload ? string.Join("", Enumerable.Repeat("This is a large input. ", 500)) : "This is the input"; var request = new HttpRequestMessage(HttpMethod.Post, pathData.Uri) { From 0b8392d123910b33f43ca435ea059798f93e7e9e Mon Sep 17 00:00:00 2001 From: Eduardo Theiji Yshimaro Date: Mon, 12 Sep 2022 13:31:05 -0300 Subject: [PATCH 4/5] Update SoapRequest.cs --- src/Elastic.Apm.AspNetFullFramework/Extensions/SoapRequest.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Elastic.Apm.AspNetFullFramework/Extensions/SoapRequest.cs b/src/Elastic.Apm.AspNetFullFramework/Extensions/SoapRequest.cs index 88aaf0991..47f1d26f3 100644 --- a/src/Elastic.Apm.AspNetFullFramework/Extensions/SoapRequest.cs +++ b/src/Elastic.Apm.AspNetFullFramework/Extensions/SoapRequest.cs @@ -85,11 +85,9 @@ private static bool IsSoap12Action(NameValueCollection headers) internal static string GetSoap12ActionFromInputStream(Stream stream) { StreamReader streamReader = null; - try { streamReader = new StreamReader(stream); - var settings = new XmlReaderSettings { IgnoreProcessingInstructions = true, From cdce0552aa459b6ba96c17951dceba00bf8d8e6b Mon Sep 17 00:00:00 2001 From: Eduardo Theiji Date: Tue, 13 Sep 2022 14:43:29 -0300 Subject: [PATCH 5/5] Change Fact method in test to Theory method --- .../Soap/SoapRequestTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Elastic.Apm.AspNetFullFramework.Tests/Soap/SoapRequestTests.cs b/test/Elastic.Apm.AspNetFullFramework.Tests/Soap/SoapRequestTests.cs index bcb63f13c..7105f2d02 100644 --- a/test/Elastic.Apm.AspNetFullFramework.Tests/Soap/SoapRequestTests.cs +++ b/test/Elastic.Apm.AspNetFullFramework.Tests/Soap/SoapRequestTests.cs @@ -25,7 +25,7 @@ public SoapRequestTests(ITestOutputHelper xUnitOutputHelper) /// does not cause an exception to be thrown when the framework deserializes the input stream /// to parse the parameters for the web method. /// - [AspNetFullFrameworkFact] + [AspNetFullFrameworkTheory] [InlineData(false)] [InlineData(true)] public async Task Name_Should_Should_Not_Throw_Exception_When_Asmx_Soap12_Request(bool useLargePayload)