<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	>

<channel>
	<title>Adam.Kahtava.com / AdamDotCom &#187; ASP.NET MVC</title>
	<atom:link href="http://adam.kahtava.com/journal/category/aspnet-mvc/feed/" rel="self" type="application/rss+xml" />
	<link>http://adam.kahtava.com/journal</link>
	<description>A software development blog</description>
	<pubDate>Fri, 12 Mar 2010 03:41:25 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Hacking Anti Cross-site Request Forgery Tokens (CSRF) With Powershell</title>
		<link>http://adam.kahtava.com/journal/2009/12/16/hacking-an-anti-cross-site-request-forgery-tokens-csrf-with-powershell/</link>
		<comments>http://adam.kahtava.com/journal/2009/12/16/hacking-an-anti-cross-site-request-forgery-tokens-csrf-with-powershell/#comments</comments>
		<pubDate>Wed, 16 Dec 2009 16:00:25 +0000</pubDate>
		<dc:creator>Adam Kahtava</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[ASP.NET MVC]]></category>

		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://adam.kahtava.com/journal/?p=2149</guid>
		<description><![CDATA[I ported the example of how to hack an Anti CRSF Token protected form - previously shown in my post What Are Anti Cross-site Request Forgery Tokens And What Are They Good For? - to PowerShell.
How to hack an Anti CRSF Token from PowerShell


function global:spam-adamdotcom&#40;&#41;&#123;
&#160; # Load the assembly containing WebClientWithCookies and RegexUtilities
&#160; &#91;Reflection.Assembly&#93;::LoadFile&#40;&#40;Resolve-Path "AdamDotCom.WebClientWithCookies.dll"&#41;&#41; &#124; [...]]]></description>
			<content:encoded><![CDATA[<p>I ported the example of how to hack an Anti CRSF Token protected form - previously shown in my post <a href="http://adam.kahtava.com/journal/2009/11/25/what-are-anti-cross-site-request-forgery-tokens-and-what-are-they-good-for/">What Are Anti Cross-site Request Forgery Tokens And What Are They Good For?</a> - to PowerShell.</p>
<p><strong>How to hack an Anti CRSF Token from PowerShell</strong></p>
<div class="syntax_hilite">
<div id="csharp-3">
<div class="csharp">function global:spam-adamdotcom<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span></p>
<p>&nbsp; <span style="color: #008080;"># Load the assembly containing WebClientWithCookies and RegexUtilities</span><br />
&nbsp; <span style="color: #000000;">&#91;</span>Reflection.<span style="color: #0000FF;">Assembly</span><span style="color: #000000;">&#93;</span>::<span style="color: #0000FF;">LoadFile</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>Resolve-Path <span style="color: #808080;">"AdamDotCom.WebClientWithCookies.dll"</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> | out-<span style="color: #0600FF;">null</span><br />
&nbsp; <br />
&nbsp; <span style="color: #008080;"># Load the assembly containing System.Web.HttpUtilitiy</span><br />
&nbsp; <span style="color: #000000;">&#91;</span><span style="color: #0600FF;">void</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>Reflection.<span style="color: #0000FF;">Assembly</span><span style="color: #000000;">&#93;</span>::<span style="color: #0000FF;">LoadWithPartialName</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">"System.Web"</span><span style="color: #000000;">&#41;</span> | out-<span style="color: #0600FF;">null</span>&nbsp; </p>
<p>&nbsp; <span style="color: #008080;"># create a new instance of the HTTP Web Client that supports cookies</span><br />
&nbsp; $webClient = New-<span style="color: #FF0000;">Object</span> AdamDotCom.<span style="color: #0000FF;">Common</span>.<span style="color: #0000FF;">Service</span>.<span style="color: #0000FF;">Utilities</span>.<span style="color: #0000FF;">WebClientWithCookies</span></p>
<p>&nbsp; <span style="color: #008080;"># download the page that contains the Anti CRSF Token</span><br />
&nbsp; <span style="color: #000000;">&#91;</span><span style="color: #0600FF;">void</span><span style="color: #000000;">&#93;</span> $webClient.<span style="color: #0000FF;">DownloadData</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">"http://adam.kahtava.com/contact"</span><span style="color: #000000;">&#41;</span>;</p>
<p>&nbsp; <span style="color: #008080;"># use a regular expression to grab the Anti CRSF Token</span><br />
&nbsp; <span style="color: #008080;">#&nbsp; - this is an MVC site so we're looking for a token named &quot;__RequestVerificationToken_Lw__&quot;</span><br />
&nbsp; $regex = <span style="color: #808080;">"__RequestVerificationToken_Lw__=(?&lt;CRSF_Token&gt;[^;]+)"</span><br />
&nbsp; $match = <span style="color: #000000;">&#91;</span>regex<span style="color: #000000;">&#93;</span>::<span style="color: #0000FF;">matches</span><span style="color: #000000;">&#40;</span>$webClient.<span style="color: #0000FF;">ResponseHeaders</span><span style="color: #000000;">&#91;</span><span style="color: #808080;">"Set-Cookie"</span><span style="color: #000000;">&#93;</span>, $regex<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#93;</span><br />
&nbsp; $antiCrsfToken = $match.<span style="color: #0000FF;">Groups</span><span style="color: #000000;">&#91;</span><span style="color: #808080;">"CRSF_Token"</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">Captures</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">Value</span></p>
<p>&nbsp; write-host <span style="color: #808080;">"`nYour Anti CRSF Token is: "</span> $antiCrsfToken</p>
<p>&nbsp; <span style="color: #008080;"># construct the message including the Anti CSRF Token</span><br />
&nbsp; $message = <span style="color: #808080;">"__RequestVerificationToken="</span> + <span style="color: #000000;">&#91;</span><span style="color: #000000;">System</span>.<span style="color: #0000FF;">Web</span>.<span style="color: #0000FF;">HttpUtility</span><span style="color: #000000;">&#93;</span>::<span style="color: #0000FF;">UrlEncode</span><span style="color: #000000;">&#40;</span>$antiCrsfToken<span style="color: #000000;">&#41;</span> +<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080;">"&amp;amp;fromName=Johnathon Fink"</span> +<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080;">"&amp;amp;fromAddress=prancesw@rmcres.com"</span> +<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080;">"&amp;amp;subject=Call for your diploma now"</span> +<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080;">"&amp;amp;body=Is your lack of a degree..."</span></p>
<p>&nbsp; <span style="color: #008080;"># send spam-spam-spam</span><br />
&nbsp; $webClient.<span style="color: #0000FF;">Headers</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">"Content-Type"</span>, <span style="color: #808080;">"application/x-www-form-urlencoded"</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; <span style="color: #000000;">&#91;</span><span style="color: #0600FF;">void</span><span style="color: #000000;">&#93;</span> $webClient.<span style="color: #0000FF;">UploadData</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">"http://adam.kahtava.com/contact/send"</span>, <span style="color: #808080;">"POST"</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">System</span>.<span style="color: #0000FF;">Text</span>.<span style="color: #0000FF;">Encoding</span><span style="color: #000000;">&#93;</span>::<span style="color: #0000FF;">UTF8</span>.<span style="color: #0000FF;">GetBytes</span><span style="color: #000000;">&#40;</span>$message<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;</p>
<p>&nbsp; write-host <span style="color: #808080;">"`nSuccess!!! Your spam has been sent.`n"</span><br />
<span style="color: #000000;">&#125;</span></div>
</div>
</div>
<p>
To run this script:</p>
<ol>
<li>Download the <a href="http://code.google.com/p/adamdotcom-script/source/browse/trunk/Scripts/PowerShell/Automated-AntiCSRF-Authentication-Script.ps1">script</a></li>
<li>Run PowerShell</li>
<li>Load the script: <code><a href="http://code.google.com/p/adamdotcom-script/source/browse/trunk/Scripts/PowerShell/Automated-AntiCSRF-Authentication-Script.ps1">.\Automated-AntiCSRF-Authentication-Script.ps1</a></code></li>
<li>Start sending spam-spam-spam: <code>PS &gt; spam-adamdotcom</code></li>
</ol>
<p>Here's the output as seen on my machine:</p>
<div class="syntax_hilite">
<div id="code-4">
<div class="code">PS C:\&gt; .\Automated-AntiCSRF-Authentication-Script.<span style="">ps1</span><br />
PS C:\&gt; spam-adamdotcom</p>
<p>Your Anti CRSF Token is:&nbsp; f54ZlHS3L1Xyl65dYd1uYYh90ygNKYmCswXJUnr0GYtgcrJdJILsQ2jyFotzc10L</p>
<p>Success!!! Your spam has been sent.</p></div>
</div>
</div>
<p></p>
<p>This example uses a derivation of the .NET Framework's <a href="http://msdn.microsoft.com/en-us/library/system.net.webclient.aspx">Web Client</a> class but with Cookies enabled, so it depends on the <a href="http://adamdotcom-services.googlecode.com/svn/trunk/AdamDotCom.Common.Service/Final-Assemblies/AdamDotCom.Common.Service.dll">AdamDotCom.Common.Service.dll</a> assembly (browse the source <a href="http://code.google.com/p/adamdotcom-services/source/browse/trunk#trunk/AdamDotCom.Common.Service/Source/Common/Utilities">here</a>). This dependency can be automatically resolved by issuing the <code>download-client</code> function that's also found within the PowerShell script.</p>
<p>Contribute, view, or download the openly available script here: <a href="http://code.google.com/p/adamdotcom-script/source/browse/trunk/Scripts/PowerShell/Automated-AntiCSRF-Authentication-Script.ps1">Automated-AntiCSRF-Authentication-Script.ps1</a></p>
]]></content:encoded>
			<wfw:commentRss>http://adam.kahtava.com/journal/2009/12/16/hacking-an-anti-cross-site-request-forgery-tokens-csrf-with-powershell/feed/</wfw:commentRss>
		</item>
		<item>
		<title>RESTful Web Services: What Are They?</title>
		<link>http://adam.kahtava.com/journal/2009/12/04/restful-web-services-what-are-they/</link>
		<comments>http://adam.kahtava.com/journal/2009/12/04/restful-web-services-what-are-they/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 16:00:35 +0000</pubDate>
		<dc:creator>Adam Kahtava</dc:creator>
		
		<category><![CDATA[ASP.NET MVC]]></category>

		<category><![CDATA[RESTful]]></category>

		<category><![CDATA[Services]]></category>

		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://adam.kahtava.com/journal/?p=2004</guid>
		<description><![CDATA[RESTful web services are all the rage these days, and for good reason. Many web based MVC frameworks depend on REST. Here's a crash course on what RESTful web services are and aren't.
REST stands for Representational state transfer. REST is not an architecture, instead it's a set of design criteria. RESTfulness and RESTful web service [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://en.wikipedia.org/wiki/Representational_State_Transfer#RESTful_web_services">RESTful web services</a> are all the rage these days, and for good reason. Many <a href="http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller#Implementations_of_MVC_as_web-based_frameworks">web based MVC frameworks</a> depend on REST. <strong>Here's a crash course on what RESTful web services are and aren't.</strong></p>
<p><a href="http://en.wikipedia.org/wiki/Representational_State_Transfer">REST</a> stands for Representational state transfer. REST is not an architecture, instead it's a set of design criteria. RESTfulness and RESTful web service try to make use of the full gambit of <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html">HTTP Methods</a> (GET, PUT, POST, DELETE, OPTIONS, and HEAD), and try to expose every resource or operation in a meaningful <a href="http://en.wikipedia.org/wiki/Uniform_Resource_Identifier">URI</a> / URL. RESTful web services are intuitive, and work similar to the way the human web works (meaningful semantic data is returned to the client, resources link to other resources, <a href="http://en.wikipedia.org/wiki/Microformat">microformats</a> are employed, and so on).</p>
<p><strong>Qualities associated with RESTfulness:</strong></p>
<ul>
<li>RESTful is the the way the human web works - where the data returned by services can be easily understood by humans (or robots) and usually contain links to other resources</li>
<li>RESTful web services use varying response formats. Common formats include: XHTML pages, XHTML microformats, JSON, XML, ad-hoc HTML, JavaScript, or build your own</li>
<li>RESTful web services depend on meaningful URIs. These URIs can contain scoping information, but shouldn't contain query requests. <em>For example: when searching for 'kumquat' on Google you're redirected to <span style="text-decoration: underline;">http://www.google.com/search?q=kumquat</span> where your search query is present in the URI. Whereas a URI like <span style="font-style: normal;"><span style="text-decoration: underline;">http://www.google.com/search/kumquat/</span></span> specifies the search parameters within the URI - this is not recommended as it implies some predictability, search results are unpredictable</em></li>
<li>RESTful web services also use query variables as inputs to algorithms</li>
<li>RESTful web services expose a URI for every piece of data the client may want to operate on</li>
<li>RESTful web services make use of HTTP methods (GET, PUT, POST, DELETE, OPTIONS, and HEAD)</li>
<li>RESTful web services don't keep the state on the server (that's the client's job), they don't like cookies, and don't like sessions</li>
<li>RESTful web services make use of <a href="http://en.wikipedia.org/wiki/List_of_HTTP_headers">HTTP Headers</a></li>
</ul>
<p><strong>Examples of RESTful web services:</strong></p>
<ul>
<li> <a href="http://en.wikipedia.org/wiki/Amazon_S3">Amazon S3</a></li>
<li> <a href="http://developer.yahoo.com/everything.html">Most of Yahoo!'s web services</a></li>
<li> The Atom protocol</li>
</ul>
<p><strong>Qualities that are <span style="text-decoration: underline;">not</span> RESTful:</strong></p>
<ul>
<li>Most SOAP or other RPC-Style Architectures where XML messages are placed in the <a href="http://en.wikipedia.org/wiki/HTTP_body_data">HTTP Body</a></li>
<li>Frameworks that depend heavily on overloaded POSTs and XML (See <a class="site-tit1" rel="nofollow" href="http://www.devarticles.com/c/a/Web-Services/Safety-Idempotence-and-the-ResourceOriented-Architecture/">Safety, Idempotence, and the Resource-Oriented Architecture</a> for more information)</li>
<li>Most big corporate web service frameworks are not RESTful. Some frameworks like WCF try to provide REST like functionality on top of a SOAP based API, but these add-ons can be obtuse and unRESTful.</li>
</ul>
<p><strong>Examples of unRESTful web services:</strong></p>
<ul>
<li><a href="http://www.flickr.com/services/api/request.xmlrpc.html">The XML-RPC Flickr API</a></li>
<li><a href="http://www.flickr.com/services/api/request.soap.html">The SOAP Flickr API</a></li>
<li><a href="http://www.flickr.com/services/api/request.rest.html">The REST Flickr API</a> - although the name implis REST, this API is designed more like an XML-RPC</li>
<li><a href="http://delicious.com/help/api">The delicious API</a></li>
</ul>
<p>The growing popularity of web based MVC frameworks is providing a welcomed push towards RESTfulness and the simplicity that it brings, because working with the grain of the web (REST) makes life simpler and more semantically meaningful too. If you want to learn more about RESTful web services then check out <a href="http://www.amazon.com/dp/0596529260/">Restful Web Services</a> by Leonard Richardson and Sam Ruby.</p>
]]></content:encoded>
			<wfw:commentRss>http://adam.kahtava.com/journal/2009/12/04/restful-web-services-what-are-they/feed/</wfw:commentRss>
		</item>
		<item>
		<title>What Are Anti Cross-site Request Forgery Tokens And What Are They Good For?</title>
		<link>http://adam.kahtava.com/journal/2009/11/25/what-are-anti-cross-site-request-forgery-tokens-and-what-are-they-good-for/</link>
		<comments>http://adam.kahtava.com/journal/2009/11/25/what-are-anti-cross-site-request-forgery-tokens-and-what-are-they-good-for/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 17:00:05 +0000</pubDate>
		<dc:creator>Adam Kahtava</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[ASP.NET MVC]]></category>

		<guid isPermaLink="false">http://adam.kahtava.com/journal/?p=2030</guid>
		<description><![CDATA[Anti Cross-site Request Forgery Tokens help prevent Cross-site Request Forgery (CSRF) also known as XSRF - pronounced "sea-surf" - and are usually implemented through a hidden HTML form element that contains a unique ID. This ID is passed along with subsequent requests for data and validated on the server. Anti CSRF Tokens try to ensure the [...]]]></description>
			<content:encoded><![CDATA[<p>Anti Cross-site Request Forgery Tokens help prevent <a href="http://en.wikipedia.org/wiki/Cross-site_request_forgery">Cross-site Request Forgery (CSRF)</a> also known as XSRF - pronounced <em>"sea-surf"</em> - and are usually implemented through a hidden HTML form element that contains a unique ID. This ID is passed along with subsequent requests for data and validated on the server. Anti CSRF Tokens try to ensure the identity of the user. They aren't a replacement for <a href="http://en.wikipedia.org/wiki/CAPTCHA">CAPTCHA</a>s and don't prevent robots or <a href="http://en.wikipedia.org/wiki/Web_scraping">web scrapers</a> from manipulating your site - as you'll soon see.</p>
<p><strong>Why use an Anti CRSF Token?</strong></p>
<p>An overly simple example: If I didn't use an Anti Forgery Token on <a href="http://adam.kahtava.com/contact/">my contact page</a> (see the source code: <a href="http://code.google.com/p/adamdotcom-website/source/browse/trunk/Source/Website/App/Views/Contact/Index.aspx">View</a> or <a href="http://code.google.com/p/adamdotcom-website/source/browse/trunk/Source/Website/App/Controllers/ContactController.cs">Controller</a>), a Spammer could POST data directly against my contact form and potentially drown me with spam.</p>
<p>Here's a hypothetical form created by an evil Spammer. This form is hosted on http://spammer.com (not my site):</p>
<pre>&lt;form action="<strong>http://adam.kahtava.com/contact/send</strong>" method="POST"&gt;
  &lt;input name="fromName" type="text" value="Johnathon Fink" /&gt;
  &lt;input name="fromAddress" type="text" value="prancesw@rmcres.com" /&gt;
  &lt;input name="subject" type="text" value="Call for your diploma now" /&gt;
  &lt;textarea name="body"&gt;Is your lack of a degree...&lt;/textarea&gt;
  ...
&lt;/form&gt;</pre>
<p><em>Again, note that the form action contains a reference to my site (even though it is hosted on another site). </em></p>
<p>Now, imagine this was a form prompting a user for their username and password. These credentials could be maliciously stored while the user successfully authenticates and is then redirected to the site they thought they were visiting - the way <a href="http://en.wikipedia.org/wiki/Phishing">phishing</a> usually works.</p>
<p>After adding an Anti CRSF Token to my contact form, a Spammer can't access my form remotely (at least not without the token). My contact form with it's Anti CRSF Token:</p>
<pre>&lt;form action="/contact/send" method="post" name="contact"&gt;
  &lt;input name="<strong>__RequestVerificationToken</strong>" type="hidden" value="0sAqY1ZKb+Qia4..." /&gt;
  &lt;input name="fromName" ...</pre>
<p><em>Note the presence of the RequestVerificationToken.</em></p>
<p>Said Spammer, can't abuse my form without including the unique token. Technically speaking the Spammer can still abuse my form, but he now needs to:</p>
<ul>
<li>Request (GET) <a href="http://adam.kahtava.com/contact">my contact form</a></li>
<li>Parse out the Anti CRSF Token</li>
<li>POST their spam into <a href="http://adam.kahtava.com/contact/send">my contact form</a> along with the token</li>
</ul>
<p>This is pretty easy to do if you have an implementation of a HTTP Client library that supports cookies.</p>
<p><strong>How to hack an Anti CRSF Token protected form</strong></p>
<p>Using an extended instance of .NETs Web Client here's how our Spammer could circumvent my Anti CRSF Token.</p>
<p>The Spamming script by that wascaly Spammer:</p>
<pre><strong>// create a new HTTP Web Client that supports cookies</strong>
var webClient = new <a href="http://code.google.com/p/adamdotcom-services/source/browse/trunk/AdamDotCom.Common.Service/Source/Common/Utilities/WebClientWithCookies.cs">WebClientWithCookies</a>();

<strong>//download my contact page containing the Anti CRSF Token</strong>
webClient = webClient.DownloadData("http://adam.kahtava.com/contact");

<strong>//parse out the Anti CRSF Token</strong>
var antiCrsfToken = <a href="http://code.google.com/p/adamdotcom-services/source/browse/trunk/AdamDotCom.Common.Service/Source/Common/Utilities/Utilities.cs">RegexUtilities</a>.GetTokenString(
                      new Regex("__RequestVerificationToken=(?&lt;CRSF_Token&gt;[^;]+)")
                      .Match(webClient.ResponseHeaders["Set-Cookie"]), "CRSF_Token");

<strong>//now the Spammer can drown me in spam-spam-spam
// by scraping my Anti CRSF Token and posting it into my form</strong>
webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
byte[] response = webClient.UploadData("http://adam.kahtava.com/contact/send", "POST",
                            Encoding.UTF8.GetBytes(
                              "<strong>__RequestVerificationToken</strong>=" + antiCrsfToken +
                              "&amp;fromName=\"Johnathon Fink\"" +
                              "&amp;fromAddress=\"prancesw@rmcres.com\"" +
                              "&amp;subject=\"Call for your diploma now\"" +
                              "&amp;body=\"Is your lack of a degree...\""));</pre>
<p>The Spammer is back at their old tricks sending me more Spam. ARGH!</p>
<p><strong>What's the use of an Anti CRSF Token?</strong></p>
<p>Anti CRSF Tokens help prevent phishing attacks. They aren't meant to prevent spammers or Dr Robotnik and his robots (or web scrapers) from running automated scripts against your web application. Keep in mind, that if your site suffers from other <a href="http://en.wikipedia.org/wiki/Cross-site_scripting">XSS</a> vulnerabilities (where the privacy of your cookies or sessions are compromised) then Anti CRSF Tokens don't work at all.</p>
<p>Read more about how Anti CRSF Tokens work here: <a href="http://blog.codeville.net/2008/09/01/prevent-cross-site-request-forgery-csrf-using-aspnet-mvcs-antiforgerytoken-helper/">Prevent Cross-Site Request Forgery (CSRF) using ASP.NET MVC’s AntiForgeryToken() helper</a> or learn more about Cross-Site Request Forgery at: <a href="http://www.cgisecurity.com/csrf-faq.html">The Cross-Site Request Forgery (CSRF/XSRF) FAQ</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://adam.kahtava.com/journal/2009/11/25/what-are-anti-cross-site-request-forgery-tokens-and-what-are-they-good-for/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How To Fix the: &#8220;Validation of viewstate MAC failed&#8221; Error (ASP.NET MVC)</title>
		<link>http://adam.kahtava.com/journal/2009/11/23/how-to-fix-the-validation-of-viewstate-mac-failed-error-aspnet-mvc/</link>
		<comments>http://adam.kahtava.com/journal/2009/11/23/how-to-fix-the-validation-of-viewstate-mac-failed-error-aspnet-mvc/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 17:00:26 +0000</pubDate>
		<dc:creator>Adam Kahtava</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[ASP.NET MVC]]></category>

		<guid isPermaLink="false">http://adam.kahtava.com/journal/?p=2011</guid>
		<description><![CDATA[I run my site on a Windows Shared Hosting account, and every time I updated the assemblies on my ASP.NET MVC site I'd be presented with the "Validation of viewstate MAC failed" error.
The "Validation of viewstate MAC failed" error only occurred when a page contained an HTML form element that made use of MVC's AntiForgeryToken. The quick fix was to [...]]]></description>
			<content:encoded><![CDATA[<p>I run my site on a Windows Shared Hosting account, and every time I updated the assemblies on my ASP.NET MVC site I'd be presented with the <em>"Validation of viewstate MAC failed"</em> error.</p>
<p>The <em>"Validation of viewstate MAC failed"</em> error only occurred when a page contained an HTML form element that made use of MVC's <a href="http://msdn.microsoft.com/en-us/library/dd492767.aspx">AntiForgeryToken</a>. The quick fix was to delete my <code>__RequestVerificationToken</code> cookie, but the error would rear its ugly head the minute I touched my assemblies. The <strong>long term solution</strong> was to add a <a href="http://msdn.microsoft.com/en-us/library/w8h3skw9.aspx">machineKey element</a> to my Web.config file - asking visitors to delete a specific cookies when visiting my site was not a viable option.</p>
<p><strong>How I fixed the </strong><em><strong>"Validation of viewstate MAC failed"</strong></em><strong> error on Shared Hosting:</strong></p>
<ol>
<li>I used the <a href="http://aspnetresources.com/tools/keycreator.aspx">&lt;machineKey&gt; Generator Tool</a> to generate a machine key</li>
<li>I added the machineKey element to my Web.config file</li>
</ol>
<p>My Web.config now looks similar to this:</p>
<pre>&lt;?xml version="1.0"?&gt;
&lt;configuration&gt;
  &lt;system.web&gt;
    &lt;machineKey validationKey="..." decryptionKey="..." validation="SHA1" /&gt;</pre>
<p>Anyhow, I hope this post helps anyone else that's encountering this error.</p>
<p>Oh wait, here's the error in its entirety for The Google Machine's crawlers:</p>
<blockquote><p><code>Server Error in '/' Application.</code></p>
<p><code>Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that  configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.</code></p>
<p><code>Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.</code></p>
<p><code> </code><code>Exception Details: System.Web.HttpException: Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that  configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.</code></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://adam.kahtava.com/journal/2009/11/23/how-to-fix-the-validation-of-viewstate-mac-failed-error-aspnet-mvc/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Site Update: New Resume, Contact, Reviews, and Reading Lists Sections</title>
		<link>http://adam.kahtava.com/journal/2009/11/08/site-update-new-resume-contact-reviews-and-reading-lists-sections/</link>
		<comments>http://adam.kahtava.com/journal/2009/11/08/site-update-new-resume-contact-reviews-and-reading-lists-sections/#comments</comments>
		<pubDate>Sun, 08 Nov 2009 17:00:37 +0000</pubDate>
		<dc:creator>Adam Kahtava</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[ADC Services]]></category>

		<category><![CDATA[ADC Website]]></category>

		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[ASP.NET MVC]]></category>

		<category><![CDATA[Amazon]]></category>

		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://adam.kahtava.com/journal/?p=1974</guid>
		<description><![CDATA[This site now sports a Resume, Contact Me, Reviews, and Reading Lists section.
If you're reading this from an RSS feed, then the changes looks like this:

These new sections make use of the services I created earlier - my resume content is pulled directly from LinkedIn via my Resume service, the Reading Lists and Reviews are being pulled from Amazon [...]]]></description>
			<content:encoded><![CDATA[<p>This site now sports a <a href="http://adam.kahtava.com/resume/curriculum-vitae/software-developer/">Resume</a>, <a href="http://adam.kahtava.com/contact-me/">Contact Me</a>, <a href="http://adam.kahtava.com/book-reviews/">Reviews</a>, and <a href="http://adam.kahtava.com/reading-lists/recommended-and-wishlist/">Reading Lists</a> section.</p>
<p>If you're reading this from an RSS feed, then the changes looks like this:</p>
<p style="padding-left: 30px;"><img src="http://adam.kahtava.com/journal/images/blog/adamdotcom-navigation-update.png" alt="Navigation changes on my site" width="429" height="112" /></p>
<p>These new sections make use of the services I created earlier - my resume content is pulled directly from LinkedIn via my <a href="http://adam.kahtava.com/journal/2009/09/24/introducing-my-linkedin-resume-service-view-your-resume/">Resume service</a>, the Reading Lists and Reviews are being pulled from Amazon via my <a href="http://adam.kahtava.com/journal/2009/09/15/introducing-my-amazon-web-service-find-your-profile-view-your-wishlist-or-reviews/">Amazon service</a>, and I'm still working on a personalized greeting module which will make use of my <a href="http://adam.kahtava.com/journal/2009/09/30/introducing-my-whois-service-customize-your-site-content-based-on-referrals-location-and-more/">Whois service</a>.</p>
<p>Now, when I update my resume on LinkedIn, add a new item to my Amazon wishlist, or write a new Review on Amazon the content is updated within this site and indexed by the Google.</p>
<p>It took longer than expected to get these new pages up and running - mostly due to a couple false starts. You see, I'm running this site on Windows shared hosting which unfortunately doesn't give me many options - sure, sure, I could purchase another hosting account, but developers are like freak'n MAcGyver we like working within ridiculous constraints. It's all about the challenge! Anyways, I first tried using Ruby on Rails on shared hosting (fail), then tried using PHP on Trax (fail), and finally reverted to ASP.NET MVC. While ASP.NET MVC is heads and tails more fun than Web Forms / Classic ASP.NET, the impedance mismatch between strongly typed objects and web languages (JavaScript, CSS, XHTML) is still annoying. Thankfully the <a href="http://github.com/mvccontrib/MvcContrib">MVC Contrib</a> project solves some of these pains, however it can't solve them all.</p>
<p>My next steps with this site are to: finish the greeting module, update the layout (drop the WordPress theme), and finish a Github / Google Code repo widget (kind of like this <a href="http://drnicwilliams.com/2008/05/03/github-badge-for-your-blog/">one</a>) for the sidebar.</p>
<p>Contribute, view, or download the openly available source code <a href="http://code.google.com/p/adamdotcom-website/source/browse/trunk/#trunk/Source/Website">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://adam.kahtava.com/journal/2009/11/08/site-update-new-resume-contact-reviews-and-reading-lists-sections/feed/</wfw:commentRss>
		</item>
		<item>
		<title>MVC is a Welcome Addition to ASP.NET, but&#8230;. MVC Frameworks, like Ruby on Rails are More Mature</title>
		<link>http://adam.kahtava.com/journal/2008/11/26/mvc-is-a-welcome-addition-to-aspnet-but-mvc-frameworks-like-ruby-on-rails-are-more-mature/</link>
		<comments>http://adam.kahtava.com/journal/2008/11/26/mvc-is-a-welcome-addition-to-aspnet-but-mvc-frameworks-like-ruby-on-rails-are-more-mature/#comments</comments>
		<pubDate>Thu, 27 Nov 2008 03:01:29 +0000</pubDate>
		<dc:creator>Adam Kahtava</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[ASP.NET MVC]]></category>

		<category><![CDATA[RoR]]></category>

		<guid isPermaLink="false">http://adam.kahtava.com/journal/PermaLink,guid,3cc6f99a-4716-46bb-a9bf-f1bfc46274b0.aspx</guid>
		<description><![CDATA[The Model View Controller (MVC) pattern is a great addition to ASP.NET. The MVC pattern was first described in 1979 by the SmallTalk community - those crazy SmallTalk guys!
Today Wikipedia lists 80 different web frameworks that use MVC - with Java and PHP topping the list for the languages with the most MVC web frameworks. [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://en.wikipedia.org/wiki/Model-view-controller">Model View Controller (MVC)</a> pattern is a great addition to ASP.NET. The MVC pattern was first described in 1979 by the SmallTalk community - <em>those crazy SmallTalk guys!</em></p>
<p>Today <a href="http://en.wikipedia.org/wiki/Model-view-controller#Implementations_of_MVC_as_web-based_frameworks">Wikipedia lists 80 different web frameworks that use MVC</a> - with Java and PHP topping the list for the languages with the most MVC web frameworks. MVC enforces a separation of responsibilities: Markup / CSS / JavaScript, Domain Objects / Containers, and Actions / Controls are broken up into their respective directories. In addition MVC provides the ability to test most of your code and is more intuitive with how the web works (REST like, based on URIs, plays nicer with the browser, and not dependent on POST backs).</p>
<p><strong>Finding good resources specifically for ASP.NET MVC is impossible at this time, but <a href="http://www.amazon.com/s/ref=nb_ss_gw?url=search-alias%3Dstripbooks&amp;amp;field-keywords=rails&amp;amp;x=13&amp;amp;y=23">the books covering Ruby on Rails (RoR)</a> are invaluable.</strong> RoR has been around since 2005, it uses the same basic MVC approach, similar routing, similar control structure, has a mature community, a large collection of plug-ins, and well established tools (anyone claiming that ASP.NET MVC can't do what WebForms can, should look to Rails as an example). <em>Gasp! It's almost like ASP.NET MVC has copied Rails!! :)</em></p>
<p>Anyhow; the more I learn about Rails and Ruby, the more I realized that the communities like RoR (SmallTalk, and even some of the PHP world) are years ahead of my native .NET community. At this point I'm considering abandoning .NET in favour of Ruby / Rails / RSpec or at least Merb / Ruby / RSpec. In the future when ASP.NET MVC and IronRuby are more mature or when the corporate world starts using ASP.NET MVC (read <em>never ever!</em>) or when I'm approached to work on an ASP.NET MVC project I might move back into ASP.NET. <strong>In the mean time I'd like to contribute to IronRuby as I work towards jumping my current technology stack. </strong>I've armed myself with Textmate (the <a href="http://www.e-texteditor.com/">E Text Editor</a>) and a MacBook Pro is in my future. I'll get back to you on how this goes. :)</p>
]]></content:encoded>
			<wfw:commentRss>http://adam.kahtava.com/journal/2008/11/26/mvc-is-a-welcome-addition-to-aspnet-but-mvc-frameworks-like-ruby-on-rails-are-more-mature/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
