Prevent altering the result when supplied user-agent is different from current user-agent

This commit is contained in:
Faisal Salman 2023-03-29 22:52:56 +07:00
parent 30de983043
commit b09878934f
5 changed files with 13 additions and 11 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -477,7 +477,7 @@ http.createServer(function (req, res) {
res.setHeader('Accept-CH', getHighEntropyValues); res.setHeader('Accept-CH', getHighEntropyValues);
res.setHeader('Critical-CH', getHighEntropyValues); res.setHeader('Critical-CH', getHighEntropyValues);
var ua = uap(req.headers); var ua = uap(req.headers).withClientHints();
// END since@2.0 */ // END since@2.0 */

View File

@ -932,26 +932,27 @@
['data', createUAParserData(itemType, ua, rgxMap, uaCH)] ['data', createUAParserData(itemType, ua, rgxMap, uaCH)]
]); ]);
this.parse(); this.parse();
var isSelfNav = NAVIGATOR && NAVIGATOR.userAgent == ua;
switch(this.itemType) { switch(this.itemType) {
case UA_BROWSER: case UA_BROWSER:
// Brave-specific detection // Brave-specific detection
if (NAVIGATOR && NAVIGATOR.userAgent == ua && NAVIGATOR.brave && typeof NAVIGATOR.brave.isBrave == FUNC_TYPE) { if (isSelfNav && NAVIGATOR.brave && typeof NAVIGATOR.brave.isBrave == FUNC_TYPE) {
this.set(NAME, 'Brave'); this.set(NAME, 'Brave');
} }
this.set(MAJOR, majorize(this.get(VERSION))); this.set(MAJOR, majorize(this.get(VERSION)));
break; break;
case UA_DEVICE: case UA_DEVICE:
if (!this.get(TYPE) && NAVIGATOR_UADATA && NAVIGATOR_UADATA[MOBILE]) { if (isSelfNav && !this.get(TYPE) && NAVIGATOR_UADATA && NAVIGATOR_UADATA[MOBILE]) {
this.set(TYPE, MOBILE); this.set(TYPE, MOBILE);
} }
// iPadOS-specific detection: identified as Mac, but has some iOS-only properties // iPadOS-specific detection: identified as Mac, but has some iOS-only properties
if (this.get(MODEL) == 'Macintosh' && NAVIGATOR && typeof NAVIGATOR.standalone !== UNDEF_TYPE && NAVIGATOR.maxTouchPoints && NAVIGATOR.maxTouchPoints > 2) { if (isSelfNav && this.get(MODEL) == 'Macintosh' && NAVIGATOR && typeof NAVIGATOR.standalone !== UNDEF_TYPE && NAVIGATOR.maxTouchPoints && NAVIGATOR.maxTouchPoints > 2) {
this.set(MODEL, 'iPad') this.set(MODEL, 'iPad')
.set(TYPE, TABLET); .set(TYPE, TABLET);
} }
break; break;
case UA_OS: case UA_OS:
if (!this.get(NAME) && NAVIGATOR_UADATA && NAVIGATOR_UADATA[PLATFORM] && NAVIGATOR_UADATA[PLATFORM] != 'Unknown') { if (isSelfNav && !this.get(NAME) && NAVIGATOR_UADATA && NAVIGATOR_UADATA[PLATFORM]) {
this.set(NAME, NAVIGATOR_UADATA[PLATFORM]); this.set(NAME, NAVIGATOR_UADATA[PLATFORM]);
} }
break; break;

View File

@ -936,26 +936,27 @@ const window = undefined;
['data', createUAParserData(itemType, ua, rgxMap, uaCH)] ['data', createUAParserData(itemType, ua, rgxMap, uaCH)]
]); ]);
this.parse(); this.parse();
var isSelfNav = NAVIGATOR && NAVIGATOR.userAgent == ua;
switch(this.itemType) { switch(this.itemType) {
case UA_BROWSER: case UA_BROWSER:
// Brave-specific detection // Brave-specific detection
if (NAVIGATOR && NAVIGATOR.userAgent == ua && NAVIGATOR.brave && typeof NAVIGATOR.brave.isBrave == FUNC_TYPE) { if (isSelfNav && NAVIGATOR.brave && typeof NAVIGATOR.brave.isBrave == FUNC_TYPE) {
this.set(NAME, 'Brave'); this.set(NAME, 'Brave');
} }
this.set(MAJOR, majorize(this.get(VERSION))); this.set(MAJOR, majorize(this.get(VERSION)));
break; break;
case UA_DEVICE: case UA_DEVICE:
if (!this.get(TYPE) && NAVIGATOR_UADATA && NAVIGATOR_UADATA[MOBILE]) { if (isSelfNav && !this.get(TYPE) && NAVIGATOR_UADATA && NAVIGATOR_UADATA[MOBILE]) {
this.set(TYPE, MOBILE); this.set(TYPE, MOBILE);
} }
// iPadOS-specific detection: identified as Mac, but has some iOS-only properties // iPadOS-specific detection: identified as Mac, but has some iOS-only properties
if (this.get(MODEL) == 'Macintosh' && NAVIGATOR && typeof NAVIGATOR.standalone !== UNDEF_TYPE && NAVIGATOR.maxTouchPoints && NAVIGATOR.maxTouchPoints > 2) { if (isSelfNav && this.get(MODEL) == 'Macintosh' && NAVIGATOR && typeof NAVIGATOR.standalone !== UNDEF_TYPE && NAVIGATOR.maxTouchPoints && NAVIGATOR.maxTouchPoints > 2) {
this.set(MODEL, 'iPad') this.set(MODEL, 'iPad')
.set(TYPE, TABLET); .set(TYPE, TABLET);
} }
break; break;
case UA_OS: case UA_OS:
if (!this.get(NAME) && NAVIGATOR_UADATA && NAVIGATOR_UADATA[PLATFORM] && NAVIGATOR_UADATA[PLATFORM] != 'Unknown') { if (isSelfNav && !this.get(NAME) && NAVIGATOR_UADATA && NAVIGATOR_UADATA[PLATFORM]) {
this.set(NAME, NAVIGATOR_UADATA[PLATFORM]); this.set(NAME, NAVIGATOR_UADATA[PLATFORM]);
} }
break; break;