<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US"><title type="html">Sacha Faust Web Security Blog</title><subtitle type="html" /><id>http://blogs.msdn.com/sfaust/atom.xml</id><link rel="alternate" type="text/html" href="http://blogs.msdn.com/sfaust/default.aspx" /><link rel="self" type="application/atom+xml" href="http://blogs.msdn.com/sfaust/atom.xml" /><generator uri="http://communityserver.org" version="2.1.61025.2">Community Server</generator><updated>2008-09-02T06:20:00Z</updated><entry><title>Fxcop rule to verify the use of ASP.NET MVC AntiforgeryTokenAttribute</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/sfaust/archive/2009/01/07/fxcop-rule-to-verify-the-use-of-asp-net-mvc-antiforgerytokenattribute.aspx" /><link rel="enclosure" type="application/x-zip-compressed" length="4250" href="http://blogs.msdn.com/sfaust/attachment/9290714.ashx" /><id>http://blogs.msdn.com/sfaust/archive/2009/01/07/fxcop-rule-to-verify-the-use-of-asp-net-mvc-antiforgerytokenattribute.aspx</id><published>2009-01-08T00:56:00Z</published><updated>2009-01-08T00:56:00Z</updated><content type="html">&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Arial','sans-serif'"&gt;I’ve been working on code auditing for a project that makes use of the latest &lt;A class="" title="ASP.NET MVC" href="http://www.asp.net/mvc/" target=_blank mce_href="http://www.asp.net/mvc/"&gt;ASP.NET MVC&lt;/A&gt; api. Turned out that it didn’t benefit from the built-in &lt;A class="" title=CSRF href="http://en.wikipedia.org/wiki/Cross-site_request_forgery" target=_blank mce_href="http://en.wikipedia.org/wiki/Cross-site_request_forgery"&gt;CSRF&lt;/A&gt; mitigation available since preview 5 version of the api. The mitigation is quite simple and generates tokens and validates them inside controller actions. As usual, I rather spend my time looking for more complex issues during code audit&amp;nbsp;and I prefer relying on the &lt;A class="" title=FxCop href="http://en.wikipedia.org/wiki/FxCop" target=_blank mce_href="http://en.wikipedia.org/wiki/FxCop"&gt;FxCop&lt;/A&gt; automation we have to spot this sort of problem earlier so I implemented a simple rule that will catch where the mitigation should be used. The rule will look for controller actions that are available via POST and look to see if the method declares the &lt;EM&gt;ValidateAntiForgeryTokenAttribute&lt;/EM&gt;. You can read more on how to implement the mitigation in your code by reading Steve Sanderson &lt;A class="" title="blog post" href="http://blog.codeville.net/2008/09/01/prevent-cross-site-request-forgery-csrf-using-aspnet-mvcs-antiforgerytoken-helper/" target=_blank mce_href="http://blog.codeville.net/2008/09/01/prevent-cross-site-request-forgery-csrf-using-aspnet-mvcs-antiforgerytoken-helper/"&gt;blog post&lt;/A&gt; on the subject.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Arial','sans-serif'"&gt;&lt;STRONG&gt;&lt;U&gt;Installation&lt;/U&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;
&lt;DIV class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Arial','sans-serif'"&gt;Copy MVCAntiforgeryTokenChecker.dll in your FxCop rule folder. By default it's under c:\Program Files\Microsoft FxCop 1.36\Rules&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Arial','sans-serif'"&gt;Launch FxCop and the rule is "AntiforgeryToken used" under "ASP.NET MVC Security" group.&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Arial','sans-serif'"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;FONT size=3&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9290714" width="1" height="1"&gt;</content><author><name>sfaust</name><uri>http://blogs.msdn.com/members/sfaust.aspx</uri></author><category term="ASP.NET" scheme="http://blogs.msdn.com/sfaust/archive/tags/ASP.NET/default.aspx" /><category term="FxCop" scheme="http://blogs.msdn.com/sfaust/archive/tags/FxCop/default.aspx" /><category term="CSRF" scheme="http://blogs.msdn.com/sfaust/archive/tags/CSRF/default.aspx" /><category term="MVC" scheme="http://blogs.msdn.com/sfaust/archive/tags/MVC/default.aspx" /></entry><entry><title>Checking for ViewStateUserKey using FxCop</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/sfaust/archive/2008/09/25/checking-for-viewstateuserkey-using-fxcop.aspx" /><link rel="enclosure" type="application/x-zip-compressed" length="3739" href="http://blogs.msdn.com/sfaust/attachment/8965585.ashx" /><id>http://blogs.msdn.com/sfaust/archive/2008/09/25/checking-for-viewstateuserkey-using-fxcop.aspx</id><published>2008-09-25T23:31:00Z</published><updated>2008-09-25T23:31:00Z</updated><content type="html">&lt;P&gt;ASP.NET has had a mitigation to prevent against&amp;nbsp;CSRF/One-Click attacks since 1.1 with the use of &lt;A class="" href="http://msdn.microsoft.com/en-us/library/system.web.ui.page.viewstateuserkey.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/system.web.ui.page.viewstateuserkey.aspx"&gt;Page.ViewStateUserKey&lt;/A&gt; property. I've implemented a basic FXCop rule to verify if this property is used on each page. The rule is basic so it doesn't look at what is assigned to the property and only looks if something is assigned to it. The ViewStateUserKey property is not full proof. If you are not using viewstate on the page it doesn't help much. You can also review this &lt;A class="" href="http://keepitlocked.net/archive/2008/05/29/viewstateuserkey-doesn-t-prevent-cross-site-request-forgery.aspx" target=_blank mce_href="http://keepitlocked.net/archive/2008/05/29/viewstateuserkey-doesn-t-prevent-cross-site-request-forgery.aspx"&gt;post&lt;/A&gt; regarding limitation of the ViewStateUserKey. I strongly recommend that you include this rule when running fxcop or code analysis in visual studio on web projects.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Installation&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&amp;nbsp;Unzip and select the appropriate rule for the fxcop release you are using&lt;/LI&gt;
&lt;UL&gt;
&lt;LI&gt;For Visual Studio Team System 2005 select the fxcop 1.35 version and place it in&amp;nbsp;&lt;EM&gt;C:\Program Files\Microsoft Visual Studio 8\Team Tools\Static Analysis Tools\FxCop\Rules&lt;/EM&gt;&lt;/LI&gt;
&lt;LI&gt;For Visual Studio Team System 2008 select the fxcop 1.36 version and place it in &lt;EM&gt;C:\Program Files\Microsoft Visual Studio 9.0\Team Tools\Static Analysis Tools\FxCop\Rules&lt;/EM&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;LI&gt;The rule can be enabled under the "ASP.NET Security" section and it's called "ViewStateUserKey used"&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Update&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;I've been working with projects using &lt;A class="" title="ASP.NET MVC" href="http://www.asp.net/mvc/" target=_blank mce_href="http://www.asp.net/mvc/"&gt;ASP.NET MVC&lt;/A&gt;&amp;nbsp;and made some update to the rule to ignore classes inheriting from ViewPage since MVC doesn't use ViewState.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8965585" width="1" height="1"&gt;</content><author><name>sfaust</name><uri>http://blogs.msdn.com/members/sfaust.aspx</uri></author><category term="ASP.NET" scheme="http://blogs.msdn.com/sfaust/archive/tags/ASP.NET/default.aspx" /><category term="FxCop" scheme="http://blogs.msdn.com/sfaust/archive/tags/FxCop/default.aspx" /><category term="CSRF" scheme="http://blogs.msdn.com/sfaust/archive/tags/CSRF/default.aspx" /><category term="One-Click" scheme="http://blogs.msdn.com/sfaust/archive/tags/One-Click/default.aspx" /></entry><entry><title>Fxcop HtmlSpotter - Spotting ASP.NET XSS using Fxcop and Html encoding document</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/sfaust/archive/2008/09/18/fxcop-htmlspotter-spotting-asp-net-xss-using-fxcop-and-html-encoding-document.aspx" /><link rel="enclosure" type="application/x-zip-compressed" length="17300" href="http://blogs.msdn.com/sfaust/attachment/8957838.ashx" /><id>http://blogs.msdn.com/sfaust/archive/2008/09/18/fxcop-htmlspotter-spotting-asp-net-xss-using-fxcop-and-html-encoding-document.aspx</id><published>2008-09-18T23:30:00Z</published><updated>2008-09-18T23:30:00Z</updated><content type="html">&lt;P&gt;In my previous &lt;A class="" href="http://blogs.msdn.com/sfaust/archive/2008/09/02/which-asp-net-controls-automatically-encodes.aspx" target=_blank mce_href="https://blogs.msdn.com:443/sfaust/archive/2008/09/02/which-asp-net-controls-automatically-encodes.aspx"&gt;post&lt;/A&gt;, I provided a list of which ASP.NET HTML control property that offers automatic HTML encoding. As a side note, I was&amp;nbsp;made aware that an older version of that file is available from&amp;nbsp;the support files of the &lt;A class="" href="http://www.microsoft.com/mspress/companion/0-7356-2187-X/" mce_href="http://www.microsoft.com/mspress/companion/0-7356-2187-X/"&gt;Hunting Security Bugs&lt;/A&gt; book. I initially received this document from Tom Gallagher team and made some updates regarding BaseValidator and child classes ErrorMessage property so the version I posted is more up to date. I'll remind the book authors to update the file on their side.&lt;/P&gt;
&lt;P&gt;The document was targeted to ASP.NET 2.0 developers who were interested to know which control doesn't offer encoding to mitigate against &lt;A class="" href="http://en.wikipedia.org/wiki/Cross-site_scripting" mce_href="http://en.wikipedia.org/wiki/Cross-site_scripting"&gt;XSS&lt;/A&gt; problems. The document is also very useful during code review and I've decided to quickly plug it into &lt;A class="" href="http://msdn.microsoft.com/en-us/library/bb429476(VS.80).aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb429476(VS.80).aspx"&gt;FxCop&lt;/A&gt; so it can quickly spot areas that should be reviewed.&lt;/P&gt;
&lt;P&gt;The rule will load the control encoding information stored in asp_controls.xml and will apply the following logic:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;If properties that don't offer encoding are used, it will be listed in the FxCop result&lt;/LI&gt;
&lt;LI&gt;If it finds a property that offers encoding but that property is bound to html attribute, it will spot it to make sure that users cannot inject things like javascript: or other handlers&lt;/LI&gt;
&lt;UL&gt;
&lt;LI&gt;In the future, it will only show cases where the attribute can be executed. I'm currently looking to potentially integrate the rule with the &lt;A class="" href="http://www.webappsec.org/projects/scriptmapping/" target=_blank mce_href="http://www.webappsec.org/projects/scriptmapping/"&gt;script mapping project&lt;/A&gt; from &lt;A class="" href="http://www.webappsec.org/" target=_blank mce_href="http://www.webappsec.org/"&gt;WASC&lt;/A&gt;.&lt;/LI&gt;&lt;/UL&gt;&lt;/UL&gt;
&lt;P&gt;This will give a detailed list of items to review. The aim is not to automatically detect XSS but to identify spots in the code that should be reviewed.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Installation&lt;/U&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Simply unzip the files and put them in the FxCop Rules folder (C:\Program Files\Microsoft FxCop 1.36\Rules)&lt;/LI&gt;
&lt;LI&gt;Launch FxCop&lt;/LI&gt;
&lt;LI&gt;The rule can be selected from the Rules tab under the&amp;nbsp;&lt;STRONG&gt;Html Review&lt;/STRONG&gt; section&lt;/LI&gt;&lt;/OL&gt;
&lt;BLOCKQUOTE&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8957838" width="1" height="1"&gt;</content><author><name>sfaust</name><uri>http://blogs.msdn.com/members/sfaust.aspx</uri></author><category term="Code Review" scheme="http://blogs.msdn.com/sfaust/archive/tags/Code+Review/default.aspx" /><category term="XSS" scheme="http://blogs.msdn.com/sfaust/archive/tags/XSS/default.aspx" /><category term="ASP.NET" scheme="http://blogs.msdn.com/sfaust/archive/tags/ASP.NET/default.aspx" /><category term="FxCop" scheme="http://blogs.msdn.com/sfaust/archive/tags/FxCop/default.aspx" /></entry><entry><title>Which ASP.NET Controls Automatically Encodes?</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/sfaust/archive/2008/09/02/which-asp-net-controls-automatically-encodes.aspx" /><link rel="enclosure" type="text/html" length="1641277" href="http://blogs.msdn.com/sfaust/attachment/8918996.ashx" /><id>http://blogs.msdn.com/sfaust/archive/2008/09/02/which-asp-net-controls-automatically-encodes.aspx</id><published>2008-09-02T08:20:00Z</published><updated>2008-09-02T08:20:00Z</updated><content type="html">&lt;P&gt;I've had a lot of people ask me which ASP.NET control offers automatic html encoding and the answer I had for a long time was to look at MSDN or even write a quick sample and test the behavior. If you are asking yourself the same question, you can now use the attached document to see if the control if offering the appropriate encoding. The document list all asp.net control and which property offers html, script or url encoding. You can also see which html attribute the property is bound to. This document is quite useful when you are reviewing your code for possible Cross-Site Scripting (XSS) or double encoding problems.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Side note&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;I was made aware that the initial content was provided as part of the companion content for the excellent book Hunting for Security bugs available at &lt;A href="http://www.microsoft.com/mspress/companion/0-7356-2187-X/" rel=nofollow target=_new&gt;&lt;FONT color=#0065e2&gt;http://www.microsoft.com/mspress/companion/0-7356-2187-X/&lt;/FONT&gt;&lt;/A&gt;. The file attached to this is indeed base on the same content since I received it internally by the author's team. I found some slight issues and made some changes. I recommend the file I provide until the book companio content gets updated.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8918996" width="1" height="1"&gt;</content><author><name>sfaust</name><uri>http://blogs.msdn.com/members/sfaust.aspx</uri></author><category term="Code Review" scheme="http://blogs.msdn.com/sfaust/archive/tags/Code+Review/default.aspx" /><category term="XSS" scheme="http://blogs.msdn.com/sfaust/archive/tags/XSS/default.aspx" /><category term="ASP.NET" scheme="http://blogs.msdn.com/sfaust/archive/tags/ASP.NET/default.aspx" /></entry></feed>