Skip to content

Commit 5b8adfe

Browse files
committedMar 31, 2023
Backport - Prevent altering the result when supplied user-agent is different from current user-agent
Reference: Commit: b098789
1 parent 2e06a34 commit 5b8adfe

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed
 

‎src/ua-parser.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,7 @@
803803
var _ua = ua || ((_navigator && _navigator.userAgent) ? _navigator.userAgent : EMPTY);
804804
var _uach = (_navigator && _navigator.userAgentData) ? _navigator.userAgentData : undefined;
805805
var _rgxmap = extensions ? extend(regexes, extensions) : regexes;
806+
var _isSelfNav = _navigator && _navigator.userAgent == _ua;
806807

807808
this.getBrowser = function () {
808809
var _browser = {};
@@ -811,7 +812,7 @@
811812
rgxMapper.call(_browser, _ua, _rgxmap.browser);
812813
_browser[MAJOR] = majorize(_browser[VERSION]);
813814
// Brave-specific detection
814-
if (_navigator && _navigator.brave && typeof _navigator.brave.isBrave == FUNC_TYPE) {
815+
if (_isSelfNav && _navigator && _navigator.brave && typeof _navigator.brave.isBrave == FUNC_TYPE) {
815816
_browser[NAME] = 'Brave';
816817
}
817818
return _browser;
@@ -828,11 +829,11 @@
828829
_device[MODEL] = undefined;
829830
_device[TYPE] = undefined;
830831
rgxMapper.call(_device, _ua, _rgxmap.device);
831-
if (!_device[TYPE] && _uach && _uach.mobile) {
832+
if (_isSelfNav && !_device[TYPE] && _uach && _uach.mobile) {
832833
_device[TYPE] = MOBILE;
833834
}
834835
// iPadOS-specific detection: identified as Mac, but has some iOS-only properties
835-
if (_device[MODEL] == 'Macintosh' && _navigator && typeof _navigator.standalone !== UNDEF_TYPE && _navigator.maxTouchPoints && _navigator.maxTouchPoints > 2) {
836+
if (_isSelfNav && _device[MODEL] == 'Macintosh' && _navigator && typeof _navigator.standalone !== UNDEF_TYPE && _navigator.maxTouchPoints && _navigator.maxTouchPoints > 2) {
836837
_device[MODEL] = 'iPad';
837838
_device[TYPE] = TABLET;
838839
}
@@ -850,7 +851,7 @@
850851
_os[NAME] = undefined;
851852
_os[VERSION] = undefined;
852853
rgxMapper.call(_os, _ua, _rgxmap.os);
853-
if (!_os[NAME] && _uach && _uach.platform != 'Unknown') {
854+
if (_isSelfNav && !_os[NAME] && _uach && _uach.platform != 'Unknown') {
854855
_os[NAME] = _uach.platform
855856
.replace(/chrome os/i, CHROMIUM_OS)
856857
.replace(/macos/i, MAC_OS); // backward compatibility

0 commit comments

Comments
 (0)