title: testing for html/script injection and getting kicked from a server
body: <p>In researching an idea I came across a good <a href="https://www.youtube.com/watch?v=QSMbk2nLTBk" rel="nofollow noreferrer">YouTube video on security (with nodejs)</a> which covered a lot more than the usual SQL injection. One such was simple script and html injection through html encoding. javascript buffers etc. </p>
  
  <p>In researching this for a project I'm working on I came across this script from the <a href="http://php.net/manual/en/language.variables.external.php" rel="nofollow noreferrer">php.net</a> documentation website:</p>
  
  <pre><code>&lt;?php
  if ($_POST) {
      echo '&lt;pre&gt;';
      echo htmlspecialchars(print_r($_POST, true));
      echo '&lt;/pre&gt;';
  }
  ?&gt;
  &lt;form action="" method="post"&gt;
      Name:  &lt;input type="text" name="personal[name]" /&gt;&lt;br /&gt;
      Email: &lt;input type="text" name="personal[email]" /&gt;&lt;br /&gt;
      Beer: &lt;br /&gt;
      &lt;select multiple name="beer[]"&gt;
          &lt;option value="warthog"&gt;Warthog&lt;/option&gt;
          &lt;option value="guinness"&gt;Guinness&lt;/option&gt;
          &lt;option value="stuttgarter"&gt;Stuttgarter Schwabenbräu&lt;/option&gt;
      &lt;/select&gt;&lt;br /&gt;
      &lt;input type="submit" value="submit me!" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Looking at the code, I believed the html injection was safe and as I didn't have somewhere to test this script out, I just uploaded it to a hosting domain I have and played with it remotely. When I tried a basic <code>alert</code> injection:</p>
  
  <pre><code>&lt;script&gt;alert("test");&lt;/script&gt;
  </code></pre>
  
  <p>I got an error from the server (a <code>403 Forbidden</code>). I thought I malformed the html so I tried some minor variations and before I knew it I was banned from my server :D (I was able to reset it, that's not the concern). </p>
  
  <p>Tonight I deployed a VM with apache and php and started playing with it, and when I used the same code, I actually saw what I'd originally expected to see. The array output is presented as expected because of the <code>htmlspecialchars</code>.</p>
  
  <pre><code>Array
  (
      [personal] =&gt; Array
          (
              [name] =&gt; &lt;b&gt;bold&lt;/bold&gt;
              [email] =&gt; &lt;script&gt;alert("test");&lt;/script&gt;
          )
  
      [beer] =&gt; Array
          (
              [0] =&gt; stuttgarter
          )
  
  )
  </code></pre>
  
  <p>What I'd like to know is:</p>
  
  <p><strong>1. Does the browser do some manipulation that nullifies the script tags since there's nothing in the form that does that?</strong> My guess is that nothing is an issue until it's attempted to be parsed by the page on form submission. Correct?</p>
  
  <p><strong>2.</strong> When I ran it locally the output was as expected (ie, no alert box and correct parsing) which infers that the values are somewhat "safe" until php attempts to parse them via the <code>print_r</code>. If I remove the <code>htmlspecialchars</code> the page fails to load <code>ERR_BLOCKED_BY_XSS_AUDITOR</code> (so that's good). <strong>If the original page never parses the raw code, why would the remote server ban my IP if it's correctly escaped within the output code?</strong> Again, I'm guessing, but would it be the host is just preemptively trying to prevent attacks and processing all <code>$_POST</code> vars for XSS? </p>