Skip to content
XSS Write-up Beginner

Re-basing of Relative URLs

A web application reflected user input without sanitisation and lacked a base-uri directive in its CSP, allowing an attacker to inject a base element. This could cause relative script URLs to resolve to an attacker-controlled domain, potentially executing malicious JavaScript in the victim's browser.

medium.com

Published on medium.com

Hey peeps, in this blog we will discuss about base-uridirective in CSP policy. As we all know, CSP policy is imposed by browser to accept resources from trusted sources and one such directive used in CSP policy is base-uri.

Yashwanth_Krishna, 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 reflected unsanitised user input into the page and its Content-Security-Policy omitted the base-uri directive, so an injected base element could change how relative URLs were resolved.

What the attacker needed

Reflected user input on the page; CSP lacks base-uri directive; attacker controls a domain

The fix

The site should add a base-uri directive to its Content-Security-Policy and sanitise user input so a base element cannot be injected.

How it was found

  1. Observe the application reflects user input on the page and the document's baseURI is the local application URL.
  2. Inject a base HTML element pointing to an attacker-controlled domain.
  3. Observe the document's baseURI changes to the attacker domain and a relative script fails to load from the original location.

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 web page can use a base tag to tell the browser where to find files that are referenced with short, relative paths. If a site lets an attacker add their own base tag, the browser may load scripts from the attacker's server instead of the real one. This report shows that missing a security rule called base-uri in the site's content security policy makes that possible.

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.