From c21eccc57e7852ec3fcbeb3a4438cd32f58b1a63 Mon Sep 17 00:00:00 2001 From: Slava Leleka Date: Wed, 10 May 2023 20:37:37 +0300 Subject: [PATCH] improve responseType checking condition --- src/scriptlets/prevent-fetch.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/scriptlets/prevent-fetch.js b/src/scriptlets/prevent-fetch.js index d00873c6..b9f2277f 100644 --- a/src/scriptlets/prevent-fetch.js +++ b/src/scriptlets/prevent-fetch.js @@ -116,10 +116,18 @@ export function preventFetch(source, propsToMatch, responseBody = 'emptyObj', re return; } + const isResponseTypeSpecified = typeof responseType !== 'undefined'; + const isResponseTypeSupported = (responseType) => { + const SUPPORTED_TYPES = [ + 'default', + 'opaque', + ]; + return SUPPORTED_TYPES.includes(responseType); + }; // Skip disallowed response types, // specified responseType has limited list of possible values - if (typeof responseType !== 'undefined' - && !(responseType === 'default' || responseType === 'opaque')) { + if (isResponseTypeSpecified + && !isResponseTypeSupported(responseType)) { logMessage(source, `Invalid responseType parameter: '${responseType}'`); return; }