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

    valueOf: Another way to get this

    By Gareth Heyes (@hackvertor)

    Published 1 year ago • Last updated May 12, 2025 • ⏱️ < 1 min read

    ← Back to articles

    Browser window with an SVG tag and arrows

    Back in the day, you could use valueOf to access the window object because browsers would fall back to it by default. This behavior was eventually patched in the JavaScript specification - now, the engine returns undefined instead. Here’s what that trick looked like:

    (1,[].valueOf)().alert(1)

    We used this for all sorts of non-alphanumeric payloads, but that fun ended with the spec change. Still, not all is lost: you can still (ab)use valueOf in event handlers. In that context, valueOf refers to the current HTML node, much like this.

    <svg onload=valueOf().ownerDocument.defaultView.alert(1)>

    Basically calling valueOf() in the event will be the equivalent of accessing this since the HTML node is an object and valueOf() will return the current object's value and the JS specification doesn't alter this behaviour.

    ← Back to articles