Skip to content

Commit

Permalink
Revert "#1208 [RQ-1145] Relay auth header to redirected request (#1253)"
Browse files Browse the repository at this point in the history
This reverts commit 3516bb5.
  • Loading branch information
wrongsahil committed Dec 12, 2023
1 parent 47543d5 commit 671d0b7
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import LINKS from "config/constants/sub/links";
import { trackDesktopAppPromoClicked } from "modules/analytics/events/common/onboarding";
import "./ruleInfoBanner.css";
import { trackMoreInfoClicked } from "modules/analytics/events/misc/moreInfo";
import { isFeatureCompatible } from "utils/CompatibilityUtils";
import FEATURES from "config/constants/sub/features";

const RuleInfoBanner: React.FC<{ ruleType: string; appMode: string }> = ({ ruleType, appMode }) => {
const ruleInfoBannerContent: Record<
Expand Down Expand Up @@ -87,13 +85,6 @@ const RuleInfoBanner: React.FC<{ ruleType: string; appMode: string }> = ({ ruleT
if (ruleInfoBannerContent[ruleType]?.appMode && !ruleInfoBannerContent[ruleType]?.appMode?.includes(appMode))
return null;

// Specific case - remove these banners after 1 more release than compatible version
if (
[GLOBAL_CONSTANTS.RULE_TYPES.REDIRECT, GLOBAL_CONSTANTS.RULE_TYPES.REPLACE].includes(ruleType) &&
isFeatureCompatible(FEATURES.RELAY_AUTH_HEADER)
)
return null;

return (
<Row className="rule-info-banner-container">
<Col span={24}>
Expand Down
4 changes: 0 additions & 4 deletions app/src/config/constants/compatibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,4 @@ export const FEATURE_COMPATIBLE_VERSION = {
[GLOBAL_CONSTANTS.APP_MODES.DESKTOP]: "1.5.12",
[GLOBAL_CONSTANTS.APP_MODES.EXTENSION]: null,
},
[FEATURES.RELAY_AUTH_HEADER]: {
[GLOBAL_CONSTANTS.APP_MODES.DESKTOP]: null,
[GLOBAL_CONSTANTS.APP_MODES.EXTENSION]: "23.12.6",
},
};
1 change: 0 additions & 1 deletion app/src/config/constants/sub/features.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ FEATURES.CREATE_RULE_FROM_TRAFFIC_TABLE = "create-rule-from-traffic-table";
FEATURES.CONNECTED_APPS = "connected-apps";
FEATURES.GRAPHQL_PAYLOAD_FILTER_OPERATOR = "graphql-payload-filter-operator";
FEATURES.CUSTOM_LAUNCH_OPTIONS = "custom-launch-options";
FEATURES.RELAY_AUTH_HEADER = "relay-auth-header";

// MARKETING
FEATURES.INTERCEPTOR = {};
Expand Down
27 changes: 3 additions & 24 deletions browser-extension/mv2/src/background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,6 @@ BG.Methods.replaceHeader = function (headers, newHeader) {
BG.Methods.addHeader(headers, newHeader);
};

BG.Methods.getHeaderValue = (headers, headerName) => {
const header = headers.find(({ name }) => name.toLowerCase() === headerName.toLowerCase());
return header?.value;
};

/**
*
* @param originalHeaders Original Headers present in the HTTP(s) request
Expand All @@ -269,29 +264,13 @@ BG.Methods.modifyHeaders = function (originalHeaders, headersTarget, details) {
ruleType,
rulePairs,
rulePair,
hasModifiedHeaders = false,
isRuleApplied = false,
modifications,
modification,
url = details.url,
mainFrameUrl = BG.Methods.getMainFrameUrl(details),
enabledRules = BG.Methods.getEnabledRules();

if (headersTarget === RQ.HEADERS_TARGET.REQUEST) {
RQ.IGNORED_HEADERS_ON_REDIRECT.forEach((headerName) => {
const customHeaderName = RQ.CUSTOM_HEADER_PREFIX + headerName;
const customHeaderValue = BG.Methods.getHeaderValue(originalHeaders, customHeaderName);
const originalHeaderValue = BG.Methods.getHeaderValue(originalHeaders, headerName);

if (customHeaderValue) {
if (!originalHeaderValue) {
BG.Methods.addHeader(originalHeaders, { name: headerName, value: customHeaderValue });
}
BG.Methods.removeHeader(originalHeaders, customHeaderName);
hasModifiedHeaders = true;
}
});
}

for (var i = 0; i < enabledRules.length; i++) {
rule = enabledRules[i];
ruleType = rule.ruleType;
Expand Down Expand Up @@ -345,7 +324,7 @@ BG.Methods.modifyHeaders = function (originalHeaders, headersTarget, details) {
continue;
}

hasModifiedHeaders = true;
isRuleApplied = true;

// Check if user has used predefinedFunction in (add/modify) header value
var valueWithPreDefFunctionsApplied = RuleMatcher.matchValueForPredefinedFunctions(modification.value, details);
Expand Down Expand Up @@ -390,7 +369,7 @@ BG.Methods.modifyHeaders = function (originalHeaders, headersTarget, details) {

// If rule is not applied and we return headers object without any change, then chrome treats them as modification
// And some websites break due to this.
return hasModifiedHeaders ? originalHeaders : null;
return isRuleApplied ? originalHeaders : null;
};

BG.Methods.getMainFrameUrl = function (details) {
Expand Down
33 changes: 5 additions & 28 deletions browser-extension/mv2/src/client/js/requestResponseRuleHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ RQ.RequestResponseRuleHandler.setup = () => {
return [RQ.RULE_TYPES.REQUEST, RQ.RULE_TYPES.RESPONSE].includes(rule.ruleType);
});

const doRedirectRulesExist = rules.some((rule) => {
return [RQ.RULE_TYPES.REDIRECT, RQ.RULE_TYPES.REPLACE].includes(rule.ruleType);
});

if (doRequestResponseRulesExist || doRedirectRulesExist) {
if (doRequestResponseRulesExist) {
RQ.RequestResponseRuleHandler.init();
}
});
Expand Down Expand Up @@ -70,13 +66,7 @@ RQ.RequestResponseRuleHandler.init = function () {
}
});

const clientArgs = {
namespace: RQ.PUBLIC_NAMESPACE,
customHeaderPrefix: RQ.CUSTOM_HEADER_PREFIX,
ignoredHeadersOnRedirect: RQ.IGNORED_HEADERS_ON_REDIRECT,
};

RQ.ClientUtils.executeJS(`(${this.interceptAJAXRequests.toString()})(${JSON.stringify(clientArgs)})`);
RQ.ClientUtils.executeJS(`(${this.interceptAJAXRequests.toString()})('${RQ.PUBLIC_NAMESPACE}')`);

RQ.RequestResponseRuleHandler.isInitialized = true;
};
Expand Down Expand Up @@ -109,15 +99,12 @@ RQ.RequestResponseRuleHandler.updateRulesCache = async () => {
};

/**
* @param {*} namespace __REQUESTLY__
* Do not refer other function/variables from this function.
* This function will be injected in website and will run in different JS context.
*/

RQ.RequestResponseRuleHandler.interceptAJAXRequests = function ({
namespace,
customHeaderPrefix = "",
ignoredHeadersOnRedirect = [],
}) {
RQ.RequestResponseRuleHandler.interceptAJAXRequests = function (namespace) {
window[namespace] = window[namespace] || {};
window[namespace].requestRules = [];
window[namespace].responseRules = [];
Expand Down Expand Up @@ -529,16 +516,6 @@ RQ.RequestResponseRuleHandler.interceptAJAXRequests = function ({
request = new Request(resource.toString(), initOptions);
}

let hasModifiedHeaders = false;

ignoredHeadersOnRedirect.forEach((header) => {
const originalHeaderValue = request.headers.get(header);
if (originalHeaderValue) {
hasModifiedHeaders = true;
request.headers.set(customHeaderPrefix + header, originalHeaderValue);
}
});

const url = getAbsoluteUrl(request.url);
const method = request.method;
// Request body can be sent only for request methods other than GET and HEAD.
Expand Down Expand Up @@ -593,7 +570,7 @@ RQ.RequestResponseRuleHandler.interceptAJAXRequests = function ({
responseHeaders = new Headers({ "content-type": contentType });
} else {
try {
if (requestRule || hasModifiedHeaders) {
if (requestRule) {
// use modified request to fetch response
fetchedResponse = await _fetch(request);
} else {
Expand Down
7 changes: 0 additions & 7 deletions browser-extension/mv2/src/shared/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,3 @@ RQ.CLIENT_MESSAGES = {
NOTIFY_RECORD_UPDATED_IN_POPUP: "notifyRecordUpdatedInPopup",
START_RULE_TESTING: "startRuleTesting",
};

RQ.CUSTOM_HEADER_PREFIX = "x-rq-";

/*
List of headers ignored by the browser on URL redirection
*/
RQ.IGNORED_HEADERS_ON_REDIRECT = ["Authorization"];

0 comments on commit 671d0b7

Please sign in to comment.