Skip to content
XSS Write-up Beginner

Reflected XSS in canonical link tag

The lab reflects user input in a canonical link tag without proper escaping, allowing an attacker to inject an attribute that calls the alert function. An attacker could craft a URL that, when visited and a specific key combination is pressed, executes JavaScript in the victim's browser.

medium.com

Published on medium.com

This lab reflects user input in a canonical link tag and escapes angle brackets.

Chirag Vyas, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the application reflects user input into the href attribute of a canonical link tag without properly escaping quotes or other attribute-breaking characters, allowing attribute injection.

Impact

An attacker could execute arbitrary JavaScript in a victim's browser if the victim visits a crafted URL and presses a specific key combination, potentially leading to session hijacking or other client-side attacks.

What the attacker needed

Victim visits a crafted URL; victim presses a specific key combination

How it was found

  1. Append a query string to the home page URL to see if it is reflected in the canonical link tag.
  2. Use a single quote to break out of the href attribute.
  3. Add an onclick attribute with the alert function, adjusting for the server adding a quote.
  4. Add an accesskey attribute so the element can be triggered via keyboard.
  5. Press the specified key combination (e.g., ALT+SHIFT+X) to trigger the alert.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

A canonical link tag tells search engines the main address of a page. Here, the page puts part of the web address into that tag without cleaning it properly. An attacker can add extra code to the address so that when someone visits the link and presses a certain key combination, harmful JavaScript runs in their browser.

What is XSS?

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.