@aikidosec/safe-chain 1.4.9 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -5
- package/bin/aikido-uvx.js +16 -0
- package/bin/safe-chain.js +18 -1
- package/docs/Release.md +25 -0
- package/docs/shell-integration.md +4 -4
- package/npm-shrinkwrap.json +54 -943
- package/package.json +3 -4
- package/src/config/configFile.js +2 -2
- package/src/config/safeChainDir.js +71 -0
- package/src/installLocation.js +42 -0
- package/src/packagemanager/currentPackageManager.js +3 -0
- package/src/packagemanager/uvx/createUvxPackageManager.js +18 -0
- package/src/registryProxy/certUtils.js +3 -3
- package/src/registryProxy/interceptors/pip/modifyPipInfo.js +17 -0
- package/src/registryProxy/interceptors/pip/pipInterceptor.js +2 -0
- package/src/shell-integration/helpers.js +6 -14
- package/src/shell-integration/path-wrappers/templates/unix-wrapper.template.sh +16 -1
- package/src/shell-integration/path-wrappers/templates/windows-wrapper.template.cmd +3 -2
- package/src/shell-integration/setup-ci.js +9 -29
- package/src/shell-integration/setup.js +3 -22
- package/src/shell-integration/startup-scripts/init-fish.fish +8 -1
- package/src/shell-integration/startup-scripts/init-posix.sh +17 -1
- package/src/shell-integration/startup-scripts/init-pwsh.ps1 +6 -1
- package/src/shell-integration/supported-shells/bash.js +75 -5
- package/src/shell-integration/supported-shells/fish.js +7 -5
- package/src/shell-integration/supported-shells/powershell.js +7 -5
- package/src/shell-integration/supported-shells/windowsPowershell.js +7 -5
- package/src/shell-integration/supported-shells/zsh.js +7 -5
- package/src/shell-integration/teardown.js +3 -1
- package/src/ultimate/ultimateTroubleshooting.js +0 -111
|
@@ -3,7 +3,9 @@ import {
|
|
|
3
3
|
doesExecutableExistOnSystem,
|
|
4
4
|
removeLinesMatchingPattern,
|
|
5
5
|
} from "../helpers.js";
|
|
6
|
+
import { getScriptsDir } from "../../config/safeChainDir.js";
|
|
6
7
|
import { execSync } from "child_process";
|
|
8
|
+
import path from "path";
|
|
7
9
|
|
|
8
10
|
const shellName = "Fish";
|
|
9
11
|
const executableName = "fish";
|
|
@@ -31,10 +33,10 @@ function teardown(tools) {
|
|
|
31
33
|
);
|
|
32
34
|
}
|
|
33
35
|
|
|
34
|
-
//
|
|
36
|
+
// Remove sourcing line to prevent safe-chain initialization in future shell sessions
|
|
35
37
|
removeLinesMatchingPattern(
|
|
36
38
|
startupFile,
|
|
37
|
-
/^source\s
|
|
39
|
+
/^source\s+.*init-fish\.fish.*#\s*Safe-chain/,
|
|
38
40
|
eol
|
|
39
41
|
);
|
|
40
42
|
|
|
@@ -46,7 +48,7 @@ function setup() {
|
|
|
46
48
|
|
|
47
49
|
addLineToFile(
|
|
48
50
|
startupFile,
|
|
49
|
-
`source
|
|
51
|
+
`source ${path.join(getScriptsDir(), "init-fish.fish")} # Safe-chain Fish initialization script`,
|
|
50
52
|
eol
|
|
51
53
|
);
|
|
52
54
|
|
|
@@ -69,7 +71,7 @@ function getStartupFile() {
|
|
|
69
71
|
function getManualTeardownInstructions() {
|
|
70
72
|
return [
|
|
71
73
|
`Remove the following line from your ~/.config/fish/config.fish file:`,
|
|
72
|
-
` source
|
|
74
|
+
` source ${path.join(getScriptsDir(), "init-fish.fish")}`,
|
|
73
75
|
`Then restart your terminal or run: source ~/.config/fish/config.fish`,
|
|
74
76
|
];
|
|
75
77
|
}
|
|
@@ -77,7 +79,7 @@ function getManualTeardownInstructions() {
|
|
|
77
79
|
function getManualSetupInstructions() {
|
|
78
80
|
return [
|
|
79
81
|
`Add the following line to your ~/.config/fish/config.fish file:`,
|
|
80
|
-
` source
|
|
82
|
+
` source ${path.join(getScriptsDir(), "init-fish.fish")}`,
|
|
81
83
|
`Then restart your terminal or run: source ~/.config/fish/config.fish`,
|
|
82
84
|
];
|
|
83
85
|
}
|
|
@@ -4,7 +4,9 @@ import {
|
|
|
4
4
|
removeLinesMatchingPattern,
|
|
5
5
|
validatePowerShellExecutionPolicy,
|
|
6
6
|
} from "../helpers.js";
|
|
7
|
+
import { getScriptsDir } from "../../config/safeChainDir.js";
|
|
7
8
|
import { execSync } from "child_process";
|
|
9
|
+
import path from "path";
|
|
8
10
|
|
|
9
11
|
const shellName = "PowerShell Core";
|
|
10
12
|
const executableName = "pwsh";
|
|
@@ -30,10 +32,10 @@ function teardown(tools) {
|
|
|
30
32
|
);
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
// Remove
|
|
35
|
+
// Remove sourcing line to prevent shell from loading safe-chain after uninstallation
|
|
34
36
|
removeLinesMatchingPattern(
|
|
35
37
|
startupFile,
|
|
36
|
-
/^\.\s+["']
|
|
38
|
+
/^\.\s+["']?.*init-pwsh\.ps1["']?.*#\s*Safe-chain/,
|
|
37
39
|
);
|
|
38
40
|
|
|
39
41
|
return true;
|
|
@@ -52,7 +54,7 @@ async function setup() {
|
|
|
52
54
|
|
|
53
55
|
addLineToFile(
|
|
54
56
|
startupFile,
|
|
55
|
-
`. "$
|
|
57
|
+
`. "${path.join(getScriptsDir(), "init-pwsh.ps1")}" # Safe-chain PowerShell initialization script`,
|
|
56
58
|
);
|
|
57
59
|
|
|
58
60
|
return true;
|
|
@@ -74,7 +76,7 @@ function getStartupFile() {
|
|
|
74
76
|
function getManualTeardownInstructions() {
|
|
75
77
|
return [
|
|
76
78
|
`Remove the following line from your PowerShell profile (run "echo $PROFILE" to find its location):`,
|
|
77
|
-
` . "$
|
|
79
|
+
` . "${path.join(getScriptsDir(), "init-pwsh.ps1")}"`,
|
|
78
80
|
`Then restart your terminal or run: . $PROFILE`,
|
|
79
81
|
];
|
|
80
82
|
}
|
|
@@ -82,7 +84,7 @@ function getManualTeardownInstructions() {
|
|
|
82
84
|
function getManualSetupInstructions() {
|
|
83
85
|
return [
|
|
84
86
|
`Add the following line to your PowerShell profile (run "echo $PROFILE" to find its location):`,
|
|
85
|
-
` . "$
|
|
87
|
+
` . "${path.join(getScriptsDir(), "init-pwsh.ps1")}"`,
|
|
86
88
|
`Then restart your terminal or run: . $PROFILE`,
|
|
87
89
|
];
|
|
88
90
|
}
|
|
@@ -4,7 +4,9 @@ import {
|
|
|
4
4
|
removeLinesMatchingPattern,
|
|
5
5
|
validatePowerShellExecutionPolicy,
|
|
6
6
|
} from "../helpers.js";
|
|
7
|
+
import { getScriptsDir } from "../../config/safeChainDir.js";
|
|
7
8
|
import { execSync } from "child_process";
|
|
9
|
+
import path from "path";
|
|
8
10
|
|
|
9
11
|
const shellName = "Windows PowerShell";
|
|
10
12
|
const executableName = "powershell";
|
|
@@ -30,10 +32,10 @@ function teardown(tools) {
|
|
|
30
32
|
);
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
// Remove
|
|
35
|
+
// Remove sourcing line to clean up safe-chain integration from the shell profile
|
|
34
36
|
removeLinesMatchingPattern(
|
|
35
37
|
startupFile,
|
|
36
|
-
/^\.\s+["']
|
|
38
|
+
/^\.\s+["']?.*init-pwsh\.ps1["']?.*#\s*Safe-chain/,
|
|
37
39
|
);
|
|
38
40
|
|
|
39
41
|
return true;
|
|
@@ -52,7 +54,7 @@ async function setup() {
|
|
|
52
54
|
|
|
53
55
|
addLineToFile(
|
|
54
56
|
startupFile,
|
|
55
|
-
`. "$
|
|
57
|
+
`. "${path.join(getScriptsDir(), "init-pwsh.ps1")}" # Safe-chain PowerShell initialization script`,
|
|
56
58
|
);
|
|
57
59
|
|
|
58
60
|
return true;
|
|
@@ -74,7 +76,7 @@ function getStartupFile() {
|
|
|
74
76
|
function getManualTeardownInstructions() {
|
|
75
77
|
return [
|
|
76
78
|
`Remove the following line from your PowerShell profile (run "echo $PROFILE" to find its location):`,
|
|
77
|
-
` . "$
|
|
79
|
+
` . "${path.join(getScriptsDir(), "init-pwsh.ps1")}"`,
|
|
78
80
|
`Then restart your terminal or run: . $PROFILE`,
|
|
79
81
|
];
|
|
80
82
|
}
|
|
@@ -82,7 +84,7 @@ function getManualTeardownInstructions() {
|
|
|
82
84
|
function getManualSetupInstructions() {
|
|
83
85
|
return [
|
|
84
86
|
`Add the following line to your PowerShell profile (run "echo $PROFILE" to find its location):`,
|
|
85
|
-
` . "$
|
|
87
|
+
` . "${path.join(getScriptsDir(), "init-pwsh.ps1")}"`,
|
|
86
88
|
`Then restart your terminal or run: . $PROFILE`,
|
|
87
89
|
];
|
|
88
90
|
}
|
|
@@ -3,7 +3,9 @@ import {
|
|
|
3
3
|
doesExecutableExistOnSystem,
|
|
4
4
|
removeLinesMatchingPattern,
|
|
5
5
|
} from "../helpers.js";
|
|
6
|
+
import { getScriptsDir } from "../../config/safeChainDir.js";
|
|
6
7
|
import { execSync } from "child_process";
|
|
8
|
+
import path from "path";
|
|
7
9
|
|
|
8
10
|
const shellName = "Zsh";
|
|
9
11
|
const executableName = "zsh";
|
|
@@ -31,10 +33,10 @@ function teardown(tools) {
|
|
|
31
33
|
);
|
|
32
34
|
}
|
|
33
35
|
|
|
34
|
-
//
|
|
36
|
+
// Remove sourcing line to complete shell integration cleanup
|
|
35
37
|
removeLinesMatchingPattern(
|
|
36
38
|
startupFile,
|
|
37
|
-
/^source\s
|
|
39
|
+
/^source\s+.*init-posix\.sh.*#\s*Safe-chain/,
|
|
38
40
|
eol
|
|
39
41
|
);
|
|
40
42
|
|
|
@@ -46,7 +48,7 @@ function setup() {
|
|
|
46
48
|
|
|
47
49
|
addLineToFile(
|
|
48
50
|
startupFile,
|
|
49
|
-
`source
|
|
51
|
+
`source ${path.join(getScriptsDir(), "init-posix.sh")} # Safe-chain Zsh initialization script`,
|
|
50
52
|
eol
|
|
51
53
|
);
|
|
52
54
|
|
|
@@ -69,7 +71,7 @@ function getStartupFile() {
|
|
|
69
71
|
function getManualTeardownInstructions() {
|
|
70
72
|
return [
|
|
71
73
|
`Remove the following line from your ~/.zshrc file:`,
|
|
72
|
-
` source
|
|
74
|
+
` source ${path.join(getScriptsDir(), "init-posix.sh")}`,
|
|
73
75
|
`Then restart your terminal or run: source ~/.zshrc`,
|
|
74
76
|
];
|
|
75
77
|
}
|
|
@@ -77,7 +79,7 @@ function getManualTeardownInstructions() {
|
|
|
77
79
|
function getManualSetupInstructions() {
|
|
78
80
|
return [
|
|
79
81
|
`Add the following line to your ~/.zshrc file:`,
|
|
80
|
-
` source
|
|
82
|
+
` source ${path.join(getScriptsDir(), "init-posix.sh")}`,
|
|
81
83
|
`Then restart your terminal or run: source ~/.zshrc`,
|
|
82
84
|
];
|
|
83
85
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
import { ui } from "../environment/userInteraction.js";
|
|
3
3
|
import { detectShells } from "./shellDetection.js";
|
|
4
|
-
import { knownAikidoTools, getPackageManagerList
|
|
4
|
+
import { knownAikidoTools, getPackageManagerList } from "./helpers.js";
|
|
5
|
+
import { getShimsDir, getScriptsDir } from "../config/safeChainDir.js";
|
|
5
6
|
import fs from "fs";
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -109,4 +110,5 @@ export async function teardownDirectories() {
|
|
|
109
110
|
);
|
|
110
111
|
}
|
|
111
112
|
}
|
|
113
|
+
|
|
112
114
|
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { platform } from 'os';
|
|
2
|
-
import { ui } from "../environment/userInteraction.js";
|
|
3
|
-
import { readFileSync, existsSync } from "node:fs";
|
|
4
|
-
import {randomUUID} from "node:crypto";
|
|
5
|
-
import {createWriteStream} from "fs";
|
|
6
|
-
import archiver from 'archiver';
|
|
7
|
-
import path from "node:path";
|
|
8
|
-
|
|
9
|
-
export async function printUltimateLogs() {
|
|
10
|
-
const { proxyLogPath, ultimateLogPath, proxyErrLogPath, ultimateErrLogPath } = getPathsPerPlatform();
|
|
11
|
-
|
|
12
|
-
await printLogs(
|
|
13
|
-
"SafeChain Proxy",
|
|
14
|
-
proxyLogPath,
|
|
15
|
-
proxyErrLogPath
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
await printLogs(
|
|
19
|
-
"SafeChain Ultimate",
|
|
20
|
-
ultimateLogPath,
|
|
21
|
-
ultimateErrLogPath
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export async function troubleshootingExport() {
|
|
26
|
-
const { logDir } = getPathsPerPlatform();
|
|
27
|
-
return new Promise((resolve, reject) => {
|
|
28
|
-
if (!existsSync(logDir)) {
|
|
29
|
-
ui.writeError(`Log directory not found: ${logDir}`);
|
|
30
|
-
reject(new Error(`Log directory not found: ${logDir}`));
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const date = new Date().toISOString().split('T')[0];
|
|
35
|
-
const uuid = randomUUID();
|
|
36
|
-
const zipFileName = `safechain-ultimate-${date}-${uuid}.zip`;
|
|
37
|
-
const output = createWriteStream(zipFileName);
|
|
38
|
-
const archive = archiver('zip', { zlib: { level: 9 } });
|
|
39
|
-
|
|
40
|
-
output.on('close', () => {
|
|
41
|
-
ui.writeInformation(`Logs collected and zipped as: ${path.resolve(zipFileName)}`);
|
|
42
|
-
resolve(zipFileName);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
archive.on('error', (/** @type {Error} */ err) => {
|
|
46
|
-
ui.writeError(`Failed to zip logs: ${err.message}`);
|
|
47
|
-
reject(err);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
archive.pipe(output);
|
|
51
|
-
archive.directory(logDir, false);
|
|
52
|
-
archive.finalize();
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
function getPathsPerPlatform() {
|
|
58
|
-
const os = platform();
|
|
59
|
-
if (os === 'win32') {
|
|
60
|
-
const logDir = `C:\\ProgramData\\AikidoSecurity\\SafeChainUltimate\\logs`;
|
|
61
|
-
return {
|
|
62
|
-
logDir,
|
|
63
|
-
proxyLogPath: `${logDir}\\SafeChainProxy.log`,
|
|
64
|
-
ultimateLogPath: `${logDir}\\SafeChainUltimate.log`,
|
|
65
|
-
proxyErrLogPath: `${logDir}\\SafeChainProxy.err`,
|
|
66
|
-
ultimateErrLogPath: `${logDir}\\SafeChainUltimate.err`,
|
|
67
|
-
};
|
|
68
|
-
} else if (os === 'darwin') {
|
|
69
|
-
const logDir = `/Library/Logs/AikidoSecurity/SafeChainUltimate`;
|
|
70
|
-
return {
|
|
71
|
-
logDir,
|
|
72
|
-
proxyLogPath: `${logDir}/safechain-proxy.log`,
|
|
73
|
-
ultimateLogPath: `${logDir}/safechain-ultimate.log`,
|
|
74
|
-
proxyErrLogPath: `${logDir}/safechain-proxy.error.log`,
|
|
75
|
-
ultimateErrLogPath: `${logDir}/safechain-ultimate.error.log`,
|
|
76
|
-
};
|
|
77
|
-
} else {
|
|
78
|
-
throw new Error('Unsupported platform for log printing.');
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* @param {string} appName
|
|
84
|
-
* @param {string} logPath
|
|
85
|
-
* @param {string} errLogPath
|
|
86
|
-
*/
|
|
87
|
-
async function printLogs(appName, logPath, errLogPath) {
|
|
88
|
-
ui.writeInformation(`=== ${appName} Logs ===`);
|
|
89
|
-
try {
|
|
90
|
-
if (existsSync(logPath)) {
|
|
91
|
-
const logs = readFileSync(logPath, "utf-8");
|
|
92
|
-
ui.writeInformation(logs);
|
|
93
|
-
} else {
|
|
94
|
-
ui.writeWarning(`${appName} log file not found: ${logPath}`);
|
|
95
|
-
}
|
|
96
|
-
} catch (error) {
|
|
97
|
-
ui.writeError(`Failed to read ${appName} logs: ${error}`);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
ui.writeInformation(`=== ${appName} Error Logs ===`);
|
|
101
|
-
try {
|
|
102
|
-
if (existsSync(errLogPath)) {
|
|
103
|
-
const errLogs = readFileSync(errLogPath, "utf-8");
|
|
104
|
-
ui.writeInformation(errLogs);
|
|
105
|
-
} else {
|
|
106
|
-
ui.writeInformation(`No error log file found for ${appName}.`);
|
|
107
|
-
}
|
|
108
|
-
} catch (error) {
|
|
109
|
-
ui.writeError(`Failed to read ${appName} error logs: ${error}`);
|
|
110
|
-
}
|
|
111
|
-
}
|