Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

216
Views
Is location.hash vulnerable to DOM XSS in jQuery selector when combined with other selectors

I'm using checkmarx SAST tool and its highlighting jquery selectors using the hash from the URL as Client DOM XSS:

$('[name=' +  location.hash.replace('#', '') + ' ]')

or even

$('#'location.hash.replace('#', ''))

I dont understand how any of the above examples can be vulnerable to XSS given that it has other parts of the selector in it, especially the first one. In my understanding, the only way someone can be vulnerable to XSS via jquery selector is by inserting the hash value without the hash symbol as the following:

$(location.hash.replace('#', ''))

where someone can put something malicious after the hash as https://example.com#<img src="" onerror="alert(1)". Even plain $(location.hash) I think was fixed in the latest releases of jquery.

Please fill me in with whatever I am missing

UPDATE

It turns out that what I thought is the least vulnerable is actually the most. try this $('[name="<img src="" onerror="alert(document.cookie)""]/>') and you'll see the alert popup.

Only jQuery selectors starting with hash or even starting with other selectors but has a hash preceding the injected element will not be exploitable for example this $('.something <img src="" onerror="alert(document.cookie)""]/> #hash') is exploitable, but this $('#hash <img src="" onerror="alert(document.cookie)""]/>') is not.

Can anyone please confirm that my findings are right, and if indeed any hash starting selector can be marked as not exploitable.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!