mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Fix proxy for npm 10.0.0 -> 10.4.0
This commit is contained in:
parent
3b145a4695
commit
95663dc5f4
1 changed files with 10 additions and 1 deletions
|
|
@ -17,7 +17,8 @@ function createHttpsServer(hostname, isAllowed) {
|
||||||
const cert = generateCertForHost(hostname);
|
const cert = generateCertForHost(hostname);
|
||||||
|
|
||||||
async function handleRequest(req, res) {
|
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))) {
|
if (!(await isAllowed(targetUrl))) {
|
||||||
res.writeHead(403, "Forbidden - blocked by safe-chain");
|
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) {
|
function forwardRequest(req, hostname, res) {
|
||||||
const proxyReq = createProxyRequest(hostname, req, res);
|
const proxyReq = createProxyRequest(hostname, req, res);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue