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

@ -1,4 +1,5 @@
// Rôle : vérifie les en-têtes de cache du serveur Node sur des fichiers de production représentatifs.
import { createHash } from "node:crypto";
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { dirname, join } from "node:path";
@ -97,3 +98,27 @@ test("stable files can be revalidated with an ETag while no-store and immutable
assert.equal((await fetch(url("/"))).headers.get("etag"), null);
assert.equal((await fetch(url("/assets/index-Ab12_cd34.js"))).headers.get("etag"), null);
});
test("every response carries the security headers and the CSP allows only the inline script of the build", async (t) => {
const root = await mkdtemp(join(tmpdir(), "sokko-server-headers-"));
const inlineScript = "console.log('recovery');";
await writeFixture(root, "index.html", `<script>${inlineScript}</script><script type="module" src="/assets/a.js"></script>`);
const server = createStaticServer({ root, publicRoot: root });
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
t.after(async () => {
await new Promise((resolve, reject) => server.close((error) => error ? reject(error) : resolve()));
await rm(root, { recursive: true, force: true });
});
for (const path of ["/", "/missing.js"]) {
const { headers } = await fetch(`http://127.0.0.1:${server.address().port}${path}`);
const csp = headers.get("content-security-policy");
assert.ok(csp.includes(`script-src 'self' 'sha256-${createHash("sha256").update(inlineScript).digest("base64")}';`), csp);
assert.doesNotMatch(csp, /script-src[^;]*unsafe/);
assert.match(csp, /frame-ancestors 'none'/);
assert.equal(headers.get("x-content-type-options"), "nosniff");
assert.equal(headers.get("x-frame-options"), "DENY");
assert.match(headers.get("strict-transport-security"), /^max-age=\d+$/);
assert.ok(headers.get("referrer-policy"));
}
});