GM_xmlhttpRequest referer not passing?
|
|
Hey everyone,
I've done extensive googling but have not found a specific answer, it almost seems like firefox is dropping the referer header tag? What's the deal?
|
|
|
No, GM_xmlhttpRequest does not send a referer header (or it is always blank). I assume this is a bug in Greasemonkey, or perhaps it's intentional. I tried searching for info on it but gave up. I did not see it listed here: http://greasemonkey.mozdev.org/bugs.html |
|
|
I have posted a bug request here: https://www.mozdev.org/bugs/show_bug.cgi?id=18104 It really was a key part of a test script I was making, quite annoying.
|
|
|
I haven't tried just using XMLHttpRequest, maybe it works different, or maybe it does the same thing, it's worth a try. Another thing you might want to know: when using GM_xmlhttpRequest the browser caches the requests (at least SeaMonkey does). The first request shows up in the logs but successive requests do not until the browser cache is emptied, then the first request will show again. Normally I would see a 304 (page not modified), but I didn't even see this. I even tried setting headers for caching, which I forget now, but it wouldn't matter if the browser is just pulling it out of the cache.
|
|
|
XMLHttpRequest passes Referer header correctly.
|
|
|
@gimmic Some information for you that might be helpful.
|
|
|
Thanks for the info- I'll give the Referer bit a try shortly, im going to be frustrated if that's the issue! I'll follow up if it works. I've also been poking around on the user groups and getting information saying it may be security related that some of the attribs are left out by the GM wrapper. |
|
|
@gimmic I don't see anything in the visible code that would indicate it's being filtered by GM... if it works with a direct html call, then the calls in the chrome namespace should have at minimum equal privileges. I'm not ready to do any testing as of yet myself, but when I do, down the road, will report what I find. |
|
|
@gimmic Well I've poured over TONS of code this weekend, and needed a bit of time to gather my brain cells. Here's a few things that I've learned about XMLHttpRequest
Currently Firefox is not following the W3C recommendations on XMLHttpRequest by not allowing the Referer header atom value to be set in the chrome namespace using setRequestHeader. W3C Working Draft (e.g. a whitepaper or RFC) 26 October 2007 clip from Section 2, setRequestHeader method, Item 6
8D Other related links http://groups.google.com/group/greasemonkey-dev/browse_thread/thread/7 http://wiki.greasespot.net/GM_xmlhttpRequest |
|
|
Wow. Very nice Marti.. so this is starting to kind of look like an issue with FF? Are you saying that even using XMLHttpRequest the Referer isnt being passed through FF? In other words it's currently not possible in GM to pass Referer properly? Thanks for the (very) informative update! |
|
|
Could you maybe insert a new XMLHttpRequest object in a script element into the page? That way you would have access to the Referrer. e.g. var xScript = document.createElement('script');
xScript.type = 'text/javascrpt';
xScript.innerHTML = "function getXmlHttpRequest(){var httpRequest=null;httpRequest=new XMLHttpRequest();return httpRequest;}";
document.getElementsByTagName('head')[0].appendChild(xScript);
var xhr = unsafeWindow.getXmlHttpRequest();
xhr.onreadystatechange = function() {
if (request.readyState == 4 && request.status == 200) {
alert(xhr.getResponseHeader( 'Referrer' ));
}
};
xhr.open("GET", url, true);
xhr.send(null);
|
|
|
The header name is 'Referer', and it's a Request Header.
|
|
|
Now that I've had enough time to cite references and document Greasemonkey a bit better (which is is important to the explanations I have here), I can get back for a while to u.s.o. @gimmic
What I didn't say in my response above is about YOUR NAMESPACE... any user script namespace is in what they call in the Sandbox, and of course it is not privileged enough either to send the Referer atom (at least on the machines I have tested). Currently the only way that I have successfully sent a Referer atom is to use the unsafeWindow object, which I'm not thrilled with... I usually block all Referer atoms period, but I know some sites are annoying enough to require them. In that case I usually forge them and apparently that's not possible in chrome or the sandbox using the XMLHttpRequest (XHR for short) method, which presents a very large problem. @Yansky
@Descriptor
|
|
|
@gimmic I've confirmed that it's definitely the browser that is filtering it... however it doesn't look like the Greasemonkey team is going to make any effort to implement the fix anytime in the near future. Only suggestion for now is to use the DOM XMLHttpRequest in an unsafeWindow over the Greasemonkey API implementation or some combination of both to achieve what you need. |
