From e71b8d436f77a37eed996c208ae7ccd8df5e0e7f Mon Sep 17 00:00:00 2001 From: Olivier Sambourg Date: Tue, 15 Oct 2024 10:51:39 +0200 Subject: [PATCH] feat(http): add configurable deny-list of headers --- packages/pieces/community/http/src/index.ts | 5 +++++ .../src/lib/actions/send-http-request-action.ts | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/pieces/community/http/src/index.ts b/packages/pieces/community/http/src/index.ts index 3b6ccb4ad6..40115c153f 100644 --- a/packages/pieces/community/http/src/index.ts +++ b/packages/pieces/community/http/src/index.ts @@ -24,3 +24,8 @@ export const http = createPiece({ ], triggers: [], }); + + +export type HttpPieceConfig = { + deniedHeaders?: string[] +} diff --git a/packages/pieces/community/http/src/lib/actions/send-http-request-action.ts b/packages/pieces/community/http/src/lib/actions/send-http-request-action.ts index b42b6cb4e5..ff352314e7 100644 --- a/packages/pieces/community/http/src/lib/actions/send-http-request-action.ts +++ b/packages/pieces/community/http/src/lib/actions/send-http-request-action.ts @@ -15,6 +15,7 @@ import FormData from 'form-data'; import { httpMethodDropdown } from '../common/props'; import { HttpsProxyAgent } from 'https-proxy-agent'; import axios from 'axios'; +import { HttpPieceConfig } from '../../index'; export const httpSendRequestAction = createAction({ name: 'send_request', @@ -163,6 +164,18 @@ export const httpSendRequestAction = createAction({ assertNotNullOrUndefined(method, 'Method'); assertNotNullOrUndefined(url, 'URL'); + const pieceConfig = context.pieceConfig as HttpPieceConfig; + const deniedHeaders = + pieceConfig.deniedHeaders?.map((header) => header.toLowerCase().trim()) || + []; + const blockedHeaders = Object.keys(headers).filter( + (headerName) => deniedHeaders.includes(headerName.toLowerCase().trim()) + ); + + if (blockedHeaders.length > 0) { + throw new Error(`These headers are not allowed: ${blockedHeaders}`); + } + const request: HttpRequest = { method, url, @@ -198,7 +211,7 @@ export const httpSendRequestAction = createAction({ proxyUrl = `http://${proxySettings.proxy_host}:${proxySettings.proxy_port}`; } - const httpsAgent = new HttpsProxyAgent(proxyUrl) + const httpsAgent = new HttpsProxyAgent(proxyUrl); const axiosClient = axios.create({ httpsAgent, });