From 602931bf7fdb8a960a0758d98212f112cab12d34 Mon Sep 17 00:00:00 2001 From: nai-degen Date: Fri, 23 Jun 2023 00:08:09 -0500 Subject: [PATCH] removes origin/referer headers from proxied request --- src/proxy/anthropic.ts | 2 ++ src/proxy/middleware/request/index.ts | 1 + src/proxy/middleware/request/remove-origin.ts | 10 ++++++++++ src/proxy/openai.ts | 2 ++ 4 files changed, 15 insertions(+) create mode 100644 src/proxy/middleware/request/remove-origin.ts diff --git a/src/proxy/anthropic.ts b/src/proxy/anthropic.ts index b94eab7..a99108d 100644 --- a/src/proxy/anthropic.ts +++ b/src/proxy/anthropic.ts @@ -14,6 +14,7 @@ import { finalizeBody, languageFilter, limitOutputTokens, + removeOrigin, } from "./middleware/request"; import { ProxyResHandlerWithBody, @@ -75,6 +76,7 @@ const rewriteAnthropicRequest = ( blockZoomers, languageFilter, limitOutputTokens, + removeOrigin, finalizeBody, ]; diff --git a/src/proxy/middleware/request/index.ts b/src/proxy/middleware/request/index.ts index d27e356..42d1daa 100644 --- a/src/proxy/middleware/request/index.ts +++ b/src/proxy/middleware/request/index.ts @@ -15,6 +15,7 @@ export { finalizeBody } from "./finalize-body"; export { languageFilter } from "./language-filter"; export { limitCompletions } from "./limit-completions"; export { limitOutputTokens } from "./limit-output-tokens"; +export { removeOrigin } from "./remove-origin"; export { transformKoboldPayload } from "./transform-kobold-payload"; /** diff --git a/src/proxy/middleware/request/remove-origin.ts b/src/proxy/middleware/request/remove-origin.ts new file mode 100644 index 0000000..75bbc25 --- /dev/null +++ b/src/proxy/middleware/request/remove-origin.ts @@ -0,0 +1,10 @@ +import { ProxyRequestMiddleware } from "."; + +/** + * Removes origin and referer headers before sending the request to the API for + * privacy reasons. + **/ +export const removeOrigin: ProxyRequestMiddleware = (proxyReq) => { + proxyReq.setHeader("origin", ""); + proxyReq.setHeader("referer", ""); +}; diff --git a/src/proxy/openai.ts b/src/proxy/openai.ts index c68330e..8ceeb5f 100644 --- a/src/proxy/openai.ts +++ b/src/proxy/openai.ts @@ -15,6 +15,7 @@ import { languageFilter, limitCompletions, limitOutputTokens, + removeOrigin, } from "./middleware/request"; import { createOnProxyResHandler, @@ -95,6 +96,7 @@ const rewriteRequest = ( languageFilter, limitOutputTokens, limitCompletions, + removeOrigin, finalizeBody, ];