Arbitrary Referer Spoofing with Empty Username




Networking: HTTP
10 years ago
7 years ago


(Reporter: Gregory Fleischer, Assigned: dveditz)



Bug Flags:
blocking1.8.1.13 +
wanted1.8.1.x +

Firefox Tracking Flags

(Not tracked)


(Whiteboard: [sg:dupe 415034], URL)



10 years ago
User-Agent:       Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv: Gecko/20071127 Firefox/
Build Identifier: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv: Gecko/20071127 Firefox/

This a generalization of bug 415034 that allows for spoofing of arbitrary referers.  In the URL, when the username portion of the authority is empty, arbitrary referers can be spoofed by using a specially constructed password field.  CSRF attacks can be performed against any site that depends only on referer checking for protection.

Online demo at:

The demo URL above generates a page with an iframe with a source of ''.

There is no user notification because there is no username.  The page returned makes a POST to display the request information.

When the referer is determined, there is miscalculation in the URL spec.  As a result, when the userinfo portion is removed from the URL, it actually removes the first portion of the true URL.  So, by creating a password field that aligns with the length of the URL portion to remove, an arbitrary referer can be created.  

For example:

Instead of changing:

The URL:
is changed to

The two strings in question:

Reproducible: Always

Steps to Reproduce:
1. Visit demo URL (

Actual Results:  
The line: 
is displayed.

Expected Results:  
The line should read: 

Change '' to desired referer in demo to see different values:[yoursitehere]

Comment 1

10 years ago
I believe that the problem is due to differing treatment of the 'mUsername.mLen' in the file mozilla/netwerk/base/src/nsStandardURL.cpp. 

In, "nsStandardURL::BuildNormalizedSpec", the length is tested to be greater than zero, but in "nsStandardURL::SetUserPass" the comparison is performed using greater than or equal zero.

So, the normalized spec doesn't have have the username and password added to it when the authority is calculated.  Then when the spec is adjusted in SetUserPass, the host portion is being damaged because it is assumed that it is actually the username/password that is being cleared. 

Comment 2

10 years ago
Wish I had seen this bug before I tracked it down for bug 415034 

You're exactly right, most of the URL code assumes that if there's no username there's no password, but ParseUserInfo() happily calculates its position anyway. BuildNormalizedSpec() ignores the  password when rebuilding the spec if there's no username, but does not clear the password position/length.

Places that call nsStandardURL::Userpass() get an empty string if there's no username despite any password lengths. That's actually correct, because the rebuilt spec doesn't have the password data in it anymore. Note comment "if there is no username, then there can be no password". This is why the exposable URI we create for the address bar is not munged -- that routine avoids touching the URI if it can so it checks if Userpass() is the empty string and only zaps the userpass if there is one.

The referrer, on the other hand, simply sets the userinfo to the empty string without checking (nsHttpChannel::SetReferrer, "clone->SetUserPass(EmptyCString());") and thus triggers this bug.

Couple of ways to fix this:

1) make SetUserPass() bail out on an empty username like everywhere else, checking "if (mUsername.mLen > 0) {" instead of the current >=

2) return an URI parsing error if there's a password part without a username (also need to fix SetPassword() so it errors if username length is <= 0, not just <0)

I'm uncomfortable with 1) alone, so 2) -- or both wouldn't hurt, actually

Confirming bug because of the good analysis and testcase, but this is really just a dupe of bug 415034 IMHO.
Assignee: nobody → dveditz
Ever confirmed: true
Whiteboard: [sg dupe 415034]

Comment 3

10 years ago
Fix for bug 415034 checked in to trunk
Last Resolved: 10 years ago
Flags: wanted1.8.1.x+
Flags: blocking1.8.1.13+
Resolution: --- → FIXED

Comment 4

10 years ago
Fix checked into 1.8 branch
Keywords: fixed1.8.1.13
Verified with Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/2008031114 Firefox/
Keywords: fixed1.8.1.13 → verified1.8.1.13


10 years ago
Group: security


7 years ago
Whiteboard: [sg dupe 415034] → [sg:dupe 415034]
You need to log in before you can comment on or make changes to this bug.