Skip to content

Commit bf4981f

Browse files
authored
chore: 403 reddit detection (#20)
1 parent fb0387b commit bf4981f

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -385,12 +385,13 @@ const detect = ({ headers = {}, html = '', url = '', statusCode } = {}) => {
385385
}
386386

387387
// Reddit: blocked requests are served as HTML challenge pages.
388-
// Strongest signal is the blocked-page copy in HTML.
389-
if (
390-
parseUrl(url).domain === 'reddit.com' &&
391-
hasAnyHtml([/blocked by network security\./i])
392-
) {
393-
return byHtml('reddit')
388+
if (parseUrl(url).domain === 'reddit.com') {
389+
if (statusCode === 403) {
390+
return byStatusCode('reddit')
391+
}
392+
if (hasAnyHtml([/blocked by network security\./i])) {
393+
return byHtml('reddit')
394+
}
394395
}
395396

396397
// LinkedIn: status 999 is LinkedIn's dedicated bot-detection response

test/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,20 @@ test('reddit (blocked html on non-reddit url should not match)', t => {
568568
t.is(result.provider, null)
569569
})
570570

571+
test('reddit (blocked by status code)', t => {
572+
const headers = {
573+
'content-type': 'text/html',
574+
server: 'snooserv',
575+
'cache-control': 'private, no-store'
576+
}
577+
const url =
578+
'https://www.reddit.com/r/digitalnomad/comments/1riz2r5/i_love_mexico_city_but_i_feel_so_unhealthy_here/'
579+
const result = isAntibot({ headers, url, statusCode: 403 })
580+
t.is(result.detected, true)
581+
t.is(result.provider, 'reddit')
582+
t.is(result.detection, 'statusCode')
583+
})
584+
571585
test('reddit (allowed endpoint)', t => {
572586
const headers = {
573587
'content-type': 'application/json; charset=UTF-8',

0 commit comments

Comments
 (0)