Skip to content

Commit 68f8513

Browse files
feat: Block Lighthouse cryptic user agent
Believe it or not, this is Lighthouse's user agent. They don't usually include "lighthouse" in it anymore because some people were gaming the system for LH scores, so they use some cryptic UAs now. I'll just ignore this outright because not many people will actually have that UA, and this might cause some big bills for some customers.
1 parent b6a1dbb commit 68f8513

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/__tests__/utils.test.ts

+6
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ describe('utils', () => {
165165
'Mozilla/5.0 (compatible; SeznamBot/4.0; +https://o-seznam.cz/napoveda/vyhledavani/en/seznambot-crawler/)',
166166
],
167167
['BrightEdge Crawler/1.0 ([email protected])'],
168+
[
169+
'Mozilla/5.0 (Linux; Android 11; moto g power (2022)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Mobile Safari/537.36',
170+
],
171+
[
172+
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36',
173+
],
168174
])('blocks based on user agent', (botString) => {
169175
expect(isBlockedUA(botString, [])).toBe(true)
170176
expect(isBlockedUA(botString.toLowerCase(), [])).toBe(true)

src/utils/blocked-uas.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export const DEFAULT_BLOCKED_UA_STRS = [
1717
'bot.php',
1818
'(bot;',
1919
'bot/',
20-
'chrome-lighthouse',
2120
'crawler',
2221
'dataforseobot',
2322
'deepscan',
@@ -80,6 +79,13 @@ export const DEFAULT_BLOCKED_UA_STRS = [
8079
'mediapartners-google',
8180
'storebot-google',
8281
'bytespider',
82+
83+
// Believe it or not, these are all from Lighthouse
84+
// We'll make them an exhaustive match to decrease false positives
85+
// https://github.com/GoogleChrome/lighthouse/blob/main/core/config/constants.js
86+
'chrome-lighthouse',
87+
'mozilla/5.0 (linux; android 11; moto g power (2022)) applewebkit/537.36 (khtml, like gecko) chrome/119.0.0.0 mobile safari/537.36', // Mobile UA for Lighthouse
88+
'mozilla/5.0 (macintosh; intel mac os x 10_15_7) applewebkit/537.36 (khtml, like gecko) chrome/119.0.0.0 safari/537.36', // Desktop UA for Lighthouse
8389
]
8490

8591
/**

0 commit comments

Comments
 (0)