feat(lookup): add protection against infinite recursion for Cloudflare (#1505)

Fixes #1459
Fixes #1490
This commit is contained in:
neatchee
2020-12-23 22:23:43 -08:00
committed by GitHub
parent 28d1cf90b8
commit 1cf618c1c1
2 changed files with 35 additions and 11 deletions
+15
View File
@@ -212,6 +212,21 @@ export const Print = {
}
return `${buildProductString(link, store)} :: RATE LIMIT EXCEEDED`;
},
recursionLimit(link: Link, store: Store, color?: boolean): string {
if (color) {
return (
'✖ ' +
buildProductString(link, store, true) +
' :: ' +
chalk.yellow('CLOUDFLARE RETRY LIMIT REACHED, ABORT')
);
}
return `${buildProductString(
link,
store
)} :: CLOUDFLARE RETRY LIMIT REACHED, ABORT`;
}
};
+20 -11
View File
@@ -328,7 +328,8 @@ async function handleResponse(
store: Store,
page: Page,
link: Link,
response?: Response | null
response?: Response | null,
recursionDepth = 0
) {
if (!response) {
logger.debug(Print.noResponse(link, store, true));
@@ -341,16 +342,24 @@ async function handleResponse(
logger.warn(Print.rateLimit(link, store, true));
} else if (statusCode === 503) {
if (await checkIsCloudflare(store, page, link)) {
const response: Response | null = await page.waitForNavigation({
waitUntil: 'networkidle0'
});
statusCode = await handleResponse(
browser,
store,
page,
link,
response
);
if (recursionDepth > 4) {
logger.warn(Print.recursionLimit(link, store, true));
} else {
const response: Response | null = await page.waitForNavigation(
{
waitUntil: 'networkidle0'
}
);
recursionDepth++;
statusCode = await handleResponse(
browser,
store,
page,
link,
response,
recursionDepth
);
}
} else {
logger.warn(Print.badStatusCode(link, store, statusCode, true));
}