Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: keep database bootstrap and Docker transfer passwords out of process arguments (#10484)
[._.]/ Adam Eivy5ffed6a144dc
diff --git a/scripts/db-migrate.test.js b/scripts/db-migrate.test.jsindex 51b6e123b8..cce0bd5dcd 100644--- a/scripts/db-migrate.test.js+++ b/scripts/db-migrate.test.js@@ -348,4 +348,66 @@ describe.skipIf(process.platform === 'win32')('scripts/db.sh export + migrate',expect(down.status).not.toBe(0);expect(psqlCalls().every(call => !call.includes('-p 5433 '))).toBe(true);});++ // #10484: a custom password must reach the target process through its+ // environment or stdin only, never as an argument a process list can show.+ describe('credential handling', () => {+ const SECRET = "p'a\"ss w;rd $(touch pwned) & \\back`tick`";++ const PROVISION_PSQL_STUB = `#!/bin/sh+echo "psql $*" >> "$STUB_LOG"+case "$*" in+ *pg_roles*) [ -n "$ROLE_EXISTS" ] && echo 1; exit 0 ;;+ *-lqt*) echo " $PGDATABASE |"; exit 0 ;;+ *--single-transaction*) cat >> "$IMPORT_LOG"; exit 0 ;;+ *-c*|*-f*) exit 0 ;;+esac+cat >> "$STUB_LOG_DIR/psql.stdin"+printf '%s|%s' "$PORTOS_BOOTSTRAP_ROLE" "$PORTOS_BOOTSTRAP_PASSWORD" >> "$STUB_LOG_DIR/psql.env"+exit "\${PROVISION_EXIT:-0}"+`;++ const DOCKER_ENV_STUB = DOCKER_STUB.replace('\n', '\nprintf "%s" "$PGPASSWORD" >> "$STUB_LOG_DIR/docker.env"\n');++ it.each([+ ['create', {}, 'CREATE ROLE :"role"'],+ ['alter', { ROLE_EXISTS: '1' }, 'ALTER USER :"role"'],+ ])('setup-native %s keeps the password out of argv and quotes it inside psql', (_name, extra, sql) => {+ writeStub(join(root, 'bin'), 'psql', PROVISION_PSQL_STUB);+ const result = run(['setup-native'], 'ok', { PGPASSWORD: SECRET, PGUSER: 'role"x', STUB_LOG_DIR: root, PGDATABASE: 'example_db', ...extra });+ expect(result.status, result.stderr).toBe(0);+ expect(readFileSync(stubLog, 'utf8')).not.toContain('p\'a');+ expect(result.stdout + result.stderr).not.toContain('w;rd');+ expect(existsSync(join(root, 'pwned'))).toBe(false);+ const stdin = readFileSync(join(root, 'psql.stdin'), 'utf8');+ expect(stdin).toContain(sql);+ expect(stdin).toContain("PASSWORD :'pw'");+ expect(stdin).not.toContain('w;rd');+ expect(readFileSync(join(root, 'psql.env'), 'utf8')).toBe('role"x|' + SECRET);+ });++ it('setup-native fails when role provisioning fails', () => {+ writeStub(join(root, 'bin'), 'psql', PROVISION_PSQL_STUB);+ const result = run(['setup-native'], 'ok', { PGPASSWORD: SECRET, STUB_LOG_DIR: root, PROVISION_EXIT: '3' });+ expect(result.status).not.toBe(0);+ expect(result.stdout).not.toContain('Native PostgreSQL is ready');+ expect(result.stdout + result.stderr).not.toContain('w;rd');+ });++ it('docker export and import pass the password via the docker client environment only', () => {+ writeStub(join(root, 'bin'), 'docker', DOCKER_ENV_STUB);+ rmSync(join(root, 'bin', 'psql'));+ rmSync(join(root, 'bin', 'pg_dump'));+ const exported = run(['export', 'secret'], 'ok', { PGPASSWORD: SECRET, STUB_LOG_DIR: root });+ expect(exported.status, exported.stderr).toBe(0);+ const dump = join(dumpDir, 'portos-secret.sql');+ const imported = run(['import', dump], 'ok', { PGPASSWORD: SECRET, STUB_LOG_DIR: root });+ expect(imported.status, imported.stderr).toBe(0);+ expect(readFileSync(stubLog, 'utf8')).toMatch(/docker exec .*-e PGPASSWORD portos-db pg_dump/);+ expect(readFileSync(stubLog, 'utf8')).toMatch(/docker exec -i .*-e PGPASSWORD portos-db psql/);+ expect(readFileSync(stubLog, 'utf8') + readFileSync(importLog, 'utf8')).not.toContain('w;rd');+ expect(readFileSync(join(root, 'docker.env'), 'utf8')).toContain(SECRET);+ expect(exported.stdout + exported.stderr + imported.stdout + imported.stderr).not.toContain('w;rd');+ });+ });});diff --git a/scripts/db.sh b/scripts/db.shindex fc68daac77..b17624eb57 100755--- a/scripts/db.sh+++ b/scripts/db.sh@@ -433,6 +433,18 @@ fix_native() {}# Setup native PostgreSQL — detects and reuses existing system installation+# Run one role statement as the system user without the password in argv.+# The statement arrives on stdin; psql reads the role name and password from+# the environment (\getenv, PostgreSQL 15+) and quotes them as an identifier+# (:"role") and a literal (:'pw'). The values are scoped to this one command and+# deliberately not PG* variables, so they never authenticate the connection.+provision_role() {+ local sys_user="$1" statement="$2"+ printf '%s\n%s\n%s\n' '\getenv role PORTOS_BOOTSTRAP_ROLE' '\getenv pw PORTOS_BOOTSTRAP_PASSWORD' "$statement" |+ PORTOS_BOOTSTRAP_ROLE="$PGUSER" PORTOS_BOOTSTRAP_PASSWORD="$PGPASSWORD" \+ psql -h "$PGHOST" -p "$PGPORT" -U "$sys_user" -d postgres -v ON_ERROR_STOP=1 -X -q+}+cmd_setup_native() {info "Setting up native PostgreSQL for PortOS..."@@ -518,14 +530,12 @@ cmd_setup_native() {sys_user="$(whoami)"if ! psql -h "$PGHOST" -p "$PGPORT" -U "$sys_user" -d postgres -tAc "SELECT 1 FROM pg_roles WHERE rolname='$PGUSER'" 2>/dev/null | grep -q 1; theninfo "Creating database user: $PGUSER"- psql -h "$PGHOST" -p "$PGPORT" -U "$sys_user" -d postgres \- -c "CREATE ROLE $PGUSER WITH LOGIN PASSWORD '$PGPASSWORD' CREATEDB SUPERUSER;"+ provision_role "$sys_user" 'CREATE ROLE :"role" WITH LOGIN PASSWORD :'"'"'pw'"'"' CREATEDB SUPERUSER;'log "User $PGUSER created"elselog "User $PGUSER already exists"# Ensure password and superuser are set correctly (superuser needed for extension management)- psql -h "$PGHOST" -p "$PGPORT" -U "$sys_user" -d postgres \- -c "ALTER USER $PGUSER WITH PASSWORD '$PGPASSWORD' SUPERUSER;" 2>/dev/null || true+ provision_role "$sys_user" 'ALTER USER :"role" WITH PASSWORD :'"'"'pw'"'"' SUPERUSER;' 2>/dev/null || truefi# Step 4: Create portos database if it doesn't exist@@ -579,7 +589,7 @@ run_psql() {if command -v psql >/dev/null 2>&1; thenPGPASSWORD="$PGPASSWORD" psql -h "$PGHOST" -p "$PGPORT" -U "$PGUSER" -d "$PGDATABASE" "$@"elif [ "$mode" = "docker" ] && docker_running; then- docker exec -i -e PGPASSWORD="$PGPASSWORD" portos-db psql -U "$PGUSER" -d "$PGDATABASE" "$@"+ PGPASSWORD="$PGPASSWORD" docker exec -i -e PGPASSWORD portos-db psql -U "$PGUSER" -d "$PGDATABASE" "$@"elseerr "psql not found on host and Docker DB is not running"exit 1@@ -595,7 +605,7 @@ run_pg_dump() {local modemode=$(get_mode)if [ "$mode" = "docker" ] && docker_running; then- docker exec -e PGPASSWORD="$PGPASSWORD" portos-db pg_dump -U "$PGUSER" -d "$PGDATABASE" "$@"+ PGPASSWORD="$PGPASSWORD" docker exec -e PGPASSWORD portos-db pg_dump -U "$PGUSER" -d "$PGDATABASE" "$@"elif command -v pg_dump >/dev/null 2>&1; thenPGPASSWORD="$PGPASSWORD" pg_dump -h "$PGHOST" -p "$PGPORT" -U "$PGUSER" -d "$PGDATABASE" "$@"else