title: Generating CSRF tokens for multiple forms on a single page
body: <p>I am currently generating a <code>CSRF</code> token in my forms to prevent cross-site request forgery. It looks like:</p>
  
  <pre><code>&lt;form method="post" action="action.php"&gt;
     &lt;input type="hidden" id="security_token" name="security_token" value="gTt96phAcretR99rafEjepHebrEZadEdezadagaZ3gAS5es33WReJeZaMADU2AWr" /&gt;
     ...
  &lt;/form&gt;
  </code></pre>
  
  <p>The problem is that I have multiple forms on a single page. Must I create a security token for each form so <code>security_token_1</code>, <code>security_token_2</code>, or can I simply instead of generating the security token inside of forms, append it to a property to the entire <code>body</code> tag like:</p>
  
  <pre><code>&lt;body data-csrf-token="gTt96phAcretR99rafEjepHebrEZadEdezadagaZ3gAS5es33WReJeZaMADU2AWr"&gt;
  ...
  &lt;/body&gt;
  </code></pre>
  
  <p>Is this insecure in any way? It simplifies things quite a bit, since I can simply append the security token to the body element instead of dealing with multiple security tokens.</p>
  
  <p>Thanks for the insight and comments.</p>