Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Block Lighthouse cryptic user agent #1779

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ describe('utils', () => {
'Mozilla/5.0 (compatible; SeznamBot/4.0; +https://o-seznam.cz/napoveda/vyhledavani/en/seznambot-crawler/)',
],
['BrightEdge Crawler/1.0 ([email protected])'],
[
'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',
],
[
'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',
],
])('blocks based on user agent', (botString) => {
expect(isBlockedUA(botString, [])).toBe(true)
expect(isBlockedUA(botString.toLowerCase(), [])).toBe(true)
Expand Down
8 changes: 7 additions & 1 deletion src/utils/blocked-uas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export const DEFAULT_BLOCKED_UA_STRS = [
'bot.php',
'(bot;',
'bot/',
'chrome-lighthouse',
'crawler',
'dataforseobot',
'deepscan',
Expand Down Expand Up @@ -80,6 +79,13 @@ export const DEFAULT_BLOCKED_UA_STRS = [
'mediapartners-google',
'storebot-google',
'bytespider',

// Believe it or not, these are all from Lighthouse
// We'll make them an exhaustive match to decrease false positives
// https://github.com/GoogleChrome/lighthouse/blob/main/core/config/constants.js
'chrome-lighthouse',
'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
'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
]

/**
Expand Down