Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2012
586
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 2.69 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <title>XSS Test</title>
  5.         <meta charset="utf-8">
  6.         <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
  7.  
  8.         <!-- Show that jQuery events still work normally -->
  9.         <script type="text/javascript">
  10.             $(function () {
  11.                 $('.red').click(function () { alert('jQuery Event'); });
  12.             });
  13.         </script>
  14.     </head>
  15.  
  16.     <body>
  17.         <script type="text/javascript">
  18.             (function () {
  19.                 // Remove the body from the DOM so scripts don't execute as they load
  20.                 var parent = document.body.parentNode,
  21.                     body = document.body.parentNode.removeChild(document.body);
  22.  
  23.                 document.addEventListener('DOMContentLoaded', function (e) {
  24.                     var elements,
  25.                         scripts,
  26.                         attributes,
  27.                         ii,
  28.                         jj;
  29.  
  30.                     // Remove events inside the body
  31.                     elements = body.querySelectorAll('*');
  32.                     for (ii = 0; ii < elements.length; ii += 1) {
  33.                        attributes = elements[ii].attributes;
  34.                        for (jj = 0; jj < attributes.length; jj += 1) {
  35.                            if (attributes[jj].nodeName.substr(0, 2) === 'on') {
  36.                                elements[ii].removeAttribute(attributes[jj].nodeName);
  37.                            }
  38.                        }
  39.                    }
  40.  
  41.                    // Remove script tags inside the body.
  42.                    while (true) {
  43.                        scripts = body.getElementsByTagName('script');  // For some reason one pass
  44.                        if (scripts.length === 0) {                     // doesn't always remove all of the
  45.                            break;                                      // script tags, so lather, rinse, repeat!
  46.                        }
  47.                        for (ii = 0; ii < scripts.length; ii += 1) {
  48.                            scripts[ii].parentNode.removeChild(scripts[ii]);
  49.                        }
  50.                    }
  51.                    // Reinsert the body into the document after it's been cleaned
  52.                    parent.appendChild(body);
  53.                }, false);
  54.            }());
  55.        </script>
  56.         <div class="red" onclick="alert('Failed! onclick was executed.')">hello world</div>
  57.         <img src="http://example.com/failure.png" onerror="alert('Failed! onerror was executed.');"/>
  58.         <script>
  59.         alert('Failed! Script tag was executed.');
  60.         </script>
  61.     </body>
  62. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement