Skip to content

Commit

Permalink
Merge pull request #68 from CyberSource/bugfix-readers
Browse files Browse the repository at this point in the history
Bugfix for closing reader
  • Loading branch information
gnongsie authored Apr 18, 2024
2 parents af287b0 + 7e0a2ee commit 25a1952
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 26 deletions.
2 changes: 1 addition & 1 deletion CyberSource.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>CyberSource</id>
<version>1.4.5</version>
<version>1.4.6</version>
<title>CyberSource Corporation</title>
<authors>CyberSource Corporation</authors>
<owners>CyberSource Corporation</owners>
Expand Down
4 changes: 2 additions & 2 deletions CyberSource/Base/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.4.5")]
[assembly: AssemblyFileVersion("1.4.5")]
[assembly: AssemblyVersion("1.4.6")]
[assembly: AssemblyFileVersion("1.4.6")]
48 changes: 28 additions & 20 deletions CyberSource/Client/CustomTextMessageEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,35 +59,43 @@ public override Message ReadMessage(ArraySegment<byte> buffer, BufferManager buf

public override Message ReadMessage(Stream stream, int maxSizeOfHeaders, string contentType)
{
var sr = new StreamReader(stream);
var wireResponse = sr.ReadToEnd();
sr.Close();
String wireResponse;

using (var sr = new StreamReader(stream))
{
wireResponse = sr.ReadToEnd();
}

// Fix for Xml external entity injection violation in fortify report
XmlReaderSettings settings = new XmlReaderSettings();
settings.DtdProcessing = DtdProcessing.Prohibit;
settings.XmlResolver = null;

XmlDocument doc = new XmlDocument();
StringReader stringReader = new StringReader(wireResponse);
XmlReader reader = XmlReader.Create(stringReader, settings);
doc.Load(reader);
//We need to get rid of the security header because it is not signed by the web service.
//The whole reason for the custom Encoder is to do this. the client rejected the unsigned header.
//Our WCF client is set up to allow the absence of a security header but if the header exists then it must be signed.
//Hopefully the namespace will not change. Maybe it should be put in a config.
XPathNavigator n = doc.CreateNavigator();
if (n.MoveToFollowing("Security", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"))
Message returnMessage = null;

using (StringReader stringReader = new StringReader(wireResponse))
{
n.DeleteSelf();
using (XmlReader reader = XmlReader.Create(stringReader, settings))
{
doc.Load(reader);

//We need to get rid of the security header because it is not signed by the web service.
//The whole reason for the custom Encoder is to do this. the client rejected the unsigned header.
//Our WCF client is set up to allow the absence of a security header but if the header exists then it must be signed.
//Hopefully the namespace will not change. Maybe it should be put in a config.

XPathNavigator n = doc.CreateNavigator();
if (n.MoveToFollowing("Security", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"))
{
n.DeleteSelf();
}

StringReader stringReaderInnerXml = new StringReader(doc.InnerXml);
XmlReader reader2 = XmlReader.Create(stringReaderInnerXml, settings);
returnMessage = Message.CreateMessage(reader2, maxSizeOfHeaders, MessageVersion.Soap11);
}
}
StringReader stringReaderInnerXml = new StringReader(doc.InnerXml);
reader = XmlReader.Create(stringReaderInnerXml, settings);
Message returnMessage = Message.CreateMessage(reader, maxSizeOfHeaders, MessageVersion.Soap11);

stringReader.Close();
stringReaderInnerXml.Close();
reader.Close();

return returnMessage;
}
Expand Down
4 changes: 2 additions & 2 deletions CyberSource/Client/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.4.5")]
[assembly: AssemblyFileVersion("1.4.5")]
[assembly: AssemblyVersion("1.4.6")]
[assembly: AssemblyFileVersion("1.4.6")]
2 changes: 1 addition & 1 deletion CyberSourceTests/MTTest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static void ThreadMethod()
request.Add("billTo_ipAddress", "10.7.111.111");
request.Add("card_accountNumber", "4111111111111111");
request.Add("card_expirationMonth", "12");
request.Add("card_expirationYear", "2020");
request.Add("card_expirationYear", "2030");
request.Add("purchaseTotals_currency", "USD");

// there are two items in this sample
Expand Down

0 comments on commit 25a1952

Please sign in to comment.