diff --git a/packages/safe-chain/src/registryProxy/mitmRequestHandler.js b/packages/safe-chain/src/registryProxy/mitmRequestHandler.js index 6a72879..750815e 100644 --- a/packages/safe-chain/src/registryProxy/mitmRequestHandler.js +++ b/packages/safe-chain/src/registryProxy/mitmRequestHandler.js @@ -17,7 +17,8 @@ function createHttpsServer(hostname, isAllowed) { const cert = generateCertForHost(hostname); async function handleRequest(req, res) { - const targetUrl = `https://${hostname}${req.url}`; + const pathAndQuery = getRequestPathAndQuery(req.url); + const targetUrl = `https://${hostname}${pathAndQuery}`; if (!(await isAllowed(targetUrl))) { res.writeHead(403, "Forbidden - blocked by safe-chain"); @@ -38,6 +39,14 @@ function createHttpsServer(hostname, isAllowed) { ); } +function getRequestPathAndQuery(url) { + if (url.startsWith("http://") || url.startsWith("https://")) { + const parsedUrl = new URL(url); + return parsedUrl.pathname + parsedUrl.search + parsedUrl.hash; + } + return url; +} + function forwardRequest(req, hostname, res) { const proxyReq = createProxyRequest(hostname, req, res);