title: Best Pattern for AllowUnsafeUpdates
body: <p>So far, in my research I have seen that it is unwise to set AllowUnsafeUpdates on GET request operation to avoid cross site scripting. But, if it is required to allow this, what is the proper way to handle the situation to mitigate any exposure? </p>
  
  <p>Here is my best first guess on a reliable pattern if you absolutely need to allow web or site updates on a GET request.</p>
  
  <p>Best Practice?</p>
  
  <pre><code>protected override void OnLoad(System.EventArgs e)
  {
      if(Request.HttpMethod == "POST")
      {
          SPUtility.ValidateFormDigest();
          // will automatically set AllowSafeUpdates to true
      }
  
      // If not a POST then AllowUnsafeUpdates should be used only
      // at the point of update and reset immediately after finished
  
      // NOTE: Is this true? How is cross-site scripting used on GET
      // and what mitigates the vulnerability?
  }
  
  // Point of item update
  
      using(SPSite site = new SPSite(SPContext.Current.Site.Url, SPContext.Current.Site.SystemAccount.UserToken))
      {
          using (SPWeb web = site.RootWeb)
          {
              bool allowUpdates = web.AllowUnsafeUpdates; //store original value
              web.AllowUnsafeUpdates = true;
  
              //... Do something and call Update() ...
  
              web.AllowUnsafeUpdates = allowUpdates; //restore original value
  
          }
      }
  </code></pre>
  
  <p>Feedback on the best pattern is appreciated.</p>