Skip to content

Commit

Permalink
adjust proxified images detection condition, #312
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimiry committed Oct 25, 2020
1 parent 0bc0732 commit 30232c2
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions src/electron-main/web-request/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,41 +66,37 @@ export function initWebRequestListenersByAccount(
throw new Error(`Failed to resolve the "web-client" bundle location by "${accountEntryApiUrl}" API entry point value`);
}

const origins = {
webClientEntryUrl: parseUrlOriginWithNullishCheck(webClient.entryUrl),
devTools: parseUrlOriginWithNullishCheck("devtools://devtools"),
} as const;
const allowedOrigins: readonly string[] = [
accountEntryApiUrl,
origins.webClientEntryUrl,
webClient.entryApiUrl,
webClient.entryUrl,
...(
BUILD_ENVIRONMENT === "development"
? [origins.devTools]
? ["devtools://devtools"]
: []
),
];
].map(parseUrlOriginWithNullishCheck);

// according to electron docs "only the last attached listener will be used", so no need to unsubscribe previously registered handlers
// according to electron docs "only the last attached listener will be used" so no need to unsubscribe previously registered handlers
session.webRequest.onBeforeRequest(
{urls: []},
(details, callback) => {
const {url} = details;
const urlOrigin = parseUrlOriginWithNullishCheck(url);

if (
enableExternalContentProxy // feature enabled
&&
!requestProxyCache.get(details)?.additionAllowedOrigin // has not yet been proxified (preventing infinity redirect loop)
// feature enabled
enableExternalContentProxy
&&
urlOrigin !== origins.webClientEntryUrl // not proton's static resource
// has not yet been proxified (preventing infinity redirect loop)
!requestProxyCache.get(details)?.additionAllowedOrigin
&&
String(details.resourceType).toLowerCase() === "image" // only image resources
&&
(
BUILD_ENVIRONMENT !== "development"
||
urlOrigin !== origins.devTools // not devtools-specific resource
// resources served from "allowed origins" should not be proxified as those
// are not external (proton's static resource & API, devtools, etc)
!allowedOrigins.includes(
parseUrlOriginWithNullishCheck(url),
)
&&
// only image resources
String(details.resourceType).toLowerCase() === "image"
) {
if (!externalContentProxyUrlPattern) {
throw new Error(`Invalid "external content proxy URL pattern" value.`);
Expand Down

0 comments on commit 30232c2

Please sign in to comment.