mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Rename writeVerboseInformation to writeVerbose
This commit is contained in:
parent
c5e25f4813
commit
ddc8218a2d
4 changed files with 10 additions and 12 deletions
|
|
@ -57,7 +57,7 @@ function writeExitWithoutInstallingMaliciousPackages() {
|
||||||
writeOrBuffer(() => console.error(message));
|
writeOrBuffer(() => console.error(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeVerboseInformation(message, ...optionalParams) {
|
function writeVerbose(message, ...optionalParams) {
|
||||||
if (!isVerboseMode()) return;
|
if (!isVerboseMode()) return;
|
||||||
|
|
||||||
writeOrBuffer(() => console.log(message, ...optionalParams));
|
writeOrBuffer(() => console.log(message, ...optionalParams));
|
||||||
|
|
@ -127,8 +127,8 @@ function writeBufferedLogsAndStopBuffering() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ui = {
|
export const ui = {
|
||||||
|
writeVerbose,
|
||||||
writeInformation,
|
writeInformation,
|
||||||
writeVerboseInformation,
|
|
||||||
writeWarning,
|
writeWarning,
|
||||||
writeError,
|
writeError,
|
||||||
writeExitWithoutInstallingMaliciousPackages,
|
writeExitWithoutInstallingMaliciousPackages,
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,11 @@ import { HttpsProxyAgent } from "https-proxy-agent";
|
||||||
import { ui } from "../environment/userInteraction.js";
|
import { ui } from "../environment/userInteraction.js";
|
||||||
|
|
||||||
export function mitmConnect(req, clientSocket, isAllowed) {
|
export function mitmConnect(req, clientSocket, isAllowed) {
|
||||||
ui.writeVerboseInformation(`Safe-chain: Set up MITM tunnel for ${req.url}`);
|
ui.writeVerbose(`Safe-chain: Set up MITM tunnel for ${req.url}`);
|
||||||
const { hostname } = new URL(`http://${req.url}`);
|
const { hostname } = new URL(`http://${req.url}`);
|
||||||
|
|
||||||
clientSocket.on("error", (err) => {
|
clientSocket.on("error", (err) => {
|
||||||
ui.writeVerboseInformation(
|
ui.writeVerbose(
|
||||||
`Safe-chain: Client socket error for ${req.url}: ${err.message}`
|
`Safe-chain: Client socket error for ${req.url}: ${err.message}`
|
||||||
);
|
);
|
||||||
// NO-OP
|
// NO-OP
|
||||||
|
|
@ -33,9 +33,7 @@ function createHttpsServer(hostname, isAllowed) {
|
||||||
const targetUrl = `https://${hostname}${pathAndQuery}`;
|
const targetUrl = `https://${hostname}${pathAndQuery}`;
|
||||||
|
|
||||||
if (!(await isAllowed(targetUrl))) {
|
if (!(await isAllowed(targetUrl))) {
|
||||||
ui.writeVerboseInformation(
|
ui.writeVerbose(`Safe-chain: Blocking request to ${targetUrl}`);
|
||||||
`Safe-chain: Blocking request to ${targetUrl}`
|
|
||||||
);
|
|
||||||
res.writeHead(403, "Forbidden - blocked by safe-chain");
|
res.writeHead(403, "Forbidden - blocked by safe-chain");
|
||||||
res.end("Blocked by safe-chain");
|
res.end("Blocked by safe-chain");
|
||||||
return;
|
return;
|
||||||
|
|
@ -66,7 +64,7 @@ function forwardRequest(req, hostname, res) {
|
||||||
const proxyReq = createProxyRequest(hostname, req, res);
|
const proxyReq = createProxyRequest(hostname, req, res);
|
||||||
|
|
||||||
proxyReq.on("error", (err) => {
|
proxyReq.on("error", (err) => {
|
||||||
ui.writeVerboseInformation(
|
ui.writeVerbose(
|
||||||
`Safe-chain: Error occurred while proxying request: ${err.message}`
|
`Safe-chain: Error occurred while proxying request: ${err.message}`
|
||||||
);
|
);
|
||||||
res.writeHead(502);
|
res.writeHead(502);
|
||||||
|
|
@ -78,7 +76,7 @@ function forwardRequest(req, hostname, res) {
|
||||||
});
|
});
|
||||||
|
|
||||||
req.on("end", () => {
|
req.on("end", () => {
|
||||||
ui.writeVerboseInformation(
|
ui.writeVerbose(
|
||||||
`Safe-chain: Finished proxying request to ${req.url} for ${hostname}`
|
`Safe-chain: Finished proxying request to ${req.url} for ${hostname}`
|
||||||
);
|
);
|
||||||
proxyReq.end();
|
proxyReq.end();
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ function handleConnect(req, clientSocket, head) {
|
||||||
mitmConnect(req, clientSocket, isAllowedUrl);
|
mitmConnect(req, clientSocket, isAllowedUrl);
|
||||||
} else {
|
} else {
|
||||||
// For other hosts, just tunnel the request to the destination tcp socket
|
// For other hosts, just tunnel the request to the destination tcp socket
|
||||||
ui.writeVerboseInformation(`Safe-chain: Tunneling request to ${req.url}`);
|
ui.writeVerbose(`Safe-chain: Tunneling request to ${req.url}`);
|
||||||
tunnelRequest(req, clientSocket, head);
|
tunnelRequest(req, clientSocket, head);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,12 +20,12 @@ export async function auditChanges(changes) {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (malwarePackage) {
|
if (malwarePackage) {
|
||||||
ui.writeVerboseInformation(
|
ui.writeVerbose(
|
||||||
`Safe-chain: Package ${change.name}@${change.version} is marked as malware: ${malwarePackage.status}`
|
`Safe-chain: Package ${change.name}@${change.version} is marked as malware: ${malwarePackage.status}`
|
||||||
);
|
);
|
||||||
disallowedChanges.push({ ...change, reason: malwarePackage.status });
|
disallowedChanges.push({ ...change, reason: malwarePackage.status });
|
||||||
} else {
|
} else {
|
||||||
ui.writeVerboseInformation(
|
ui.writeVerbose(
|
||||||
`Safe-chain: Package ${change.name}@${change.version} is clean`
|
`Safe-chain: Package ${change.name}@${change.version} is clean`
|
||||||
);
|
);
|
||||||
allowedChanges.push(change);
|
allowedChanges.push(change);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue