Skip to content

Self-improving AI Employees for everyone

fix(security): clear 13 CodeQL alerts (Tier 1 + 2 + 5)

trohitg02704b575b8a
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 09a4e3a2..fcc3bdc7 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -9,6 +9,12 @@ on:
pull_request:
branches: [main]
+# Minimum-privilege GITHUB_TOKEN for the implicit calls inside
+# actions (checkout, etc.). Reusable workflows called below declare
+# their own permissions; this one needs read-only at most.
+permissions:
+ contents: read
+
jobs:
predeploy:
uses: ./.github/workflows/predeploy.yml
diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml
index e465bf12..718a004c 100644
--- a/.github/workflows/docs.yml
+++ b/.github/workflows/docs.yml
@@ -10,6 +10,9 @@ on:
- 'docs-MachinaOs/**'
workflow_dispatch:
+permissions:
+ contents: read
+
jobs:
deploy:
runs-on: ubuntu-latest
diff --git a/.github/workflows/predeploy.yml b/.github/workflows/predeploy.yml
index a1c15e90..8eed612c 100644
--- a/.github/workflows/predeploy.yml
+++ b/.github/workflows/predeploy.yml
@@ -6,6 +6,9 @@ name: Predeploy
on:
workflow_call:
+permissions:
+ contents: read
+
jobs:
build-and-lint:
runs-on: ubuntu-latest
diff --git a/.github/workflows/test-install.yml b/.github/workflows/test-install.yml
index 4cdefbb6..5480ea13 100644
--- a/.github/workflows/test-install.yml
+++ b/.github/workflows/test-install.yml
@@ -7,6 +7,9 @@ on:
workflow_dispatch:
workflow_call:
+permissions:
+ contents: read
+
jobs:
# Test npm install from registry (post-release)
test-npm-install:
diff --git a/server/nodejs/src/index.ts b/server/nodejs/src/index.ts
index 202876ff..a79d4f06 100644
--- a/server/nodejs/src/index.ts
+++ b/server/nodejs/src/index.ts
@@ -5,7 +5,7 @@
import express, { Request, Response, NextFunction } from 'express';
import vm from 'node:vm';
-import { execSync } from 'node:child_process';
+import { execFileSync } from 'node:child_process';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
@@ -65,6 +65,14 @@ app.post('/execute', (req: Request, res: Response) => {
try {
const context = vm.createContext(sandbox);
+ // This service IS the sandboxed JS executor for the pythonExecutor /
+ // javascriptExecutor workflow nodes. Node's `vm` is not a security
+ // boundary (per https://nodejs.org/api/vm.html#vmcreatecontextcontextobject-options);
+ // the deployment context is: server binds to localhost only (line 16,
+ // default 'localhost') and is invoked exclusively by the same-machine
+ // Python backend via NodeJSClient. Public network exposure is the
+ // operator's responsibility.
+ // codeql[js/code-injection]
vm.runInContext(code, context, { timeout, filename: 'user-code.js' });
res.json({
@@ -83,7 +91,11 @@ app.post('/execute', (req: Request, res: Response) => {
}
});
-// Install packages - package list from request
+// Install packages - package list from request.
+// Localhost-only service (see server.listen at the bottom); same trust
+// boundary as the /execute sandbox. No request-rate limiting because the
+// only caller is the same-machine Python backend.
+// codeql[js/missing-rate-limiting]
app.post('/packages/install', (req: Request, res: Response) => {
const { packages } = req.body as { packages: string[] };
@@ -100,17 +112,22 @@ app.post('/packages/install', (req: Request, res: Response) => {
}
try {
- execSync(`npm install ${packages.join(' ')}`, { cwd: USER_PACKAGES_DIR, timeout: 60000 });
+ // execFileSync (argv array, no shell) instead of execSync with template
+ // string. The regex above already validates names, but going through
+ // execFileSync removes the shell from the path entirely as
+ // defense-in-depth.
+ execFileSync('npm', ['install', ...packages], { cwd: USER_PACKAGES_DIR, timeout: 60000 });
res.json({ success: true, message: `Installed: ${packages.join(', ')}` });
} catch (error) {
res.status(500).json({ success: false, error: error instanceof Error ? error.message : String(error) });
}
});
-// List packages
+// List packages — same localhost-only trust boundary as above.
+// codeql[js/missing-rate-limiting]
app.get('/packages', (_req: Request, res: Response) => {
try {
- const output = execSync('npm list --json --depth=0', { cwd: USER_PACKAGES_DIR, encoding: 'utf-8' });
+ const output = execFileSync('npm', ['list', '--json', '--depth=0'], { cwd: USER_PACKAGES_DIR, encoding: 'utf-8' });
res.json({ success: true, packages: JSON.parse(output).dependencies || {} });
} catch {
res.json({ success: true, packages: {} });
diff --git a/server/nodes/android/_router.py b/server/nodes/android/_router.py
index 558e1a6b..20152e4c 100644
--- a/server/nodes/android/_router.py
+++ b/server/nodes/android/_router.py
@@ -1,6 +1,8 @@
"""Android System Services routes."""
-from fastapi import APIRouter, Depends
+import re
+
+from fastapi import APIRouter, Depends, HTTPException
from pydantic import BaseModel, Field
from typing import Dict, Any
@@ -11,6 +13,20 @@ from services.plugin.deps import get_android_service
logger = get_logger(__name__)
router = APIRouter(prefix="/api/android", tags=["android"])
+# ADB device IDs: USB serials (alphanumeric), TCP "host:port" (digits + dots
+# + colon), or "emulator-NNNN". All are safe characters but we lock the
+# accepted set explicitly so untrusted input can't slip a flag or path
+# separator into the argv list we pass to subprocess.run. Anything outside
+# `[A-Za-z0-9._:-]` (and longer than 64 chars) is rejected with 400.
+_DEVICE_ID_PATTERN = re.compile(r"^[A-Za-z0-9._:-]{1,64}$")
+
+
+def _validate_device_id(device_id: str) -> str:
+ """Return device_id if it matches the ADB device-id shape, else 400."""
+ if not _DEVICE_ID_PATTERN.fullmatch(device_id):
+ raise HTTPException(status_code=400, detail="invalid device_id")
+ return device_id
+
class AndroidServiceRequest(BaseModel):
"""Request model for Android service execution."""
@@ -195,9 +211,12 @@ async def setup_port_forwarding(
device_port: int = 8888
):
"""Setup ADB port forwarding for Android device communication."""
+ device_id = _validate_device_id(device_id)
import subprocess
try:
# Setup port forwarding: adb -s device_id forward tcp:local_port tcp:device_port
+ # device_id passes _DEVICE_ID_PATTERN above; subprocess.run is called
+ # with an argv list (no shell), so no further interpolation risk.
cmd = ["adb", "-s", device_id, "forward", f"tcp:{local_port}", f"tcp:{device_port}"]
result = subprocess.run(