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

    Location based XSS attacks

    By Gareth Heyes (@hackvertor)

    Published 17 years 5 months ago • Last updated March 22, 2025 • ⏱️ 2 min read

    ← Back to articles

    The basic attack

    Using the hash portion of the location is a good way to beat filters, anything sent via the hash is not sent to the server in question. We can use a large amount of data which is hidden from the server side filters and combine it with data sent on the server. For example we can send:-

    http://someserver.com/somepage.php?
    param=",eval(location.hash.slice(1))//#alert(1)
    

    Data sent to the server : ``` ",eval(location.hash.slice(1))//

    Data only sent through the client : ```
    #alert(1)
    

    "slice" simply selects the location.hash from the second character because the # is included and would raise a syntax error.

    More advanced variation

    There are times when server side filters will remove all instances of "(" or ")" or maybe a WAF will disallow such requests. That alone will not save you from these sort of attacks because there's a trick you can use to defeat those filters.

    Remember the server can only see the server side potion of the attack, we can combine both strings to produce our attack without "(" or ")". For example:-

    http://someserver.com/somepage.php?
    param=",location='javascript:/*'+location.hash//#*/alert(1)
    

    Data sent to the server : ``` ",location='javascript:/*'+location.hash//

    Data sent to the client : ```
    #*/alert(1)
    

    We start the comment in the server side request and complete it in the client side location.hash request. Location is assigned javascript:/*#*/alert(1) removing the need for the slice(1) as shown previously.

    The attacks mentioned are DOM based XSS attacks and are actually more common than you think, they are just more difficult to find than regular XSS.

    ← Back to articles