From 8d6d7dc6d84e0be6fa826dffeb6d21bfacea25c2 Mon Sep 17 00:00:00 2001 From: Xymorot Date: Sun, 24 Jan 2021 18:43:01 +0100 Subject: [PATCH] fix: tune the cloudflare logic to work with hcaptcha, remove timeout for the test possibly needing to solve a captcha --- src/main/modules/cloudflare/cloudflare-util.ts | 13 ++++++++++--- src/main/modules/nhentai/nhentai-app-window.spec.ts | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/modules/cloudflare/cloudflare-util.ts b/src/main/modules/cloudflare/cloudflare-util.ts index 682c33a..ca56cc9 100644 --- a/src/main/modules/cloudflare/cloudflare-util.ts +++ b/src/main/modules/cloudflare/cloudflare-util.ts @@ -1,9 +1,16 @@ import type { WebContents } from 'electron'; import ContentSecurityPolicy = Session.ContentSecurityPolicy; +/** + * @see https://docs.hcaptcha.com/#content-security-policy-settings + */ export const cloudflareSiteCsp: ContentSecurityPolicy = { - 'style-src': ['cdnjs.cloudflare.com'], - 'script-src': ['hcaptcha.com'], + 'style-src': ['cdnjs.cloudflare.com', 'https://hcaptcha.com', 'https://*.hcaptcha.com'], + 'script-src': ['https://hcaptcha.com', 'https://*.hcaptcha.com'], + 'script-src-elem': ['https://hcaptcha.com', 'https://*.hcaptcha.com'], + 'frame-src': ['https://hcaptcha.com', 'https://*.hcaptcha.com'], + 'connect-src': ['https://hcaptcha.com', 'https://*.hcaptcha.com'], + 'img-src': ['https://hcaptcha.com', 'https://*.hcaptcha.com'], }; export function humanInteractionRequired(webContents: WebContents): Promise { @@ -14,6 +21,6 @@ export function humanInteractionRequired(webContents: WebContents): Promise { return webContents.executeJavaScript( - "!!document.querySelector('.cf-browser-verification, #cf-content')" + "!!document.querySelector('.cf-browser-verification, #cf-content, #cf-wrapper') || !!window._cf_translation" ) as Promise; } diff --git a/src/main/modules/nhentai/nhentai-app-window.spec.ts b/src/main/modules/nhentai/nhentai-app-window.spec.ts index 98edf38..7346f36 100644 --- a/src/main/modules/nhentai/nhentai-app-window.spec.ts +++ b/src/main/modules/nhentai/nhentai-app-window.spec.ts @@ -61,5 +61,5 @@ describe('Nhentai App Window', () => { }; gallery = await nhentaiAppWindow.getGallery('273405'); expect(gallery).deep.equalInAnyOrder(expectedGallery, 'The Archdemon in Love is not got correctly!'); - }).timeout(5000); + }).timeout(0); });