<?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>Alik Levin's : Input Validation</title><link>http://blogs.msdn.com/alikl/archive/tags/Input+Validation/default.aspx</link><description>Tags: Input Validation</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Security Code Review – String Search Patterns For Finding Input Validation Vulnerabilities</title><link>http://blogs.msdn.com/alikl/archive/2008/07/11/security-code-review-string-search-patterns-for-finding-input-validation-vulnerabilities.aspx</link><pubDate>Fri, 11 Jul 2008 14:24:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8721000</guid><dc:creator>alikl</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/alikl/comments/8721000.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alikl/commentrss.aspx?PostID=8721000</wfw:commentRss><wfw:comment>http://blogs.msdn.com/alikl/rsscomments.aspx?PostID=8721000</wfw:comment><description>&lt;p&gt;Well defined set of search patterns helps significantly reduce time (cost) when performing security code inspections. This post focuses on input validation vulnerabilities commonly found in ASP.NET web applications.&lt;/p&gt;  &lt;h3&gt;SQL Injection and Cross Site Scripting (XSS) String search patterns&lt;/h3&gt;  &lt;p&gt;SQL Injections and XSS attacks are most common that exploit improper data access and lack of output encoding. Following are the how-to’s on finding these vulnerabilities:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://blogs.msdn.com/alikl/archive/2008/03/17/quickly-find-and-fix-cross-site-scripting-xss-vulnerabilities-in-your-asp-net-application.aspx" target="_blank"&gt;Quickly Find And Fix Cross Site Scripting (XSS) Vulnerabilities In Your ASP.NET Application.&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/alikl/archive/2007/03/31/security-code-inspection-eternal-search-for-sql-injection.aspx" target="_blank"&gt;Security Code Inspection - Eternal Search For SQL Injection&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;Input Validation vulnerabilities String Search Patterns&lt;/h3&gt;  &lt;p&gt;To search and find security vulnerabilities you start &lt;a href="http://msdn.microsoft.com/en-us/library/ms998375.aspx" target="_blank"&gt;asking questions&lt;/a&gt; or better yet create a list of the questions. Here is the example how - &lt;a href="http://blogs.msdn.com/ace_team/archive/2008/01/15/generate-your-own-security-code-review-checklist-document-using-outlook-2007.aspx"&gt;Generate Your Own Security Code Review Checklist Document Using Outlook 2007&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Use search utility similar to FindStr to perform your searches (look at &lt;a href="http://msdn.microsoft.com/en-us/library/aa302437.aspx#c21618429_004" target="_blank"&gt;Performing Text Searches&lt;/a&gt;). When Visual Studio is available then you can use it - &lt;a href="http://blogs.msdn.com/alikl/archive/2007/06/05/visual-studio-2005-as-general-code-search-tool.aspx" target="_blank"&gt;Visual Studio 2005 As General Code Search Tool&lt;/a&gt;. Any other search tool is just fine. Following are the most common questions and search patterns.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;h4&gt;Does the code rely on client-side validation?&lt;/h4&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;If the code does not use Validators or Regex there is a potential vulnerability. Review each control how it is validated for type, length, range, string format. In the searches I assume there is no inline code and developers use code behind technique to separate markup from code.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;ASP.NET pages &lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;findstr /S /I &amp;quot;.Validator&amp;quot; *.aspx&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;User Controls&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;findstr /S /I &amp;quot;.Validator&amp;quot; *.ascx&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Source code&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;findstr /S /I &amp;quot;Regex&amp;quot; *.cs&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;h4&gt;Is the code susceptible to canonicalization attacks?&lt;/h4&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Review that there is no external input involved in building paths and file names.&lt;/p&gt;  &lt;p&gt;findstr /S /I “File&amp;quot; *.cs&lt;/p&gt;  &lt;p&gt;findstr /S /I “Path&amp;quot; *.cs&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;h4&gt;Does the code validate data from all sources? &lt;/h4&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;Using Cookies and QueryStrings poses a risk of the tampering threat (review &lt;a href="http://shapingsoftware.com/2008/03/30/stride-explained" target="_blank"&gt;STRIDE Explained&lt;/a&gt; to understand threats). If there is a use of Params property there is a chance for CSRF attack - &lt;a href="http://msdn.microsoft.com/en-us/testing/cc664492.aspx " target="_blank"&gt;Cross-Site Request Forgery Attack explained&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Cookies&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;findstr /S /I “Cookies&amp;quot; *.*&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Query Strings&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;findstr /S /I “QueryString&amp;quot; *.*&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Params&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;findstr /S /I “Params&amp;quot; *.*&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;h4&gt;Does the code use MapPath?&lt;/h4&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;If there is a usage of MapPath review that it does not use external input parameters and it is restricted to access only application file space. Make sure its third parameter set to false.&lt;/p&gt;  &lt;p&gt;findstr /S /I “MapPath&amp;quot; *.*&lt;/p&gt;  &lt;h3&gt;How To Mitigate Input And Data Validation Vulnerabilities&lt;/h3&gt;  &lt;p&gt;Below are detailed step-by-step guidelines for writing code that is not vulnerable to SQL Injections and XSS attacks:&lt;/p&gt;  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms998274.aspx" target="_blank"&gt;How To: Prevent Cross-Site Scripting in ASP.NET&lt;/a&gt; &lt;/li&gt;  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/bb355989.aspx" target="_blank"&gt;How To: Protect From Injection Attacks in ASP.NET&lt;/a&gt; &lt;/li&gt;  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms998271.aspx" target="_blank"&gt;How To: Protect From SQL Injection in ASP.NET&lt;/a&gt; &lt;/li&gt;  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms998267.aspx" target="_blank"&gt;How To: Use Regular Expressions to Constrain Input in ASP.NET&lt;/a&gt; &lt;/li&gt;  &lt;li&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=EFB9C819-53FF-4F82-BFAF-E11625130C25&amp;amp;displaylang=en" target="_blank"&gt;Microsoft Anti-Cross Site Scripting Library V1.5&lt;/a&gt;&amp;#160; &lt;/li&gt;  &lt;h3&gt;Share Your Practices&lt;/h3&gt;  &lt;p&gt;If you’ve got more search patterns to suggest – please do so! Let’s make the World [Wide Web] a more secure place together.&lt;/p&gt;  &lt;h3&gt;My Related Posts&lt;/h3&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://blogs.msdn.com/alikl/archive/2007/03/04/how-to-hack-wcf-new-technology-old-hacking-tricks.aspx"&gt;How To Hack WCF - New Technology, Old Hacking Tricks&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/alikl/archive/2008/05/25/wcf-security-input-data-validation-sample-visual-studio-project.aspx"&gt;WCF Security - Input/Data Validation Sample Visual Studio Project&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/alikl/archive/2008/05/25/wcf-security-input-data-validation-using-schemas.aspx"&gt;WCF Security - Input/Data Validation Using Schemas&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8721000" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alikl/archive/tags/Input+Validation/default.aspx">Input Validation</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Test+Phase/default.aspx">Test Phase</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Security/default.aspx">Security</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Tools/default.aspx">Tools</category></item><item><title>WCF Security - Input/Data Validation Using Schemas</title><link>http://blogs.msdn.com/alikl/archive/2008/05/25/wcf-security-input-data-validation-using-schemas.aspx</link><pubDate>Sun, 25 May 2008 17:52:48 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8551021</guid><dc:creator>alikl</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/alikl/comments/8551021.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alikl/commentrss.aspx?PostID=8551021</wfw:commentRss><wfw:comment>http://blogs.msdn.com/alikl/rsscomments.aspx?PostID=8551021</wfw:comment><description>&lt;p&gt;WCF offers very flexible approach of Input and Data Validation based on XML Schemas. The approach is flexible since the validation rules are expressed in form of XML schema and can be changed at any time without recompiling the solution.&lt;/p&gt;  &lt;p&gt;I followed the steps detailed in &lt;a href="http://www.codeplex.com/WCFSecurity/Wiki/View.aspx?title=How%20To%20-%20Perform%20Message%20Validation%20with%20Schemas%20in%20WCF&amp;amp;referringTitle=How%20Tos" target="_blank"&gt;How To: Perform Message Validation with Schema Validation in WCF&lt;/a&gt; and ended up with another working sample (imagine that!).&lt;/p&gt;  &lt;p&gt;It took me a bit to struggle with the schema thing and then &lt;a href="http://msdn.microsoft.com/en-us/library/ms788993.aspx" target="_blank"&gt;enabling debugging&lt;/a&gt; info on the service side (remember, WCF is secure by default) to understand what's going on and why it fails time after time.&lt;/p&gt;  &lt;p&gt;In the end me and WCF made friends and I'd thought it'd be good to share with you the Visual Studio project. Download it &lt;a href="http://cid-dd25b83e4ca261f7.skydrive.live.com/self.aspx/Visual%20Studio%20Projects/WCFInputValidationSchema.zip" target="_blank"&gt;here&lt;/a&gt; from my SkyDrive and save yourself some time. &lt;/p&gt;  &lt;p&gt;&lt;iframe style="border-right: #dde5e9 1px solid; padding-right: 0px; border-top: #dde5e9 1px solid; padding-left: 0px; padding-bottom: 0px; margin: 3px; border-left: #dde5e9 1px solid; width: 240px; padding-top: 0px; border-bottom: #dde5e9 1px solid; height: 66px; background-color: #ffffff" marginwidth="0" marginheight="0" src="http://cid-dd25b83e4ca261f7.skydrive.live.com/embedrowdetail.aspx/Visual%20Studio%20Projects/WCFInputValidationSchema.zip" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;/p&gt;  &lt;h3&gt;My related posts&lt;/h3&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://blogs.msdn.com/alikl/archive/2008/05/25/wcf-security-input-data-validation-sample-visual-studio-project.aspx"&gt;WCF Security - Input/Data Validation Sample Visual Studio Project&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Enjoy.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8551021" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alikl/archive/tags/WCF/default.aspx">WCF</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Input+Validation/default.aspx">Input Validation</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Security/default.aspx">Security</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Development+Phase/default.aspx">Development Phase</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Implementation/default.aspx">Implementation</category></item><item><title>WCF Security - Input/Data Validation Sample Visual Studio Project</title><link>http://blogs.msdn.com/alikl/archive/2008/05/25/wcf-security-input-data-validation-sample-visual-studio-project.aspx</link><pubDate>Sun, 25 May 2008 14:17:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8550886</guid><dc:creator>alikl</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/alikl/comments/8550886.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alikl/commentrss.aspx?PostID=8550886</wfw:commentRss><wfw:comment>http://blogs.msdn.com/alikl/rsscomments.aspx?PostID=8550886</wfw:comment><description>&lt;p&gt;Input and Data Validation is one of the &lt;a href="http://shapingsoftware.com/2008/04/07/security-frame/" target="_blank"&gt;core security principles&lt;/a&gt;. &lt;a href="http://blogs.msdn.com/alikl/archive/2007/03/04/how-to-hack-wcf-new-technology-old-hacking-tricks.aspx" target="_blank"&gt;WCF is no exception&lt;/a&gt;. To get most out of WCF in secure way one must implement proper Input and Data Validation.&lt;/p&gt;  &lt;p&gt;I was following instructions on &lt;a href="http://www.codeplex.com/WCFSecurity/Wiki/View.aspx?title=How%20To%20-%20Perform%20Input%20Validation%20in%20WCF&amp;amp;referringTitle=How%20Tos" target="_blank"&gt;How To &amp;#8211; Perform Input Validation in WCF&lt;/a&gt; compiled by patterns&amp;amp;practice team lead by &lt;a href="http://blogs.msdn.com/jmeier" target="_blank"&gt;JD Meier&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;In a nutshell the process consists of creating 3 classes and tweaking a config file a &amp;quot;bit&amp;quot;.&lt;/p&gt;  &lt;p&gt;From the guide:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Step 4 &amp;#8211; Create a Class That Implements the Validation Logic &lt;/li&gt;    &lt;li&gt;Step 5 &amp;#8211; Create a Class That Implements a Custom Endpoint Behavior &lt;/li&gt;    &lt;li&gt;Step 6 &amp;#8211; Create a Class That Implements a Custom Configuration Element &lt;/li&gt;    &lt;li&gt;Step 7 &amp;#8211; Add the Custom Behavior to the Configuration File &lt;/li&gt;    &lt;li&gt;Step 8 &amp;#8211; Create an Endpoint Behavior and Map It to Use the Custom Behavior &lt;/li&gt;    &lt;li&gt;Step 9 &amp;#8211; Configure the Service Endpoint to Use the Endpoint Behavior &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;I ended up with working sample built with Visual Studio 2008. I though it'd be good idea to share it to help you boost your productivity.&lt;/p&gt;  &lt;p&gt;Grab the Visual Studio project on my SkyDrive &lt;a href="http://cid-dd25b83e4ca261f7.skydrive.live.com/self.aspx/Visual%20Studio%20Projects/WCFInputValidation.zip" target="_blank"&gt;here&lt;/a&gt;. &lt;/p&gt; &lt;iframe style="border-right: #dde5e9 1px solid; padding-right: 0px; border-top: #dde5e9 1px solid; padding-left: 0px; padding-bottom: 0px; margin: 3px; border-left: #dde5e9 1px solid; width: 240px; padding-top: 0px; border-bottom: #dde5e9 1px solid; height: 66px; background-color: #ffffff" marginwidth="0" marginheight="0" src="http://cid-dd25b83e4ca261f7.skydrive.live.com/embedrowdetail.aspx/Visual%20Studio%20Projects/WCFInputValidation.zip" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;  &lt;p&gt;Enjoy&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8550886" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alikl/archive/tags/WCF/default.aspx">WCF</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Input+Validation/default.aspx">Input Validation</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Security/default.aspx">Security</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Development+Phase/default.aspx">Development Phase</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Implementation/default.aspx">Implementation</category></item><item><title>Quickly Find And Fix Cross Site Scripting (XSS) Vulnerabilities In Your ASP.NET Application.</title><link>http://blogs.msdn.com/alikl/archive/2008/03/17/quickly-find-and-fix-cross-site-scripting-xss-vulnerabilities-in-your-asp-net-application.aspx</link><pubDate>Mon, 17 Mar 2008 15:56:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8289686</guid><dc:creator>alikl</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/alikl/comments/8289686.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alikl/commentrss.aspx?PostID=8289686</wfw:commentRss><wfw:comment>http://blogs.msdn.com/alikl/rsscomments.aspx?PostID=8289686</wfw:comment><description>&lt;P&gt;Want to quickly check your ASP.NET Web application for &lt;A href="http://en.wikipedia.org/wiki/Cross-site_scripting" target=_blank mce_href="http://en.wikipedia.org/wiki/Cross-site_scripting"&gt;Cross Site Scripting (XSS) vulnerability&lt;/A&gt;?&lt;/P&gt;
&lt;P&gt;It is pretty easy with the knowledge and tools you already have. This post describes how to quickly find and fix most of XSS vulnerabilities in your code.&lt;/P&gt;
&lt;H3&gt;Why XSS vulnerabilities are possible&lt;/H3&gt;
&lt;P&gt;XSS vulnerabilities are possible when un-sanitized data printed out on the page. From what I witness when I do security code inspections most cases can be summarized to two most common:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Using &lt;SPAN style="COLOR: #2b91af"&gt;DataBinder&lt;/SPAN&gt;.Eval function: &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;SPAN style="BACKGROUND: #ffee62"&gt;&amp;lt;%&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;#&lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;DataBinder&lt;/SPAN&gt;.Eval(Container.DataItem, &lt;SPAN style="COLOR: #a31515"&gt;"TEXT"&lt;/SPAN&gt;) &lt;SPAN style="BACKGROUND: #ffee62"&gt;%&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;UL&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;LI&gt;Assigning to Text property of the control: &lt;/LI&gt;&lt;/UL&gt;&lt;PRE class=code&gt;Label1.Text = TextBox1.Text;&lt;/PRE&gt;&lt;PRE class=code&gt;&lt;UL&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;&lt;LI&gt;&lt;STRONG&gt;&lt;EM&gt;[Update 20.7.08] &lt;/EM&gt;&lt;/STRONG&gt;Assigning to Text property of the control: &lt;/LI&gt;&lt;/UL&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;SPAN style="BACKGROUND: #ffee62"&gt;&amp;lt;%&lt;/SPAN&gt;=myStringGoesHere...&lt;/P&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;UL&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;&lt;/UL&gt;
&lt;H3&gt;How to quickly find XSS vulnerabilities&lt;/H3&gt;
&lt;P&gt;Above patterns are easily identifiable using any strings search utility. I use &lt;A href="http://blogs.msdn.com/alikl/archive/2007/06/05/visual-studio-2005-as-general-code-search-tool.aspx" mce_href="http://blogs.msdn.com/alikl/archive/2007/06/05/visual-studio-2005-as-general-code-search-tool.aspx"&gt;Visual Studio 2005 As General Code Search Tool&lt;/A&gt; to find such vulnerabilities. When Visual Studio is not an option, just use FindStr, here is an example - &lt;A href="http://blogs.msdn.com/alikl/archive/2007/03/20/code-inspection-first-look-for-what-to-look-for.aspx" mce_href="http://blogs.msdn.com/alikl/archive/2007/03/20/code-inspection-first-look-for-what-to-look-for.aspx"&gt;Code Inspection - First Look For What To Look For&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Run your search for ".Eval(" and then for ".Text =". You might want to modify slightly it as some folks omit space before "=" or other minor changes. &lt;/P&gt;
&lt;P&gt;Use searches similar to these:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;findstr /S /I ".Text =" *.cs &lt;/LI&gt;
&lt;LI&gt;findstr /S /I ".Eval(" *.aspx &lt;/LI&gt;
&lt;LI&gt;findstr /S /I ".Eval(" *.ascx&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;&lt;EM&gt;[Update 20.7.08]&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp;findstr /S /I "&amp;lt;%=" *.aspx&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Ran your search yet? What do you see? Scared?&lt;/P&gt;
&lt;H3&gt;How to quickly fix XSS vulnerabilities&lt;/H3&gt;
&lt;P&gt;The fix is pretty simple - just apply Html Encoding to both cases. The best is using freely available &lt;A href="http://www.microsoft.com/info.aspx?na=47&amp;amp;p=1&amp;amp;SrcDisplayLang=en&amp;amp;SrcCategoryId=&amp;amp;SrcFamilyId=9a2b9c92-7ad9-496c-9a89-af08de2e5982&amp;amp;u=details.aspx%3ffamilyid%3dEFB9C819-53FF-4F82-BFAF-E11625130C25%26displaylang%3den" target=_blank mce_href="http://www.microsoft.com/info.aspx?na=47&amp;amp;p=1&amp;amp;SrcDisplayLang=en&amp;amp;SrcCategoryId=&amp;amp;SrcFamilyId=9a2b9c92-7ad9-496c-9a89-af08de2e5982&amp;amp;u=details.aspx%3ffamilyid%3dEFB9C819-53FF-4F82-BFAF-E11625130C25%26displaylang%3den"&gt;Microsoft Anti-Cross Site Scripting Library V1.5&lt;/A&gt;. Note that ASP.NET’s Server.HtmlEncode is not the safest one as it only encodes &amp;lt;,&amp;gt;,",&amp;amp; characters which is not sufficient to protect against all possible attacks.&lt;/P&gt;
&lt;H3&gt;My related posts&lt;/H3&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/alikl/archive/2008/01/24/security-code-review-use-visual-studio-bookmarks-to-capture-security-findings.aspx" mce_href="http://blogs.msdn.com/alikl/archive/2008/01/24/security-code-review-use-visual-studio-bookmarks-to-capture-security-findings.aspx"&gt;Security Code Review – Use Visual Studio Bookmarks To Capture Security Findings&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/alikl/archive/2007/03/31/security-code-inspection-eternal-search-for-sql-injection.aspx" mce_href="http://blogs.msdn.com/alikl/archive/2007/03/31/security-code-inspection-eternal-search-for-sql-injection.aspx"&gt;Security Code Inspection - Eternal Search For SQL Injection&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/alikl/archive/2007/11/21/asp-net-2-0-internet-security-reference-implementation-have-it-handy.aspx" mce_href="http://blogs.msdn.com/alikl/archive/2007/11/21/asp-net-2-0-internet-security-reference-implementation-have-it-handy.aspx"&gt;ASP.NET 2.0 Internet Security Reference Implementation - Have It Handy&lt;/A&gt; &lt;/LI&gt;&lt;/UL&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8289686" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alikl/archive/tags/Input+Validation/default.aspx">Input Validation</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Test+Phase/default.aspx">Test Phase</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Security/default.aspx">Security</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Tools/default.aspx">Tools</category></item><item><title>AJAX Security - Client Side Validation Is For Usability Only, Not For Security</title><link>http://blogs.msdn.com/alikl/archive/2007/10/03/ajax-security-client-side-validation-is-for-usability-only-not-for-security.aspx</link><pubDate>Wed, 03 Oct 2007 15:29:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5261117</guid><dc:creator>alikl</dc:creator><slash:comments>6</slash:comments><comments>http://blogs.msdn.com/alikl/comments/5261117.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alikl/commentrss.aspx?PostID=5261117</wfw:commentRss><wfw:comment>http://blogs.msdn.com/alikl/rsscomments.aspx?PostID=5261117</wfw:comment><description>&lt;blockquote&gt; &lt;p&gt;“As to methods there may be a million and then some, but principles are few. The man who grasps principles can successfully select his own methods. The man who tries methods, ignoring principles, is sure to have trouble.”  &lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Ralph_Waldo_Emerson" target="_blank"&gt;Ralph Waldo Emerson&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;AJAX is another technique among myriads of others to present information and to send it back to server.  &lt;p&gt;In &lt;a href="http://blogs.msdn.com/jmeier/archive/2007/03/18/driver-s-guide-vs-owner-s-manual.aspx" target="_blank"&gt;Driver's Guide vs. Owner's Manual&lt;/a&gt;&amp;nbsp;JD Meier provides great run down about the difference between "How things work" vs. "How to get most out of it".&lt;/p&gt; &lt;p&gt;Here is an example of how to apply it in practice:&lt;/p&gt; &lt;p&gt;In &lt;a href="http://weblogs.asp.net/davidbarkol/archive/2007/07/29/asp-net-ajax-role-application-service-visual-studio-2008-orcas.aspx" target="_blank"&gt;ASP.NET AJAX Role Application Service – Visual Studio 2008 (Orcas)&lt;/a&gt;&amp;nbsp;David walks through new feature introduced in Orcas - AJAX Roles service. It provides also some sample. This is Owner's Manual explaining how things work:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;function onLoadRolesCompleted(result, userContext, methodName){ if (Sys.Services.RoleService.isUserInRole("Administrator")){ $get("adminView").style.display = "block"; } }&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;In &lt;a href="http://weblogs.asp.net/mschwarz/archive/2007/07/30/asp-net-ajax-roles-and-security.aspx" target="_blank"&gt;ASP.NET AJAX Roles and Security&lt;/a&gt;&amp;nbsp;Michael comments on the above features pointing out the importance of server side role membership validation. This is Driver's Guide for safe and secure driving:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;"You have to test &lt;strong&gt;&lt;u&gt;ALWAYS&lt;/u&gt;&lt;/strong&gt; on the server-side code if the user has the needed user rights to execute your code."&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Some server side techniques to test server side code:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms978512.aspx#securityhowtosindex_input" target="_blank"&gt;Input and Data Validation&lt;/a&gt;  &lt;li&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms978512.aspx#securityhowtosindex_auth" target="_blank"&gt;Authentication and Authorization&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Here is another example&amp;nbsp;for not following core security principle of server side validation:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="http://blogs.msdn.com/alikl/archive/2007/03/04/how-to-hack-wcf-new-technology-old-hacking-tricks.aspx"&gt;How To Hack WCF - New Technology, Old Hacking Tricks&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=5261117" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alikl/archive/tags/Input+Validation/default.aspx">Input Validation</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Security/default.aspx">Security</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Development+Phase/default.aspx">Development Phase</category><category domain="http://blogs.msdn.com/alikl/archive/tags/AJAX/default.aspx">AJAX</category></item><item><title>Creating a Parameterized Query In Visual Studio</title><link>http://blogs.msdn.com/alikl/archive/2007/05/28/creating-a-parameterized-query-in-visual-studio.aspx</link><pubDate>Mon, 28 May 2007 07:10:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2933559</guid><dc:creator>alikl</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/alikl/comments/2933559.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alikl/commentrss.aspx?PostID=2933559</wfw:commentRss><wfw:comment>http://blogs.msdn.com/alikl/rsscomments.aspx?PostID=2933559</wfw:comment><description>&lt;p&gt;Creating parameterized queries is one of the major countermeasures&amp;nbsp;to SQL Injection attacks (not the ultimate but major).&lt;/p&gt; &lt;p&gt;I always did it in old fashion way - using code only and I am ashamed I never utilize advanced productivity features of Visual Studio.&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/bethmassi/default.aspx" target="_blank"&gt;Beth Massi&lt;/a&gt;&amp;nbsp;does great job explaining how to build parameterized queries in her &lt;a href="http://blogs.msdn.com/bethmassi/archive/2007/05/25/creating-a-parameterized-query.aspx" target="_blank"&gt;Creating a Parameterized Query&lt;/a&gt;&amp;nbsp;post. I must do some critics though here - I would really love to see other example rather&amp;nbsp;creating custom login form, say products catalog. Building custom authentication scheme is a surest way to disaster. I must admit that Beth put proper disclaimer though:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;(By the way, this example does NOT demonstrate a secure way of writing login forms. We'll be passing what the user enters directly into the database which stores the password in clear text. It is NOT safe practice to store clear text passwords in your database. I'll post a follow-up that talks about techniques we can use to protect users' passwords,&amp;nbsp;especially if we need to store them in a database. For now, let's concentrate on how we add parameterized queries to our TableAdapters.)&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Related articles:&lt;/p&gt; &lt;p&gt;&lt;a href="http://msdn2.microsoft.com/ms998271.aspx" target="_blank"&gt;How To: Protect From SQL Injection in ASP.NET&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://msdn2.microsoft.com/bb355989.aspx" target="_blank"&gt;How To: Protect From Injection Attacks in ASP.NET&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Good read, looking forward to see the post on passwords&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2933559" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alikl/archive/tags/Input+Validation/default.aspx">Input Validation</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Security/default.aspx">Security</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Implementation/default.aspx">Implementation</category></item><item><title>Security Code Inspection - Eternal Search For SQL Injection</title><link>http://blogs.msdn.com/alikl/archive/2007/03/31/security-code-inspection-eternal-search-for-sql-injection.aspx</link><pubDate>Sat, 31 Mar 2007 23:04:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2001473</guid><dc:creator>alikl</dc:creator><slash:comments>6</slash:comments><comments>http://blogs.msdn.com/alikl/comments/2001473.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alikl/commentrss.aspx?PostID=2001473</wfw:commentRss><wfw:comment>http://blogs.msdn.com/alikl/rsscomments.aspx?PostID=2001473</wfw:comment><description>&lt;P&gt;Here are couple of techniques I used for searching hints&amp;nbsp;of SQL Injections in .Net apps.&lt;/P&gt;
&lt;P&gt;The basic approach is described here &lt;A title=http://msdn2.microsoft.com/en-us/library/ms998399.aspx href="http://msdn2.microsoft.com/en-us/library/ms998399.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms998399.aspx"&gt;http://msdn2.microsoft.com/en-us/library/ms998399.aspx&lt;/A&gt;. It is basically split into two major parts - preliminary scan and the detailed scan. The keyword is hotspot - find hotspot and&amp;nbsp; investigate it accordingly. Hotspot can be something around &lt;A href="http://msdn2.microsoft.com/en-us/library/ms998271.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms998271.aspx"&gt;SQL injection&lt;/A&gt; or &lt;A href="http://msdn2.microsoft.com/en-us/library/ms998274.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms998274.aspx"&gt;XSS&lt;/A&gt;. I personally like calling it hints rather hotspot.&lt;/P&gt;
&lt;P&gt;Here are some techniques I used during &lt;A href="http://msdn2.microsoft.com/en-us/library/ms998364.aspx#paght000027_step2" mce_href="http://msdn2.microsoft.com/en-us/library/ms998364.aspx#paght000027_step2"&gt;preliminary scan&lt;/A&gt; to&amp;nbsp;find hints for SQL Injection:&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/alikl/archive/2007/03/20/code-inspection-first-look-for-what-to-look-for.aspx" mce_href="http://blogs.msdn.com/alikl/archive/2007/03/20/code-inspection-first-look-for-what-to-look-for.aspx"&gt;&lt;STRONG&gt;Code Inspection - First Look For What To Look For&lt;/STRONG&gt;&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;This technique allows to dump all the strings from compiled assemblies. It is very useful when looking for sensitive data in it but along the way one can recognize funny things: &lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/CodeInspectionFirstLookForWhatToLookFor_C01E/image022.png" atomicselection="true" mce_href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/CodeInspectionFirstLookForWhatToLookFor_C01E/image022.png"&gt;&lt;IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=101 src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/CodeInspectionFirstLookForWhatToLookFor_C01E/image0_thumb12.png" width=576 border=0 mce_src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/CodeInspectionFirstLookForWhatToLookFor_C01E/image0_thumb12.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;that can provide some hints for further investigation. &lt;/P&gt;
&lt;P&gt;ILDASM and FindStr are our friends with this technique. Resulting dump can be investigated using ... Outlook 2007 - &lt;A href="http://blogs.msdn.com/alikl/archive/2007/03/26/security-net-code-inspection-using-outlook-2007.aspx" mce_href="http://blogs.msdn.com/alikl/archive/2007/03/26/security-net-code-inspection-using-outlook-2007.aspx"&gt;Security .Net Code Inspection Using Outlook 2007&lt;/A&gt;:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/SecurityCodeInspectionUsingOutlook2007_878A/image011.png" atomicselection="true" mce_href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/SecurityCodeInspectionUsingOutlook2007_878A/image011.png"&gt;&lt;IMG height=347 src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/SecurityCodeInspectionUsingOutlook2007_878A/image0_thumb5.png" width=729 mce_src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/SecurityCodeInspectionUsingOutlook2007_878A/image0_thumb5.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;Look inside source code&lt;/STRONG&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;This techniques assumes you one knows what to look for - it can be&amp;nbsp;&lt;STRONG&gt;hints&lt;/STRONG&gt; gathered from previous step or just finding all instances of&amp;nbsp;&lt;B&gt;OdbcCommand, &lt;/B&gt;&lt;B&gt;OleDbCommand, &lt;/B&gt;&lt;B&gt;OracleCommand, &lt;/B&gt;&lt;B&gt;SqlCommand, &lt;/B&gt;&lt;B&gt;SqlCeCommand&lt;/B&gt; usage.&lt;/P&gt;
&lt;P&gt;FindStr is of great help here and the syntax would look like : FindStr /S /M /I /d:c:\projects\yourweb "SqlCommand" *.cs&lt;/P&gt;
&lt;P&gt;from &lt;A title=http://msdn2.microsoft.com/en-us/library/aa302437.aspx href="http://msdn2.microsoft.com/en-us/library/aa302437.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/aa302437.aspx"&gt;http://msdn2.microsoft.com/en-us/library/aa302437.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;FindStr&lt;/B&gt; uses the following command-line parameters: 
&lt;UL&gt;
&lt;LI&gt;&lt;B&gt;/S&lt;/B&gt; — include subdirectories. 
&lt;LI&gt;&lt;B&gt;/M&lt;/B&gt; — list only the file names. No actual matches displayed. 
&lt;LI&gt;&lt;B&gt;/I&lt;/B&gt; — use a case insensitive search. 
&lt;LI&gt;/&lt;B&gt;D:&lt;/B&gt;&lt;I&gt;dir&lt;/I&gt; — search a semicolon-delimited list of directories. If the file path you want to search includes spaces, surround the path in double quotes. &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Incase where Visual Studio is at hand same result (I presume FindStr is used under the cover) can be achieved by pressing ctrl+shift+f. This command brings up "Find In Files" dialog box:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/SecurityCodeReviewEternalSearchForSQLinj_C715/image%7B0%7D%5B5%5D.png" atomicselection="true" mce_href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/SecurityCodeReviewEternalSearchForSQLinj_C715/image%7B0%7D%5B5%5D.png"&gt;&lt;IMG height=304 src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/SecurityCodeReviewEternalSearchForSQLinj_C715/image%7B0%7D_thumb%5B1%5D.png" width=354 mce_src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/SecurityCodeReviewEternalSearchForSQLinj_C715/image%7B0%7D_thumb%5B1%5D.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;and the result is:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/SecurityCodeReviewEternalSearchForSQLinj_C715/image%7B0%7D%5B9%5D.png" atomicselection="true" mce_href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/SecurityCodeReviewEternalSearchForSQLinj_C715/image%7B0%7D%5B9%5D.png"&gt;&lt;IMG height=155 src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/SecurityCodeReviewEternalSearchForSQLinj_C715/image%7B0%7D_thumb%5B3%5D.png" width=737 mce_src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/SecurityCodeReviewEternalSearchForSQLinj_C715/image%7B0%7D_thumb%5B3%5D.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;(file and the string match == FindStr /S /I /d:c:\projects\yourweb "SqlCommand" *.*)&lt;/P&gt;
&lt;P&gt;Looking at the match one can decide to look further into it or not.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://msdn2.microsoft.com/en-us/library/ms182310(VS.80).aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms182310(VS.80).aspx"&gt;&lt;STRONG&gt;Use FxCop's ReviewSqlQueriesForSecurityVulnerabilities&lt;/STRONG&gt;&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Run FxCop with ReviewSqlQueriesForSecurityVulnerabilities rule checked:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/SecurityCodeReviewEternalSearchForSQLinj_C715/image%7B0%7D%5B13%5D.png" atomicselection="true" mce_href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/SecurityCodeReviewEternalSearchForSQLinj_C715/image%7B0%7D%5B13%5D.png"&gt;&lt;IMG height=209 src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/SecurityCodeReviewEternalSearchForSQLinj_C715/image%7B0%7D_thumb%5B5%5D.png" width=678 mce_src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/SecurityCodeReviewEternalSearchForSQLinj_C715/image%7B0%7D_thumb%5B5%5D.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;Do not include any other checks - FxCop consumes tones of memory, and it may be a problem with large projects that include many DLL's.&lt;/P&gt;
&lt;P&gt;Seems like FxCop approach is most efficient since it knows how&amp;nbsp;to get hold on those hints where XXXComand object is used and CommandText property includes string that was built dynamically.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do not fall in trap of false&amp;nbsp;positives and false negatives - tools are great but &lt;A href="http://blogs.microsoft.co.il/blogs/alikl/archive/2007/02/14/Most-Powerful-Security-Tool.aspx" mce_href="http://blogs.microsoft.co.il/blogs/alikl/archive/2007/02/14/Most-Powerful-Security-Tool.aspx"&gt;the best tool is between your ears&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;False positives&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp; - it is situation&amp;nbsp;when the tool finds the issue but from detailed inspection it is not. For example, FxCop spots the code like this:&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;SPAN style="FONT-WEIGHT: normal; FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;SPAN style="FONT-WEIGHT: normal; FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/SPAN&gt; sql &lt;SPAN style="FONT-WEIGHT: normal; FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/SPAN&gt; &lt;SPAN style="FONT-WEIGHT: normal; FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"SELECT NAME, DESCN FROM PRODUCT WHERE NAME ='"&lt;/SPAN&gt; &lt;SPAN style="FONT-WEIGHT: normal; FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;+&lt;/SPAN&gt; searchCriteria &lt;SPAN style="FONT-WEIGHT: normal; FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;+&lt;/SPAN&gt; &lt;SPAN style="FONT-WEIGHT: normal; FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"'"&lt;/SPAN&gt; &lt;BR&gt;&lt;BR&gt;SqlCommand cmd &lt;SPAN style="FONT-WEIGHT: normal; FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/SPAN&gt; &lt;SPAN style="FONT-WEIGHT: normal; FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/SPAN&gt; SqlCommand(sql, con); &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Is it a problem? Depends where &lt;EM&gt;searchCriteria &lt;/EM&gt;value&amp;nbsp;comes from - if it is &lt;FONT color=#ff0000&gt;user controlled&lt;/FONT&gt; then &lt;FONT color=#ff0000&gt;YES&lt;/FONT&gt;, otherwise not [sure]. 
&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;False negatives&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp; - it is situation where the tool does not find anything but the problem actually exists and only manual detailed scan can reveal it. 
&lt;P&gt;While false positives just consume more energy while manually inspecting&amp;nbsp;the findings, false negatives leave bad stuff undiscovered, which is I think worse. 
&lt;P&gt;&lt;STRONG&gt;Conclusion&lt;/STRONG&gt; 
&lt;P&gt;While tools are vital and usually boost the productivity when inspecting the code for security vulnerabilities, it is important to have right set of expectations from those tools - what it can and what it cannot do. Remember the best tool is between your ears (&lt;A href="http://blogs.msdn.com/jmeier/archive/2007/02/07/it-s-between-your-ears.aspx" mce_href="http://blogs.msdn.com/jmeier/archive/2007/02/07/it-s-between-your-ears.aspx"&gt;original version by JD&lt;/A&gt;)&amp;nbsp; 
&lt;P&gt;:) 
&lt;P&gt;Enjoy&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2001473" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alikl/archive/tags/Input+Validation/default.aspx">Input Validation</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Test+Phase/default.aspx">Test Phase</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Security/default.aspx">Security</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Code+Inspection/default.aspx">Code Inspection</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Development+Phase/default.aspx">Development Phase</category></item><item><title>XSS? - Do not Make Me Laugh, We Use WinForms</title><link>http://blogs.msdn.com/alikl/archive/2007/03/25/xss-do-not-make-me-laugh-we-use-winforms.aspx</link><pubDate>Mon, 26 Mar 2007 00:16:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1948441</guid><dc:creator>alikl</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/alikl/comments/1948441.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alikl/commentrss.aspx?PostID=1948441</wfw:commentRss><wfw:comment>http://blogs.msdn.com/alikl/rsscomments.aspx?PostID=1948441</wfw:comment><description>&lt;p&gt;Reposted from &lt;a href="http://blogs.microsoft.co.il/blogs/alikl/archive/2007/01/04/XSS_3F00_-_2D00_-Do-not-Make-Me-Laugh_2C00_-We-Use-WinForms.aspx"&gt;XSS? - Do not Make Me Laugh, We Use WinForms&lt;/a&gt;&lt;/p&gt; &lt;p&gt;I find myself sometimes (actually too many times...) in situation explaining people of impact of &lt;a href="http://en.wikipedia.org/wiki/Cross_site_scripting" target="_blank"&gt;Cross Site Scripting (attack)&lt;/a&gt; attacks as a result of &lt;a href="http://www.guidanceshare.com/wiki/How_To_Identify_Cross_Site_Scripting_Vulnerabilities" target="_blank"&gt;importer encoding of user input (vulnerability)&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag2/html/PAGHT000004.asp" target="_blank"&gt;how to counter this attack&lt;/a&gt; properly. Once all parties understand this everybody feels great relief since "our app is not web app - we use WinForms". Great!! The threat is mitigated by removing the feature of rendering HTML output...&lt;/p&gt; &lt;p&gt;"Hold it, you told me that your system presents to end user different types of documents, right?"&lt;/p&gt; &lt;p&gt;"Right, so?"&lt;/p&gt; &lt;p&gt;"Do you show HTML docs too?"&lt;/p&gt; &lt;p&gt;"Sure!"&lt;/p&gt; &lt;p&gt;"Great, and what do you use for it?"&lt;/p&gt; &lt;p&gt;"WebBrowser control, of course"&lt;/p&gt; &lt;p&gt;"I get it... So if you get HTML doc, it might include some script&amp;nbsp;like this one:&lt;/p&gt; &lt;p&gt;&amp;lt;script&amp;gt;alert("HACKED!!")&amp;lt;/script&amp;gt;&lt;/p&gt; &lt;p&gt;&amp;nbsp;that can render as follows, right?"&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/XSSDonotMakeMelaughWeUseWinForms_D3B8/image014.png" atomicselection="true"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="320" src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/XSSDonotMakeMelaughWeUseWinForms_D3B8/image0_thumb10.png" width="485" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;"... right..."&lt;/p&gt; &lt;p&gt;How one prevents scripts running inside the WebBrowser control?&lt;/p&gt; &lt;p&gt;I did not find an easy way to control it other than using PINVOKE described here -&amp;nbsp; &lt;a title="http://msdn.microsoft.com/workshop/browser/hosting/wbcustomization.asp?frame=true" href="http://msdn.microsoft.com/workshop/browser/hosting/wbcustomization.asp?frame=true"&gt;http://msdn.microsoft.com/workshop/browser/hosting/wbcustomization.asp?frame=true&lt;/a&gt;&amp;nbsp;Here is another post on that one - &lt;a title="http://slingkid.blogsome.com/2006/05/26/" href="http://slingkid.blogsome.com/2006/05/26/"&gt;http://slingkid.blogsome.com/2006/05/26/&lt;/a&gt;&amp;nbsp;(that actually points back to the above link but has good interop example) and another discussion here - &amp;nbsp;&lt;a title="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=66493&amp;amp;SiteID=1" href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=66493&amp;amp;SiteID=1"&gt;http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=66493&amp;amp;SiteID=1&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Cheers&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1948441" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alikl/archive/tags/Input+Validation/default.aspx">Input Validation</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Test+Phase/default.aspx">Test Phase</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Security/default.aspx">Security</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Development+Phase/default.aspx">Development Phase</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Implementation/default.aspx">Implementation</category></item><item><title>Good Chance For Canonicalization Attack When Using Path.Combine()</title><link>http://blogs.msdn.com/alikl/archive/2007/03/15/beware-of-path-combine-s1-s2-good-chance-for-canonicalization-attack.aspx</link><pubDate>Fri, 16 Mar 2007 01:31:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1890210</guid><dc:creator>alikl</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/alikl/comments/1890210.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alikl/commentrss.aspx?PostID=1890210</wfw:commentRss><wfw:comment>http://blogs.msdn.com/alikl/rsscomments.aspx?PostID=1890210</wfw:comment><description>&lt;P&gt;In my previous post, &lt;A href="http://blogs.msdn.com/alikl/archive/2007/03/12/net-assembly-spoof-attack.aspx" mce_href="http://blogs.msdn.com/alikl/archive/2007/03/12/net-assembly-spoof-attack.aspx"&gt;.Net Assembly Spoof Attack&lt;/A&gt;, I've described potential DLL hijacking/spoof attack when using reflection for dynamically loaded assemblies. &lt;/P&gt;
&lt;P&gt;Today I was reviewing some project where I stumbled on exactly such case. One thing that caught my eyes was that path to reflected DLL, the one to be loaded dynamically was built like this:&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;SPAN style="FONT-WEIGHT: normal; FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;SPAN style="FONT-WEIGHT: normal; FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;static&lt;/SPAN&gt; &lt;SPAN style="FONT-WEIGHT: normal; FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/SPAN&gt; Main(&lt;SPAN style="FONT-WEIGHT: normal; FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/SPAN&gt;[] args)&lt;BR&gt;{ &lt;BR&gt;&lt;BR&gt;&lt;SPAN style="FONT-WEIGHT: normal; FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/SPAN&gt; dllName &lt;SPAN style="FONT-WEIGHT: normal; FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/SPAN&gt; Console.ReadLine();&amp;nbsp;&lt;BR&gt;&lt;BR&gt;&lt;SPAN style="FONT-WEIGHT: normal; FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;while&lt;/SPAN&gt; (!dllName.Equals(&lt;SPAN style="FONT-WEIGHT: normal; FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"exit"&lt;/SPAN&gt;))&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&lt;SPAN style="FONT-WEIGHT: normal; FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;string&lt;/SPAN&gt; path &lt;SPAN style="FONT-WEIGHT: normal; FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/SPAN&gt; &lt;SPAN style="FONT-WEIGHT: normal; FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;@"C:\DLLS\"&lt;/SPAN&gt;&amp;nbsp;&lt;BR&gt;&lt;BR&gt;&lt;SPAN style="FONT-WEIGHT: normal; FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//BUILD FULL PATH TO ASSEMBLY TO LOAD DYNAMICALLY USING Assembly.LoadFrom&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="FONT-WEIGHT: normal; FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;string&lt;/SPAN&gt; fullDllPath &lt;SPAN style="FONT-WEIGHT: normal; FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/SPAN&gt; Path.Combine(path, dllName);&amp;nbsp;&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Console.WriteLine(&lt;SPAN style="FONT-WEIGHT: normal; FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"FULL PATH IS: "&lt;/SPAN&gt; &lt;SPAN style="FONT-WEIGHT: normal; FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;+&lt;/SPAN&gt; fullDllPath);&amp;nbsp;&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dllName &lt;SPAN style="FONT-WEIGHT: normal; FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/SPAN&gt; Console.ReadLine();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;}&lt;/SPAN&gt; &lt;/P&gt;
&lt;P&gt;Let me run it and see what happens if I provide expected DLL name say, alikl.dll: 
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/Bew.Combines1s2GoodChanceForCanonicaliza_3B3/image%7B0%7D%5B2%5D.png" mce_href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/Bew.Combines1s2GoodChanceForCanonicaliza_3B3/image%7B0%7D%5B2%5D.png" atomicselection="true"&gt;&lt;IMG style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px" height=117 src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/Bew.Combines1s2GoodChanceForCanonicaliza_3B3/image%7B0%7D_thumb.png" width=437 border=0 mce_src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/Bew.Combines1s2GoodChanceForCanonicaliza_3B3/image%7B0%7D_thumb.png"&gt;&lt;/A&gt; 
&lt;P&gt;And now let's provide something less expected like Z:\XACKER\ATTACK.DLL: 
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/Bew.Combines1s2GoodChanceForCanonicaliza_3B3/image%7B0%7D%5B5%5D.png" mce_href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/Bew.Combines1s2GoodChanceForCanonicaliza_3B3/image%7B0%7D%5B5%5D.png" atomicselection="true"&gt;&lt;IMG style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px" height=117 src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/Bew.Combines1s2GoodChanceForCanonicaliza_3B3/image%7B0%7D_thumb%5B1%5D.png" width=437 border=0 mce_src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/Bew.Combines1s2GoodChanceForCanonicaliza_3B3/image%7B0%7D_thumb%5B1%5D.png"&gt;&lt;/A&gt; 
&lt;P&gt;It&amp;nbsp;means that if we supply full path as second parameter to Combine method it will ignore the first parameter. 
&lt;P&gt;How to validate? 
&lt;P&gt;1. Check the path for goodness using Path.GetFullPath() comparing result to "C:\DLLS" in our case 
&lt;P&gt;2. Sign your assembly and explicitly check it's evidence&amp;nbsp; - example is here &lt;A href="http://blogs.msdn.com/alikl/archive/2007/03/12/net-assembly-spoof-attack.aspx" mce_href="http://blogs.msdn.com/alikl/archive/2007/03/12/net-assembly-spoof-attack.aspx"&gt;.Net Assembly Spoof Attack&lt;/A&gt; 
&lt;P&gt;More resources: 
&lt;P&gt;&lt;A onmouseover='TopicTipOn(this, "id1167");' onmouseout=TopicTipOff(); href="http://channel9.msdn.com/wiki/default.aspx/SecurityWiki.CanonicalizationLab"&gt;Canonicalization Lab&lt;/A&gt; (includes code and video by &lt;A class="" href="http://pluralsight.com/blogs/keith/" mce_href="http://pluralsight.com/blogs/keith/"&gt;Keith Brown&lt;/A&gt;) 
&lt;P&gt;&lt;A class="" href="http://msdn2.microsoft.com/en-us/library/bb355989.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/bb355989.aspx"&gt;How To: Protect From Injection Attacks in ASP.NET&lt;/A&gt; 
&lt;P&gt;Enjoy &lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1890210" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alikl/archive/tags/Input+Validation/default.aspx">Input Validation</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Test+Phase/default.aspx">Test Phase</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Security/default.aspx">Security</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Code+Inspection/default.aspx">Code Inspection</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Development+Phase/default.aspx">Development Phase</category></item><item><title>How To Hack WCF - New Technology, Old Hacking Tricks</title><link>http://blogs.msdn.com/alikl/archive/2007/03/04/how-to-hack-wcf-new-technology-old-hacking-tricks.aspx</link><pubDate>Sun, 04 Mar 2007 23:11:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1805472</guid><dc:creator>alikl</dc:creator><slash:comments>12</slash:comments><comments>http://blogs.msdn.com/alikl/comments/1805472.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alikl/commentrss.aspx?PostID=1805472</wfw:commentRss><wfw:comment>http://blogs.msdn.com/alikl/rsscomments.aspx?PostID=1805472</wfw:comment><description>&lt;P&gt;First of I'd like to thank &lt;A href="http://blogs.microsoft.co.il/blogs/bursteg/" mce_href="http://blogs.microsoft.co.il/blogs/bursteg/"&gt;Guy&lt;/A&gt; for his excellent screencast - very convenient, so thanks.&lt;/P&gt;
&lt;P&gt;Specifically I liked introductory screencast for WCF which can be found here: &lt;A title=http://blogs.microsoft.co.il/blogs/bursteg/pages/WCF-Introduction-Demo-_2800_ScreenCast_2900_.aspx href="http://blogs.microsoft.co.il/blogs/bursteg/pages/WCF-Introduction-Demo-_2800_ScreenCast_2900_.aspx" mce_href="http://blogs.microsoft.co.il/blogs/bursteg/pages/WCF-Introduction-Demo-_2800_ScreenCast_2900_.aspx"&gt;http://blogs.microsoft.co.il/blogs/bursteg/pages/WCF-Introduction-Demo-_2800_ScreenCast_2900_.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;It is dubbed in Hebrew, but the screens are flipping in so logical way so that one who does not understand Hebrew will be fine - go for it - recommended a lot for WCF newbies like me.&lt;/P&gt;
&lt;P&gt;My interest was to understand the &lt;A class="" href="http://blogs.msdn.com/drnick/archive/2007/03/07/message-flow-interception-points.aspx" mce_href="http://blogs.msdn.com/drnick/archive/2007/03/07/message-flow-interception-points.aspx"&gt;pipeline&lt;/A&gt; that the &lt;A href="http://msdn2.microsoft.com/en-us/library/ms734675.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms734675.aspx"&gt;WCF Message&lt;/A&gt; goes through before it is put on the transport. The idea was to inject some custom modules (Inspectors)&amp;nbsp;in the pipeline. Why? Is not it clear? To mess around with the message - tamper it in it raw format before it goes down to the transport signed and protected. Why? To show that it DOES NOT matter what communication technology you use - HTTP, Remoting, MSMQ, WCF, RMI, CORBA, DCOM, MQ, &amp;lt;&amp;lt;fill in your own here&amp;gt;&amp;gt; - the basic principle of VALIDATING INPUT ON THE SERVER SIDE is immutable.&lt;/P&gt;
&lt;P&gt;Here I showed it for Web Services &lt;A href="http://blogs.microsoft.co.il/blogs/alikl/archive/2006/11/24/App-Architecture-with-Security-in-mind-_2D00_-Video_2C00_-Part-I.aspx" mce_href="http://blogs.microsoft.co.il/blogs/alikl/archive/2006/11/24/App-Architecture-with-Security-in-mind-_2D00_-Video_2C00_-Part-I.aspx"&gt;App Architecture with Security in mind - Video, Part I&lt;/A&gt;&amp;nbsp;(that was easy - &lt;A href="http://www.fiddlertool.com/" mce_href="http://www.fiddlertool.com/"&gt;Fiddler&lt;/A&gt; is of much help here)&lt;/P&gt;
&lt;P&gt;Then remoting came along - same result, here &lt;A href="http://blogs.microsoft.co.il/blogs/alikl/archive/2006/11/25/App-Architecture-with-Security-in-mind-_2D00_-Video_2C00_-Part-II.aspx" mce_href="http://blogs.microsoft.co.il/blogs/alikl/archive/2006/11/25/App-Architecture-with-Security-in-mind-_2D00_-Video_2C00_-Part-II.aspx"&gt;App Architecture with Security in mind - Video, Part II&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Now it is mighty WCF.&lt;/P&gt;
&lt;P&gt;I used excellent demo from &lt;A href="http://blogs.msdn.com/madhuponduru/default.aspx" mce_href="http://blogs.msdn.com/madhuponduru/default.aspx"&gt;Madhu&lt;/A&gt; here &lt;A title=http://blogs.msdn.com/madhuponduru/archive/2006/07/19/671922.aspx href="http://blogs.msdn.com/madhuponduru/archive/2006/07/19/671922.aspx" mce_href="http://blogs.msdn.com/madhuponduru/archive/2006/07/19/671922.aspx"&gt;http://blogs.msdn.com/madhuponduru/archive/2006/07/19/671922.aspx&lt;/A&gt;&amp;nbsp;that explained how to build &lt;A href="http://msdn2.microsoft.com/en-us/library/system.servicemodel.dispatcher.iclientmessageinspector.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/system.servicemodel.dispatcher.iclientmessageinspector.aspx"&gt;IClientMessageInspector&lt;/A&gt; (NOTE - demo that works!)&lt;/P&gt;
&lt;P&gt;So here is the service contract:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/WCFInterceptors_8951/image02.png" mce_href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/WCFInterceptors_8951/image02.png" atomicselection="true"&gt;&lt;IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=176 src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/WCFInterceptors_8951/image0_thumb.png" width=359 border=0 mce_src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/WCFInterceptors_8951/image0_thumb.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;and the implementation:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/WCFInterceptors_8951/image05.png" mce_href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/WCFInterceptors_8951/image05.png" atomicselection="true"&gt;&lt;IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=180 src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/WCFInterceptors_8951/image0_thumb1.png" width=416 border=0 mce_src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/WCFInterceptors_8951/image0_thumb1.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;and the client side validation:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/WCFInterceptors_8951/image08.png" mce_href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/WCFInterceptors_8951/image08.png" atomicselection="true"&gt;&lt;IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=403 src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/WCFInterceptors_8951/image0_thumb2.png" width=692 border=0 mce_src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/WCFInterceptors_8951/image0_thumb2.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;here is the client rejects the input:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/WCFInterceptors_8951/image011.png" mce_href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/WCFInterceptors_8951/image011.png" atomicselection="true"&gt;&lt;IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=89 src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/WCFInterceptors_8951/image0_thumb3.png" width=389 border=0 mce_src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/WCFInterceptors_8951/image0_thumb3.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;and here is the result of server processing for good input:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/WCFInterceptors_8951/image014.png" mce_href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/WCFInterceptors_8951/image014.png" atomicselection="true"&gt;&lt;IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=76 src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/WCFInterceptors_8951/image0_thumb4.png" width=315 border=0 mce_src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/WCFInterceptors_8951/image0_thumb4.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;after adding the custom message inspector, I am offered to tamper the massage before it is sent to the service and the resulting reply from the service is in red at the bottom:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/WCFInterceptors_8951/image017.png" mce_href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/WCFInterceptors_8951/image017.png" atomicselection="true"&gt;&lt;IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=210 src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/WCFInterceptors_8951/image0_thumb5.png" width=623 border=0 mce_src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/WCFInterceptors_8951/image0_thumb5.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;&lt;FONT color=#ff0000&gt;Conclusion&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Does that mean that the communication technologies are bad? -&amp;nbsp;NO, it is the way &lt;FONT color=#ff0000&gt;&lt;STRONG&gt;WE&lt;/STRONG&gt;&lt;/FONT&gt; use it.&lt;/P&gt;
&lt;P&gt;Here is an basic example&amp;nbsp;for input validation in Web Services &lt;A href="http://blogs.microsoft.co.il/blogs/alikl/archive/2007/02/22/Web-Service-Input-Validation.aspx" mce_href="http://blogs.microsoft.co.il/blogs/alikl/archive/2007/02/22/Web-Service-Input-Validation.aspx"&gt;Web Service Input Validation&lt;/A&gt;&amp;nbsp;- it has link to regex usage that you can use on the server side for input validation.&lt;/P&gt;
&lt;P&gt;Enjoy&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1805472" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alikl/archive/tags/WCF/default.aspx">WCF</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Input+Validation/default.aspx">Input Validation</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Test+Phase/default.aspx">Test Phase</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Fuzzing/default.aspx">Fuzzing</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Security/default.aspx">Security</category></item></channel></rss>