mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
fix(core): Apply correct hostname to redirected requests (#8674)
This commit is contained in:
@@ -252,6 +252,24 @@ const getHostFromRequestObject = (
|
||||
}
|
||||
};
|
||||
|
||||
const getBeforeRedirectFn =
|
||||
(agentOptions: AgentOptions, axiosConfig: AxiosRequestConfig) =>
|
||||
(redirectedRequest: Record<string, any>) => {
|
||||
const redirectAgent = new Agent({
|
||||
...agentOptions,
|
||||
servername: redirectedRequest.hostname,
|
||||
});
|
||||
redirectedRequest.agent = redirectAgent;
|
||||
redirectedRequest.agents.https = redirectAgent;
|
||||
|
||||
if (axiosConfig.headers?.Authorization) {
|
||||
redirectedRequest.headers.Authorization = axiosConfig.headers.Authorization;
|
||||
}
|
||||
if (axiosConfig.auth) {
|
||||
redirectedRequest.auth = `${axiosConfig.auth.username}:${axiosConfig.auth.password}`;
|
||||
}
|
||||
};
|
||||
|
||||
export async function parseRequestObject(requestObject: IRequestOptions) {
|
||||
// This function is a temporary implementation
|
||||
// That translates all http requests done via
|
||||
@@ -475,22 +493,6 @@ export async function parseRequestObject(requestObject: IRequestOptions) {
|
||||
axiosConfig.maxRedirects = 0;
|
||||
}
|
||||
|
||||
axiosConfig.beforeRedirect = (redirectedRequest) => {
|
||||
if (axiosConfig.headers?.Authorization) {
|
||||
redirectedRequest.headers.Authorization = axiosConfig.headers.Authorization;
|
||||
}
|
||||
if (axiosConfig.auth) {
|
||||
redirectedRequest.auth = `${axiosConfig.auth.username}:${axiosConfig.auth.password}`;
|
||||
}
|
||||
};
|
||||
|
||||
if (requestObject.rejectUnauthorized === false) {
|
||||
axiosConfig.httpsAgent = new Agent({
|
||||
rejectUnauthorized: false,
|
||||
secureOptions: crypto.constants.SSL_OP_LEGACY_SERVER_CONNECT,
|
||||
});
|
||||
}
|
||||
|
||||
const host = getHostFromRequestObject(requestObject);
|
||||
const agentOptions: AgentOptions = {};
|
||||
if (host) {
|
||||
@@ -502,6 +504,8 @@ export async function parseRequestObject(requestObject: IRequestOptions) {
|
||||
}
|
||||
axiosConfig.httpsAgent = new Agent(agentOptions);
|
||||
|
||||
axiosConfig.beforeRedirect = getBeforeRedirectFn(agentOptions, axiosConfig);
|
||||
|
||||
if (requestObject.timeout !== undefined) {
|
||||
axiosConfig.timeout = requestObject.timeout;
|
||||
}
|
||||
@@ -894,6 +898,8 @@ function convertN8nRequestToAxios(n8nRequest: IHttpRequestOptions): AxiosRequest
|
||||
}
|
||||
axiosRequest.httpsAgent = new Agent(agentOptions);
|
||||
|
||||
axiosRequest.beforeRedirect = getBeforeRedirectFn(agentOptions, axiosRequest);
|
||||
|
||||
if (n8nRequest.arrayFormat !== undefined) {
|
||||
axiosRequest.paramsSerializer = (params) => {
|
||||
return stringify(params, { arrayFormat: n8nRequest.arrayFormat });
|
||||
|
||||
Reference in New Issue
Block a user