The Spanner logo
    • Home
    • Blog
      • Blog home
      • RSS
    • Login
    • Home
    • Blog
      • Blog home
      • RSS
    • Login
    The Spanner logo

    The Spanner
    Web security blog

    Made by Gareth Heyes
    Follow me on Twitter: @garethheyes

    Javascript for hackers!

    Hackvertor logo
    Shazzer logo
    My Github account
    Recent posts
    Introducing Feedworm: A Privacy-First RSS Reader That Lives in DevToolsSpeedy RSVP extensionAutoVaderHackvertor history and tag finderShadow Repeater v1.2.3 releaseBurp Hackvertor v2.1.24 releaseHacking roomsXSSing TypeErrors in SafarivalueOf: Another way to get thisMaking the Unexploitable Exploitable with X-Mixed-Replace on FirefoxThe curious case of the evt parameterCSS-Only Tic Tac Toe ChallengeRewriting relative urls with the base tag in SafariBypassing DOMPurify with mXSSNew IE mutation vectorHow I smashed MentalJSMentalJS DOM bypassAnother XSS auditor bypassXSS Auditor bypassBypassing the IE XSS filterUnbreakable filterMentalJS bypassesmXSSJava SerializationBypassing the XSS filter using function reassignmentRPOSandboxed jQueryX-Domain scroll detection on IE using focusEpic fail IEnew operatorDecoding complex non-alphanumeric JavaScriptHacking FirefoxDOM ClobberingBypassing XSS AuditorThe evolution of codeNon-Alpha PHP in 6-7 charsetTweetable PHP-Non AlphaMentalJS for PHPOpera x domain with video tutorialSandboxing and parsing jQuery in 100ms

    Eval a url

    By Gareth Heyes (@hackvertor)

    Published 14 years 1 month ago • Last updated July 2, 2025 • ⏱️ < 1 min read

    ← Back to articles

    You might have seen a blog post or came to the conclusion that urls are in fact valid JavaScript such as:

    http://thespanner.co.uk (label) (comment)

    That's weird and cool but how do we execute JavaScript from the url? Something like:

    http://thespanner.co.uk\nalert(1) (label) (comment) (newLine) (functionCall)

    Trouble is the new line isn't allowed inside the browser url bar or is it? ES5 introduced in the standard that line separators and paragraph separators would act as traditional new lines in JavaScript and separate new statements. Thankfully our friend IE allows us to do this directly in the url. Using these characters allows you to create an eval'able url.

    test line sep test para sep

    So now we don't need to do eval(location.hash.slice(1)) we can simply do eval(location) :) I found this while discussing with Mario and Yosuke Hasegawa on what the shortest HTML based XSS injection was. Using this technique it's probably 21 (without using netscape 4).

    <svg onload=eval(URL)

    You of course must pass your JavaScript as a non-existent query param such as:

    &&#x2028;alert(1)

    Update...

    As Stefano Di Paola points out, using hash will allow you to use this technique on Chrome and Opera.

    ← Back to articles