[Privacy] Web browser user agents

Teo Parashkevov
The Code Vault
Published in
6 min readOct 5, 2021

How to anonymize yourself on the web using the user agent setting

Introduction

It is clear that in recent years a substantial amount of companies have changed their business models of operation to a more web-centric way of marketing and providing products and services. This, unsurprisingly, has led to an increase in the amount of user/customer data that needs to be aggregated in order to provide a more wholesome service. Therefore, much of today's web architecture relies on gathering statistical data from the users end-point device.

Web browsers were the earliest pieces of software to encounter this type of change. Actually, even before companies started to gather statistical user data, web browsers were sending all kinds of end-point device information. The user agent string is part of the Header that a browser may include when initializing a connection to a particular server. The reason being, “back in the day” when browsers did not agree upon a specific interpretation of a particular file/webpage/multi media file etc. , the server had to send a specific web page architecture that corresponded with the way that particular browser was going to interpret it.

The reason for having user agent information in the request of each connection header was valid for that particular time period. Nevertheless, nowadays most browsers “agree” on almost everything, however the user agent information is still being sent. Yet its purpose has expanded to a field closer to statistics rather than computer science.

In this article I will try to focus the readers attention towards one of modern web browsers privacy problems that we all face in this day an age, that is web browser user agents. I will give specific advice regarding static and dynamic change of web browser user agents and also some additional advice for a safer web browsing experience.

What is a web browser user agent ?

Mozilla MDN Web Documentations:

A user agent is a computer program representing a person, for example, a browser in a Web context. Besides a browser, a user agent could be a bot scraping webpages, a download manager, or another app accessing the Web. Along with each request they make to the server, browsers include a self-identifying User-Agent HTTP header called a user agent (UA) string. This string often identifies the browser, its version number, and its host operating system.

Spam bots, download managers, and some browsers often send a fake UA string to announce themselves as a different client. This is known as user agent spoofing.

The user agent string can be accessed with JavaScript on the client side using the NavigatorID.userAgent property.

Wikipedia:

In computing, a user agent is any software, acting on behalf of a user, which “retrieves, renders and facilitates end-user interaction with Web content”. A user agent is therefore a special kind of software agent.

Some prominent examples of user agents are web browsers and email readers. Often, a user agent acts as the client in a client–server system. In some contexts, such as within the Session Initiation Protocol (SIP), the term user agent refers to both end points of a communications session.

Examples

Example 1:

Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0

Example 2:

Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0

Example 3:

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.1 Safari/605.1.15

User agent string structure

<Browser software name> (<Operating System> <version>; <x86/x64 system>; <other system info>) <layout engine> / <layout engine version> <Browser software full name> <Browser software full version>

The advantages/disadvantages of changing the user agent

Advantages

  1. Gives a certain degree of protection against target specific malware
  2. Confuses tracking algorithms, therefore increasing the degree of web anonymity
  3. Randomizing user agents on every webpage you visit drastically reduce the chances of a hacker attack.

Disadvantages

  1. Reduces the quality of product advertisement relevance to a certain degree
  2. May lead to unrelated search, product suggestions.

Mozilla Firefox

Setting the user agent globally involves the setup of the general.useragent.override variable in the about:config preference panel. Type about:config > (accept the risk) > search for general.useragent.override. Then change the user agent string to the desired user agent.

Setting general.useragent.override string to the desired user agent string and restarting Firefox is the whole process of changing the user agent.

A useful add-on: User-Agent-Switcher

(How-to guide)

Google Chrome

Setting the user agent globally involves the setup of the useragent string variable. Open DevTools > (Show Network conditions) > Network conditions > User agent. Then choosing the desired user agent. If the desired user agent is not listed, you can choose “custom” and specify the user agent string.

Setting useragent string to the desired user agent string and restarting Chrome is the whole process of changing the user agent.

A useful add-on: User-Agent-Switcher

(How-to guide)

Microsoft Edge

Setting the user agent globally involves the setup of the useragent string variable. Open DevTools > (Show Network conditions) > Network conditions > User agent. Then choosing the desired user agent. If the desired user agent is not listed, you can choose “custom” and specify the user agent string.

Setting useragent string to the desired user agent string and restarting Edge is the whole process of changing the user agent.

A useful add-on: User-Agent-Switcher

(How-to guide)

Opera

Specifying user agent for Opera requires opening the opera.dll file with a HEX editor and changing the hard coded user agent string. This DLL file can be located inside the opera profile path. If you do not know where this directory is on your OS, go to opera:about in Opera and scroll down to Profile section. Another workaround is to enable “Reduce User-Agent request header” flag, from opera:flags

Creating a specific user agent for a specific website is also an option not only for Opera, but for all other web browsers. Here are the steps that need to be performed on Opera, in order to accomplish this.

A useful add-on: User-Agent-Switcher

Apple Safari

Setting the user agent globally involves going in the menu bar and selecting Develop > User Agent, then choosing the desired user agent. If the desired user agent is not listed, you can choose “other” and specify the user agent string.

To enable Develop menu tab go to Preferences > Advanced > Enable Develop menu in bar.

Setting useragent string to the desired user agent string and restarting Safari is the whole process of changing the user agent.

Suckless Surf

As all suckless utilities, surf has command line arguments for all its parameters. The one corresponding to the user agent is -u . If you need a randomized user agent on each instance of Surf, you can use the environment variable SURF_USERAGENT. Surf uses this environment variable if the -u is not specified.

Additional advice

Usually, if the browser executable is being called from the command line. You can specify the user agent using your browser executable specific option for user agent.

Example:

user@hostname: surf -u "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.1 Safari/605.1.15"

Example:

C:\Program Files\Opera\launcher.exe --user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36"

In addition you can write a simple script/program to randomize user agents from a given list inside a file. However, most of the add-ons i have listed support this randomization capability, therefore you can either do it for fun or write something even better than what the add-ons provide. 😃

Conclusion

Changing the browser user agent is not an universal remedy for online privacy protection. Yet, it is one simple step that can be accomplished without the need for specialized knowledge on the users side.

--

--

Teo Parashkevov
The Code Vault

Computer (Science) Engineer | C / Python programmer | .NET developer | ML Engineer LinkedIn: https://www.linkedin.com/in/teo-parashkevov/