Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I spoof the user agent of a JavaScript GET request?

How can I spoof the user agent of a JavaScript GET request? setRequestHeader with User-Agent isn't allowed:

xmlHttpRequest.setRequestHeader("User-Agent", "...");
like image 997
XP1 Avatar asked Aug 09 '11 11:08

XP1


People also ask

Can you spoof a user agent?

The process is called user-agent spoofing. Yes, when a browser or any client sends a different user-agent HTTP header from what they are and fake it that is called spoofing.

What is user agent in JavaScript?

User-Agents is a JavaScript package for generating random User Agents based on how frequently they're used in the wild. A new version of the package is automatically released every day, so the data is always up to date.

What is browser spoof?

What Is Browser Spoofing? Fraudster use browser spoofing to manipulate their browser to make it seem as if they are using a different browser configuration which they would use regularly, for example, to make it seems as if they're from a different country.

Is user agent accurate?

Yes its reliable for non hacker user. The user agent string is a text that the browsers themselves send to the webserver to identify themselves, so that websites can send different content based on the browser or based on browser compatibility.


2 Answers

In short: You can't due to built-in cross-domain limitations.

One way "around" that was to write a proxy-webservice and let the server spoof whatever headers you need spoofed.

like image 106
erlando Avatar answered Sep 18 '22 23:09

erlando


You can't do this in a half-decent browser because of security issues surrounding it. You don't want XSS scripts to be changing request headers and running rampant on your site.

However I believe there's a workaround in IE if you use VBScript:

MyHttp.setRequestHeader "User-Agent", "MyCustomUser"

The alternative is to have a web page on your site dedicated to forwarding a GET request, changing the appropriate headers as necessary.

like image 27
tskuzzy Avatar answered Sep 20 '22 23:09

tskuzzy