Skip to content

Hardening: multi-stage Docker build + .dockerignore#8

Open
bencao wants to merge 1 commit into
masterfrom
hardening/low-findings-0605
Open

Hardening: multi-stage Docker build + .dockerignore#8
bencao wants to merge 1 commit into
masterfrom
hardening/low-findings-0605

Conversation

@bencao

@bencao bencao commented Jun 5, 2026

Copy link
Copy Markdown
Owner

Summary

Two low/informational security-hardening improvements for this client-side Vite game.

1. [LOW] Dockerfile shipped the entire repo to the nginx web root

The previous Dockerfile was FROM nginx + COPY . /usr/share/nginx/html, which served raw src/, docs/, package*.json, *.psd design files, etc. to the public web root — and was also broken, since it served un-built ES modules.

Change: converted to a multi-stage build.

  • Stage 1 (node:20-alpine): npm ci && npm run build.
  • Stage 2 (nginx:alpine): COPY --from=build /app/dist /usr/share/nginx/html — only the Vite build output (Vite outDir is dist, confirmed in vite.config.js).
  • Added .dockerignore excluding node_modules, .git, docs, test, *.psd/*.ai, env files, and the Docker files themselves to keep the build context minimal.

2. [INFO] Debug window.* assignments in src/bootstrap.js

Removed the debug-only global assignments (window.game, window.welcome_scene, etc.). They are referenced nowhere else in src/, test/, or index.html (verified by grep); kick_off() runs on the local game const, so removal is safe. No security impact — this is cleanup, included since it was low-risk.

Verification

npm run build (output dir is dist/):

> vite build
vite v6.4.2 building for production...
✓ 35 modules transformed.
dist/index.html                   1.66 kB │ gzip:  0.67 kB
dist/assets/tanks-DP0YTXMF.png   14.36 kB
dist/assets/index-BON_680t.js   136.66 kB │ gzip: 29.98 kB
✓ built in 155ms

npm test: 121/121 passing (11 files).

docker build succeeds, and the resulting nginx web root contains only built assets (no source/docs/psd):

/usr/share/nginx/html:
50x.html  assets  data  favicon.ico  index.html  vendor
/usr/share/nginx/html/assets:
index-BON_680t.js  tanks-DP0YTXMF.png

(50x.html is nginx's own default error page from the base image.)

🤖 Generated with Claude Code

[LOW] The previous Dockerfile (FROM nginx + COPY . /usr/share/nginx/html)
shipped the entire repo to the nginx web root, exposing raw source (src/),
docs, package*.json, *.psd design files, etc., and was also broken because it
served un-built ES modules.

- Convert Dockerfile to a multi-stage build: stage 1 (node:20-alpine) runs
  `npm ci && npm run build`; stage 2 (nginx:alpine) copies only the Vite
  build output (`COPY --from=build /app/dist /usr/share/nginx/html`).
- Add .dockerignore excluding node_modules, .git, docs, test, *.psd/*.ai,
  env files, and Docker files to keep the build context minimal.

[INFO] Remove debug-only `window.*` game-object assignments in
src/bootstrap.js. They are referenced nowhere else (kick_off runs on the
local `game` const) so removal is safe; no security impact, just cleanup.

Verification: `npm run build` succeeds (outDir `dist/`), `npm test` 121/121
pass, and `docker build` produces a web root containing only built assets
(index.html, assets/, data/, vendor/) with no source/docs/psd.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 5, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
fc-tank-infq Ready Ready Preview, Comment Jun 5, 2026 7:09am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant