Close the security gaps found by the application audit
All checks were successful
Validate and deploy Sokko G / validate (push) Successful in 20m8s
Validate and deploy Sokko G / deploy (push) Successful in 10s

Imported toolboxes could run scripts on the site origin through image data
URLs, so only bitmap images are now accepted at import, display and opening.
The Cards game and its fake admin login no longer turn on when NODE_ENV is
missing, and the Node server now sends a CSP and the other security headers.

The deployment script no longer runs files owned by the service account as
root, the services cannot gain privileges through sudo, and the deployment
key stays in a single workflow step with actions pinned by commit. The script
and systemd units must still be reinstalled on the server after delivery.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Shinuwa 2026-11-06 10:55:35 +01:00
parent 1adccb4e04
commit 7046515d20
20 changed files with 233 additions and 36 deletions

View file

@ -106,3 +106,30 @@ test("the production service uses the same pinned Node runtime", async () => {
assert.match(service, /Environment=PATH=\/home\/shinuwa\/\.nvm\/versions\/node\/v24\.11\.1\/bin:/);
assert.doesNotMatch(service, /v26\.3\.0/);
});
test("the remote script never runs files owned by the service account as root", async () => {
const script = await readFile(remoteScriptPath, "utf8");
assert.match(script, /as_app_user "\$NODE_BIN" --version/);
assert.match(script, /as_app_user env PATH="\$NODE_HOME\/bin:\/usr\/bin:\/bin" "\$NPM_BIN" --version/);
assert.doesNotMatch(script, /\$\(\$NODE_BIN/);
assert.doesNotMatch(script, /\$\(env PATH=/);
assert.doesNotMatch(script, /chown -R/);
assert.doesNotMatch(script, /^\s*(?:mv .*(?:\$APP_ROOT|\$worktree|\$backup_dist)|rm -rf -- "\$APP_ROOT)/m);
});
test("the services cannot gain privileges through sudo", async () => {
for (const path of [servicePath, "ops/systemd/sokko-g-cards-backup.service"]) {
assert.match(await readFile(path, "utf8"), /^NoNewPrivileges=true$/m);
}
});
test("deployment secrets stay in one step and actions are pinned by commit", async () => {
for (const path of [deployWorkflowPath, validationWorkflowPath]) {
const workflow = await readFile(path, "utf8");
assert.equal(workflow.match(/secrets\.DEPLOY_SSH_KEY/g)?.length, 1);
assert.doesNotMatch(workflow.match(/ {2}deploy:\n[\s\S]*?\n {4}steps:/)?.[0] || "", /secrets\./);
assert.match(workflow, /- name: Configure the pinned production host key\n(?: {8}if: .*\n)? {8}env:\n {10}DEPLOY_SSH_KEY: \$\{\{ secrets\.DEPLOY_SSH_KEY \}\}/);
for (const [, reference] of workflow.matchAll(/uses: \S+@(\S+)/g)) assert.match(reference, /^[0-9a-f]{40}$/);
}
});