Skip to content

Commit

Permalink
fix: block bytespider bot (#1113)
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra authored Apr 3, 2024
1 parent 7c7dfde commit 5a3e62d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ describe('utils', () => {
],
['AhrefsSiteAudit (Desktop) - Mozilla/5.0 (compatible; AhrefsSiteAudit/6.1; +http://ahrefs.com/robot/)'],
['Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; GPTBot/1.0; +https://openai.com/gptbot)'],
[
'Mozilla/5.0 (Linux; Android 5.0) AppleWebKit/537.36 (KHTML, like Gecko) Mobile Safari/537.36 (compatible; Bytespider; [email protected])',
],
])('blocks based on user agent', (botString) => {
expect(_isBlockedUA(botString, [])).toBe(true)
expect(_isBlockedUA(botString.toLowerCase(), [])).toBe(true)
Expand Down
10 changes: 4 additions & 6 deletions src/utils/blocked-uas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const DEFAULT_BLOCKED_UA_STRS = [
'googleweblight',
'mediapartners-google',
'storebot-google',
'Bytespider;',
]

/**
Expand All @@ -58,11 +59,8 @@ export const _isBlockedUA = function (ua: string, customBlockedUserAgents: strin
const uaLower = ua.toLowerCase()
return DEFAULT_BLOCKED_UA_STRS.concat(customBlockedUserAgents || []).some((blockedUA) => {
const blockedUaLower = blockedUA.toLowerCase()
if (uaLower.includes) {
return uaLower.includes(blockedUaLower)
} else {
// IE 11 :/
return uaLower.indexOf(blockedUaLower) !== -1
}

// can't use includes because IE 11 :/
return uaLower.indexOf(blockedUaLower) !== -1
})
}

0 comments on commit 5a3e62d

Please sign in to comment.