Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can the Javascript `userAgent` differ from a browser's header request

Is there any plausible circumstance in which the navigator userAgent reported by Javascript could be different from the one sent as User-Agent Header.

Part of the reason I am asking is that: I have an app that collects the User Agent from JS to report back to the server. It's not necessary in most legit cases. However, could they actually differ or lie?

navigator.userAgent being 'read only' makes the change unlikely. I am just wondering if a hacker or an extension could in fact do so, on common browsers or a headless browser, for whatever reason.

like image 694
hexalys Avatar asked Sep 24 '26 01:09

hexalys


1 Answers

yes, in case of incomplete user-agent spoofing.

browser addons like

  • Custom UserAgent String
  • UAControl [outdated]
  • ua-site-switch [outdated]

will only change user-agent in http-header, but not in javascript variables

  • navigator.userAgent
  • navigator.appCodeName
  • navigator.appName
  • navigator.appVersion
  • navigator.platform
  • navigator.vendor
  • navigator.vendorSub

for a [more] complete user-agent spoofing, also change the javascript variables:

  • User-Agent JS Fixer [outdated]
  • user script for greasemonkey:
// ==UserScript==
// @name        Change navigator.userAgent
// @namespace   Rob W
// @description Changes navigator.userAgent to IE on IEGallery.com
// @match       http://www.iegallery.com/*
// @run-at      document-start
// @grant       none
// @version     1
// ==/UserScript==

Object.defineProperty(navigator, 'userAgent', {
    value: 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)'
});

test pages:

  • show javascript user agent variables
  • show client http headers
like image 172
Mila Nautikus Avatar answered Sep 25 '26 16:09

Mila Nautikus