Skip to content

armgit / Ix

Public Imported from GitHub
0

Understand any codebase instantly. System intelligence for codebases, built for humans and AI.

fix: security audit — shell injection, temp files, license, Dockerfile (#49)

Riley Thompsonf96248707838
diff --git a/homebrew/ix.rb b/homebrew/ix.rb
index 9093b4e6..2347a6ca 100644
--- a/homebrew/ix.rb
+++ b/homebrew/ix.rb
@@ -3,7 +3,7 @@ class Ix < Formula
homepage "https://github.com/ix-infrastructure/Ix"
url "https://github.com/ix-infrastructure/Ix/archive/refs/tags/v0.3.4.tar.gz"
sha256 "32bfaa786849230d3ee72198b0a89ce7706dfd011c9919d69fc9929265c10fa7"
- license "MIT"
+ license "Apache-2.0"
head "https://github.com/ix-infrastructure/Ix.git", branch: "main"
depends_on "node@22"
diff --git a/install.sh b/install.sh
index eb183308..5d65fdf9 100755
--- a/install.sh
+++ b/install.sh
@@ -265,8 +265,12 @@ fi
if [ ! -x "$IX_BIN/ix" ] || [ "$("$IX_BIN/ix" --version 2>/dev/null || echo "")" != "$VERSION" ]; then
mkdir -p "$INSTALL_DIR"
+ TMP_DIR=$(mktemp -d)
+ TMP_FILE="$TMP_DIR/${TARBALL_NAME}"
+
echo " Downloading ix CLI v${VERSION} for ${PLATFORM}..."
- if ! curl -fsSL "$TARBALL_URL" -o "/tmp/${TARBALL_NAME}" 2>/dev/null; then
+ if ! curl -fsSL "$TARBALL_URL" -o "$TMP_FILE" 2>/dev/null; then
+ rm -rf "$TMP_DIR"
echo ""
warn "Could not download pre-built CLI from:"
warn " $TARBALL_URL"
@@ -281,8 +285,8 @@ if [ ! -x "$IX_BIN/ix" ] || [ "$("$IX_BIN/ix" --version 2>/dev/null || echo "")"
fi
# Extract
- tar -xzf "/tmp/${TARBALL_NAME}" -C "$INSTALL_DIR" --strip-components=1
- rm -f "/tmp/${TARBALL_NAME}"
+ tar -xzf "$TMP_FILE" -C "$INSTALL_DIR" --strip-components=1
+ rm -rf "$TMP_DIR"
info "Extracted CLI"
# Create wrapper in bin dir
diff --git a/ix-cli/src/cli/commands/docker.ts b/ix-cli/src/cli/commands/docker.ts
index 06a3c615..1446417f 100644
--- a/ix-cli/src/cli/commands/docker.ts
+++ b/ix-cli/src/cli/commands/docker.ts
@@ -1,7 +1,7 @@
import { Command } from "commander";
-import { execSync, spawn } from "child_process";
+import { execFileSync, execSync, spawn } from "child_process";
import { createInterface } from "readline";
-import { existsSync } from "fs";
+import { existsSync, mkdirSync, writeFileSync } from "fs";
import { join } from "path";
import { homedir } from "os";
@@ -14,29 +14,17 @@ const GITHUB_RAW =
"https://raw.githubusercontent.com/ix-infrastructure/Ix/main";
function findComposeFile(): string | null {
- // Check standalone install location first
if (existsSync(LOCAL_COMPOSE)) return LOCAL_COMPOSE;
-
- // Check if we're in the Ix repo
const repoCompose = join(process.cwd(), "docker-compose.yml");
if (existsSync(repoCompose)) return repoCompose;
-
return null;
}
-/**
- * Find all Ix-managed ArangoDB Docker volumes across repos.
- *
- * Matches volumes created by Docker Compose where:
- * - The compose project name starts with "ix" (label: com.docker.compose.project)
- * - The compose volume name contains "arango" (label: com.docker.compose.volume)
- *
- * This avoids matching unrelated ArangoDB volumes (e.g. enterprise projects).
- */
function findIxArangoVolumes(): string[] {
try {
- const output = execSync(
- 'docker volume ls --format "{{.Name}}|{{.Labels}}"',
+ const output = execFileSync(
+ "docker",
+ ["volume", "ls", "--format", "{{.Name}}|{{.Labels}}"],
{ encoding: "utf-8", timeout: 10000 }
).trim();
if (!output) return [];
@@ -45,7 +33,6 @@ function findIxArangoVolumes(): string[] {
const [name, labels] = line.split("|", 2);
if (!name || !labels) return false;
- // Parse labels: "key1=val1,key2=val2,..."
const labelMap = new Map<string, string>();
for (const pair of labels.split(",")) {
const eq = pair.indexOf("=");
@@ -55,7 +42,6 @@ function findIxArangoVolumes(): string[] {
const project = labelMap.get("com.docker.compose.project") ?? "";
const volume = labelMap.get("com.docker.compose.volume") ?? "";
- // Match: Ix project (starts with "ix") + ArangoDB volume (contains "arango")
return project.startsWith("ix") && volume.includes("arango");
}).map((line) => line.split("|", 1)[0]);
} catch {
@@ -75,8 +61,8 @@ function askConfirmation(prompt: string): Promise<boolean> {
function isHealthy(): boolean {
try {
- execSync(`curl -sf ${HEALTH_URL}`, { stdio: "ignore", timeout: 5000 });
- execSync(`curl -sf ${ARANGO_URL}`, { stdio: "ignore", timeout: 5000 });
+ execFileSync("curl", ["-sf", HEALTH_URL], { stdio: "ignore", timeout: 5000 });
+ execFileSync("curl", ["-sf", ARANGO_URL], { stdio: "ignore", timeout: 5000 });
return true;
} catch {
return false;
@@ -85,7 +71,7 @@ function isHealthy(): boolean {
function dockerAvailable(): boolean {
try {
- execSync("docker info", { stdio: "ignore", timeout: 10000 });
+ execFileSync("docker", ["info"], { stdio: "ignore", timeout: 10000 });
return true;
} catch {
return false;
@@ -117,28 +103,26 @@ export function registerDockerCommand(program: Command): void {
let composeFile = findComposeFile();
- // If no compose file found, download the standalone one
if (!composeFile) {
console.log("Downloading docker-compose.yml...");
try {
- execSync(`mkdir -p "${COMPOSE_DIR}"`);
- execSync(
- `curl -fsSL "${GITHUB_RAW}/docker-compose.standalone.yml" -o "${LOCAL_COMPOSE}"`,
+ mkdirSync(COMPOSE_DIR, { recursive: true });
+ execFileSync(
+ "curl",
+ ["-fsSL", `${GITHUB_RAW}/docker-compose.standalone.yml`, "-o", LOCAL_COMPOSE],
{ stdio: "inherit" }
);
composeFile = LOCAL_COMPOSE;
console.log(`[ok] Saved to ${COMPOSE_DIR}`);
} catch {
- console.error(
- "[error] Failed to download docker-compose.yml"
- );
+ console.error("[error] Failed to download docker-compose.yml");
process.exit(1);
}
}
console.log("Starting backend services...");
try {
- execSync(`docker compose -f "${composeFile}" up -d`, {
+ execFileSync("docker", ["compose", "-f", composeFile, "up", "-d"], {
stdio: "inherit",
});
} catch {
@@ -146,7 +130,6 @@ export function registerDockerCommand(program: Command): void {
process.exit(1);
}
- // Wait for health
console.log("Waiting for services to become healthy...");
for (let i = 0; i < 30; i++) {
if (isHealthy()) {
@@ -161,9 +144,7 @@ export function registerDockerCommand(program: Command): void {
}
console.log("");
- console.error(
- "[!!] Health check timed out. Check: ix docker logs"
- );
+ console.error("[!!] Health check timed out. Check: ix docker logs");
process.exit(1);
});
@@ -178,34 +159,28 @@ export function registerDockerCommand(program: Command): void {
const composeFile = findComposeFile();
if (!composeFile) {
console.error("[error] No docker-compose.yml found.");
- console.error(
- " Run 'ix docker start' first, or run from the Ix repo."
- );
+ console.error(" Run 'ix docker start' first, or run from the Ix repo.");
process.exit(1);
}
- // --remove-all-data is a superset of --remove-data
const removeLocal = opts.removeData || opts.removeAllData;
- const flags = removeLocal ? "down -v" : "down";
+ const args = ["compose", "-f", composeFile, "down"];
+ if (removeLocal) args.push("-v");
try {
- execSync(`docker compose -f "${composeFile}" ${flags}`, {
- stdio: "inherit",
- });
+ execFileSync("docker", args, { stdio: "inherit" });
} catch {
console.error("[error] Failed to stop containers.");
process.exit(1);
}
if (opts.removeAllData) {
- // Global cleanup: find and remove all Ix ArangoDB volumes
const volumes = findIxArangoVolumes();
if (volumes.length === 0) {
console.log("[ok] Backend stopped. No additional Ix data volumes found.");
return;
}
- // Confirm unless --yes
if (!opts.yes) {
console.log("");
console.log("This will remove all local Ix ArangoDB data volumes across repos:");
@@ -222,7 +197,7 @@ export function registerDockerCommand(program: Command): void {
const failed: string[] = [];
for (const v of volumes) {
try {
- execSync(`docker volume rm "${v}"`, { stdio: "ignore", timeout: 10000 });
+ execFileSync("docker", ["volume", "rm", v], { stdio: "ignore", timeout: 10000 });
removed.push(v);
} catch {
failed.push(v);
@@ -249,9 +224,7 @@ export function registerDockerCommand(program: Command): void {
console.log("[ok] Backend stopped and data volume removed.");
} else {
console.log("[ok] Backend stopped. Data volume preserved.");
- console.log(
- " Use 'ix docker stop --remove-data' to also delete data."
- );
+ console.log(" Use 'ix docker stop --remove-data' to also delete data.");
}
});
@@ -262,7 +235,7 @@ export function registerDockerCommand(program: Command): void {
const composeFile = findComposeFile();
if (composeFile) {
try {
- execSync(`docker compose -f "${composeFile}" ps`, {
+ execFileSync("docker", ["compose", "-f", composeFile, "ps"], {
stdio: "inherit",
});
} catch {
@@ -277,19 +250,13 @@ export function registerDockerCommand(program: Command): void {
} else {
console.log("[!!] Backend is not healthy");
try {
- execSync(`curl -sf ${HEALTH_URL}`, {
- stdio: "ignore",
- timeout: 3000,
- });
+ execFileSync("curl", ["-sf", HEALTH_URL], { stdio: "ignore", timeout: 3000 });
console.log(" Memory Layer: responding");
} catch {
console.log(" Memory Layer: not responding");
}
try {
- execSync(`curl -sf ${ARANGO_URL}`, {
- stdio: "ignore",
- timeout: 3000,
- });
+ execFileSync("curl", ["-sf", ARANGO_URL], { stdio: "ignore", timeout: 3000 });
console.log(" ArangoDB: responding");
} catch {
console.log(" ArangoDB: not responding");
@@ -308,12 +275,9 @@ export function registerDockerCommand(program: Command): void {
process.exit(1);
}
- const followFlag = opts.follow ? "-f" : "";
- const child = spawn(
- "docker",
- ["compose", "-f", composeFile, "logs", followFlag].filter(Boolean),
- { stdio: "inherit" }
- );
+ const args = ["compose", "-f", composeFile, "logs"];
+ if (opts.follow) args.push("-f");
+ const child = spawn("docker", args, { stdio: "inherit" });
child.on("exit", (code) => process.exit(code || 0));
});
@@ -328,7 +292,7 @@ export function registerDockerCommand(program: Command): void {
}
try {
- execSync(`docker compose -f "${composeFile}" restart`, {
+ execFileSync("docker", ["compose", "-f", composeFile, "restart"], {
stdio: "inherit",
});
console.log("[ok] Backend restarted.");
diff --git a/ix-cli/src/cli/commands/upgrade.ts b/ix-cli/src/cli/commands/upgrade.ts
index 06d34337..e56c09da 100644
--- a/ix-cli/src/cli/commands/upgrade.ts
+++ b/ix-cli/src/cli/commands/upgrade.ts
@@ -1,8 +1,8 @@
import { Command } from "commander";
-import { execSync } from "child_process";
-import { readFileSync, writeFileSync, existsSync, mkdirSync } from "fs";
+import { execFileSync } from "child_process";
+import { readFileSync, writeFileSync, existsSync, mkdirSync, rmSync, mkdtempSync } from "fs";
import { join } from "path";
-import { homedir } from "os";
+import { homedir, tmpdir } from "os";
import chalk from "chalk";
const GITHUB_ORG = "ix-infrastructure";
@@ -84,7 +84,6 @@ export async function checkForUpdate(): Promise<void> {
const current = getCurrentVersion();
const cache = readCache();
- // Only check once per hour
if (cache && Date.now() - cache.checkedAt < 3600_000) {
if (isNewer(cache.latest, current)) {
printUpdateNotice(current, cache.latest);
@@ -92,7 +91,6 @@ export async function checkForUpdate(): Promise<void> {
return;
}
- // Fetch in background — don't block the command
fetchLatestVersion().then((latest) => {
if (!latest) return;
writeCache(latest);
@@ -138,17 +136,21 @@ export function registerUpgradeCommand(program: Command): void {
if (opts.check) return;
- // Download and install the new CLI
const platform = detectPlatform();
const tarball = `ix-${latest}-${platform}.tar.gz`;
const url = `https://github.com/${GITHUB_ORG}/${GITHUB_REPO}/releases/download/v${latest}/${tarball}`;
const installDir = join(IX_HOME, "cli");
+ // Use secure temp directory
+ const tmpDir = mkdtempSync(join(tmpdir(), "ix-upgrade-"));
+ const tmpFile = join(tmpDir, tarball);
+
console.log(`Downloading ix ${latest} for ${platform}...`);
try {
- execSync(
- `curl -fsSL "${url}" -o "/tmp/${tarball}"`,
+ execFileSync(
+ "curl",
+ ["-fsSL", url, "-o", tmpFile],
{ stdio: "inherit", timeout: 60000 }
);
} catch {
@@ -157,51 +159,52 @@ export function registerUpgradeCommand(program: Command): void {
console.error(
` curl -fsSL https://raw.githubusercontent.com/${GITHUB_ORG}/${GITHUB_REPO}/main/install.sh | bash`
);
+ rmSync(tmpDir, { recursive: true, force: true });
process.exit(1);
}
- // Extract over the existing install
console.log("Installing...");
try {
- execSync(`rm -rf "${installDir}"`, { stdio: "ignore" });
- execSync(`mkdir -p "${installDir}"`, { stdio: "ignore" });
- execSync(
- `tar -xzf "/tmp/${tarball}" -C "${installDir}" --strip-components=1`,
+ rmSync(installDir, { recursive: true, force: true });
+ mkdirSync(installDir, { recursive: true });
+ execFileSync(
+ "tar",
+ ["-xzf", tmpFile, "-C", installDir, "--strip-components=1"],
{ stdio: "ignore" }
);
- execSync(`rm -f "/tmp/${tarball}"`, { stdio: "ignore" });
+ rmSync(tmpDir, { recursive: true, force: true });
} catch {
console.error("[error] Failed to extract CLI update.");
+ rmSync(tmpDir, { recursive: true, force: true });
process.exit(1);
}
console.log(`[ok] Upgraded ix: ${current} → ${latest}`);
- // Update the Docker image too
console.log("Pulling latest backend image...");
try {
- execSync(
- "docker pull ghcr.io/ix-infrastructure/ix-memory-layer:latest",
+ execFileSync(
+ "docker",
+ ["pull", "ghcr.io/ix-infrastructure/ix-memory-layer:latest"],
{ stdio: "inherit", timeout: 120000 }
);
console.log("[ok] Backend image updated");
} catch {
- console.error(
- "[!!] Could not pull latest backend image. Run: ix docker restart"
- );
+ console.error("[!!] Could not pull latest backend image. Run: ix docker restart");
}
// Restart backend if running
try {
- execSync("curl -sf http://localhost:8090/v1/health", {
+ execFileSync("curl", ["-sf", "http://localhost:8090/v1/health"], {
stdio: "ignore",
timeout: 3000,
});
console.log("Restarting backend...");
const composeFile = join(IX_HOME, "backend", "docker-compose.yml");
if (existsSync(composeFile)) {
- execSync(
- `docker compose -f "${composeFile}" up -d --pull always`,
+ execFileSync(
+ "docker",
+ ["compose", "-f", composeFile, "up", "-d", "--pull", "always"],
{ stdio: "inherit" }
);
console.log("[ok] Backend restarted with latest image");
diff --git a/memory-layer/Dockerfile b/memory-layer/Dockerfile
index 8b8088fe..8414f687 100644
--- a/memory-layer/Dockerfile
+++ b/memory-layer/Dockerfile
@@ -5,4 +5,6 @@ COPY target/scala-2.13/ix-memory-layer.jar app.jar
EXPOSE 8090
HEALTHCHECK --interval=10s --timeout=3s --start-period=15s --retries=3 \
CMD curl -sf http://localhost:8090/v1/health || exit 1
+RUN addgroup --gid 1000 ix && adduser --uid 1000 --gid 1000 --disabled-password --gecos "" ix && chown ix:ix app.jar
+USER ix
CMD ["java", "-jar", "app.jar"]