<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Random ramblings about Technology : PII</title><link>http://blogs.msdn.com/martijnh/archive/tags/PII/default.aspx</link><description>Tags: PII</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Suppressing Personal Identifiable Information (PII) in WCF log files</title><link>http://blogs.msdn.com/martijnh/archive/2008/08/18/suppressing-personal-identifiable-information-pii-in-wcf-log-files.aspx</link><pubDate>Mon, 18 Aug 2008 23:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8877108</guid><dc:creator>martijnh</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/martijnh/comments/8877108.aspx</comments><wfw:commentRss>http://blogs.msdn.com/martijnh/commentrss.aspx?PostID=8877108</wfw:commentRss><description>&lt;P&gt;Given the vast amount of information transported between systems in today's enterprise environments, a lot of which is considered either private (addresses, social security numbers, credit card information, mortgage and pension plans, etc) or of high business value, information security is key.&lt;/P&gt;
&lt;P&gt;From the release of WCF, it has brought us tremendous flexibility and allowed development teams to be almost completely agnostic of the way information is transported between point A to point B, focusing on adding business value instead.&lt;/P&gt;
&lt;P&gt;Another great feature WCF brings us is runtime troubleshooting. In WCF, an administrator can simply enable &lt;A href="http://msdn.microsoft.com/en-us/library/ms731308.aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms731308.aspx"&gt;logging&lt;/A&gt; to troubleshoot an environment which is in production.&lt;/P&gt;
&lt;P&gt;Although a great feature for troubleshooting, Personal Identifiable Information (PII) you care about deeply while on the wire (using transport and message-level security to protect it) is available in plain text if logging is turned on at the server side.&lt;/P&gt;
&lt;P&gt;WCF's logging features currently filter out specific PII by default (only if the message is not &lt;A href="http://msdn.microsoft.com/en-us/library/ms730318.aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms730318.aspx"&gt;malformed&lt;/A&gt;). However, this functionality is not exposed to the developer.&lt;/P&gt;
&lt;P&gt;Consider the following scenario:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;You want the administrator to be able to monitor messages for auditing, logging or troubleshooting purposes; 
&lt;LI&gt;certain information is considered PII and should not show up in the log files.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;You could write your own logging subsystem and hook it in to your services. This takes a lot of work, is error prone, needs custom maintenance, documentation, etc.&lt;/P&gt;
&lt;P&gt;My proposal for the scenario:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Use a behavior which 
&lt;UL&gt;
&lt;LI&gt;introspects the published &lt;A href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.serviceendpoint.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.serviceendpoint.aspx"&gt;ServiceEndPoint&lt;/A&gt;s for published &lt;A href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.operationdescription.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.operationdescription.aspx"&gt;OperationDescription&lt;/A&gt;s and the used &lt;A href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractattribute.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractattribute.aspx"&gt;DataContract&lt;/A&gt;s, 
&lt;LI&gt;finds public properties on the DataContract marked as PII; 
&lt;LI&gt;instructs the WCF logging runtime to ignore the contents of the specified message elements.&lt;/LI&gt;&lt;/UL&gt;
&lt;LI&gt;configure the behavior through code (this is not generally considered a best practice, but the security needs of the service outweighs the flexibility needs of configuration);&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Let's have a look at how the solution works:&lt;/P&gt;
&lt;P&gt;Take a DataContract, e.g. PurchaseOrder and apply an attribute (PII) on each property which represents PII.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/martijnh/WindowsLiveWriter/SuppressingPersonalIdentifiableInformati_C46F/wcf_pii_datacontract_2.png" mce_href="http://blogs.msdn.com/blogfiles/martijnh/WindowsLiveWriter/SuppressingPersonalIdentifiableInformati_C46F/wcf_pii_datacontract_2.png"&gt;&lt;IMG style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px" height=174 alt=wcf_pii_datacontract src="http://blogs.msdn.com/blogfiles/martijnh/WindowsLiveWriter/SuppressingPersonalIdentifiableInformati_C46F/wcf_pii_datacontract_thumb.png" width=388 border=0 mce_src="http://blogs.msdn.com/blogfiles/martijnh/WindowsLiveWriter/SuppressingPersonalIdentifiableInformati_C46F/wcf_pii_datacontract_thumb.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;Next, add a PIIProtectionBehavior attribute to your service implementation class&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/martijnh/WindowsLiveWriter/SuppressingPersonalIdentifiableInformati_C46F/wcf_pii_protectionbehavior_attribute_2.png" mce_href="http://blogs.msdn.com/blogfiles/martijnh/WindowsLiveWriter/SuppressingPersonalIdentifiableInformati_C46F/wcf_pii_protectionbehavior_attribute_2.png"&gt;&lt;IMG style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px" height=107 alt=wcf_pii_protectionbehavior_attribute src="http://blogs.msdn.com/blogfiles/martijnh/WindowsLiveWriter/SuppressingPersonalIdentifiableInformati_C46F/wcf_pii_protectionbehavior_attribute_thumb.png" width=613 border=0 mce_src="http://blogs.msdn.com/blogfiles/martijnh/WindowsLiveWriter/SuppressingPersonalIdentifiableInformati_C46F/wcf_pii_protectionbehavior_attribute_thumb.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;You're done. The PIIProtectionBehavior attribute is also an &lt;A href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.iservicebehavior.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.iservicebehavior.aspx"&gt;IServiceBehavior&lt;/A&gt; implementation which performs the introspection on the EndPoints.&lt;/P&gt;
&lt;P&gt;The result when logging is turned on:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/martijnh/WindowsLiveWriter/SuppressingPersonalIdentifiableInformati_C46F/wcf_pii_messagelogging_2.png" mce_href="http://blogs.msdn.com/blogfiles/martijnh/WindowsLiveWriter/SuppressingPersonalIdentifiableInformati_C46F/wcf_pii_messagelogging_2.png"&gt;&lt;IMG style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px" height=135 alt=wcf_pii_messagelogging src="http://blogs.msdn.com/blogfiles/martijnh/WindowsLiveWriter/SuppressingPersonalIdentifiableInformati_C46F/wcf_pii_messagelogging_thumb.png" width=389 border=0 mce_src="http://blogs.msdn.com/blogfiles/martijnh/WindowsLiveWriter/SuppressingPersonalIdentifiableInformati_C46F/wcf_pii_messagelogging_thumb.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;As you can see, 'CreditCardnumber' is no longer logged, it just displays '&amp;lt;-- Removed --&amp;gt;' .&lt;/P&gt;
&lt;P&gt;I've attached the sample code, hope it's useful!&lt;/P&gt;
&lt;P&gt;Ofcourse, the normal disclaimers apply, the accompanied sample is for educational purposes only, it has not gone through rigorous testing, might contain bugs due to limited testing (me ;-)), etc. Please see the sourcecode for further remarks.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8877108" width="1" height="1"&gt;</description><enclosure url="http://blogs.msdn.com/martijnh/attachment/8877108.ashx" length="15673" type="application/x-zip-compressed" /><category domain="http://blogs.msdn.com/martijnh/archive/tags/WCF/default.aspx">WCF</category><category domain="http://blogs.msdn.com/martijnh/archive/tags/.NET/default.aspx">.NET</category><category domain="http://blogs.msdn.com/martijnh/archive/tags/Security/default.aspx">Security</category><category domain="http://blogs.msdn.com/martijnh/archive/tags/PII/default.aspx">PII</category></item></channel></rss>