showcase
- v0.2.4
- 37 commits
- 1 branch
- 6 tags
- updated
- CI 2/2
security.md
8.9 KB · 117 lines
1# Security review23Step 10 of the spec. Each rule and each "done when" item maps to the code that4enforces it and the test that proves it. Run them all with `just test`.56## Spec security rules78| # | Rule | Enforced in | Tested by |9|---|------|-------------|-----------|10| 1 | Generator uses no token, so it can only see public data (one exception: an optional token for the package listing) | `gitea.Client` sets credentials only on the package listing (`tokenPath`), refuses redirects, and the builder keeps only packages linked to repos that loaded anonymously. `gitx` runs git with no prompt, no credential helper, no user config and http(s) only. A repo the API marks private is refused anyway. | `fakeGitea` fails any request that carries `Authorization` or `Cookie`; `TestOutputIsSafe`; `TestTokenOnlyForPackages`, `TestTokenNotFollowedOnRedirect` |11| 2 | One allowlist (`config.json`) | Builder iterates `cfg.Repos`. Proxy checks `HasRepo` / `HasImage`. Packages are filtered to allowlisted repos and images. | `TestSiteGolden` (missing and private repos absent), `TestProxyRoutes` (unlisted repo and image) |12| 3 | Router default is 404, with only the listed routes | `server.route` and `proxyRoute`. Dot segments, `//`, `\` and NUL are refused before any file lookup. | `TestRoutes`, `TestProxyRoutes` |13| 4 | Realm rewrite, strip `Set-Cookie` and Gitea headers, no client `Authorization`/`Cookie` on git | `newProxy` Rewrite and ModifyResponse. Only `forwardHeaders` reach Gitea, so headers it might trust (`X-WEBAUTH-USER`) can't be injected. Non-Bearer challenges are dropped too, so git never prompts. | `TestProxyRoutes`, `TestProxyResponses`, `TestProxyDropsHeaders` |14| 5 | Safe rendering | goldmark; raw HTML is never passed through, only rebuilt from an allowlist of tags and attributes (`htmlRenderer`), with links and images resolved like Markdown's and only http(s)/mailto hrefs; dangerous URLs blanked, `html/template` everywhere, highlighter escapes every token, 512 KB / binary limits, README images relative or https only | `TestSiteGolden` (forbidden strings), `TestOutputIsSafe` (no `<script`, inline `style=` or `on*=` in any page), `TestReadmeHTML` (script, handlers, styles, `javascript:`, stray closes) |15| 6 | Security headers; raw never rendered as HTML | `route` sets the CSP, `nosniff` and `no-referrer` on every response. `raw` serves allowed images, `text/plain` or an attachment. Release assets are always attachments. | `TestRoutes` (headers on every case, raw SVG and HTML are `text/plain`), `TestProxyResponses` |16| 7 | Container: non-root, read-only, no caps, no-new-privileges, only `/data` writable | `Dockerfile` (`USER 10001`, `HOME=/data`), `deploy/compose.yaml` | `hadolint`; container not yet run (see open items) |17| 8 | Trust `X-Forwarded-*` only from Pangolin | `clientIP` uses `trusted_proxies`. The proxy strips `X-Forwarded-*` and `Forwarded` toward Gitea. | `TestClientIP`, `TestProxyRoutes` |18| 9 | Cap `git-upload-pack` bodies, reject other bodies | 10 MB `MaxBytesReader`. A GET or HEAD with a body gets a 400. Proxy GET routes require no body. | `TestProxyResponses`, `TestBodyRejected` |1920## "Done when"2122| Item | Status |23|------|--------|24| `git clone https://daum.dev/<repo>.git` works and `git push` fails | Proven with real git through the server: `TestCloneAndPush`. The fake Gitea there accepts pushes, so the refusal is ours. |25| `docker pull` works anonymously and `docker push` fails | Push methods and push scopes are refused (`TestProxyRoutes`). The pull path is unit-tested but **not yet run against real Gitea**. |26| `/api/v1/…`, `/user/login`, `/daniel/<repo>` and unlisted repos are 404 | `TestRoutes`, `TestProxyRoutes` |27| A private repo in config never appears anywhere | `TestOutputIsSafe` scans every output file, raw files included. A private, missing or renamed repo is skipped. Any other error fails the whole build, so a flaky API can't publish a site with repos missing. |28| Pages pass the CSP with no console errors and need no JS | No scripts anywhere. `TestOutputIsSafe` rules out inline styles and handlers; it caught goldmark's table-alignment `style=`, which is now an `align` attribute. Fonts, CSS and avatar are same-origin. **Not yet checked in a real browser.** |2930## Fixed during this review3132- GFM table alignment rendered `style="text-align:…"`, which the CSP blocks.33 It is now an `align` attribute.34- Registry routes: blob refs must be `sha256:<64 hex>`, and manifest refs a35 valid tag or digest, so paths like `blobs/uploads` never reach Gitea.36- `WWW-Authenticate` from Gitea is passed only when it is the registry's37 Bearer challenge (with the realm rewritten). Basic challenges are dropped, so38 git and docker never prompt for credentials that would go nowhere.39- A repo is skipped only when Gitea says it's not found or private. Any other40 error fails the build and the previous one stays live.4142## Changes after the review4344- The CSP now has `script-src 'self'` for `/static/copy.js` (copy buttons).45 Inline scripts and handlers are still impossible, and `TestOutputIsSafe`46 allows exactly that one script tag and nothing else.47- Repo SVGs on `raw/` stay `text/plain` even though `/static` serves our own48 icons as `image/svg+xml` (covered by `TestRoutes`).49- The CSP now has `connect-src 'self'` (2026-11-24), so `copy.js` can fetch50 the raw file a file page's copy button copies. Requests go to this origin51 only; `img-src https:` was already a wider way out. See decisions, "Copy52 a file".5354## Second review (2026-11-23)5556After issues, comments and the package token. Read through the server,57proxy, rendering, git wrappers, builder, registry client, config, scripts,58Dockerfile and compose file.5960Fixed:6162- **Request headers to Gitea are an allowlist** (`forwardHeaders`). The63 proxy used to pass everything except `Cookie` and some `Authorization`.64 If Gitea ever had reverse-proxy login on (`X-WEBAUTH-USER`), a visitor65 could have claimed to be you. `TestProxyDropsHeaders`.66- **At most 8 concurrent git requests** go through the proxy; more get a67 503 with `Retry-After`. Upload-pack is the expensive call for Gitea, and68 anyone can start one. `TestProxyGitSlots`.69- **Registry blobs are served as downloads** (`application/octet-stream`,70 attachment), like release assets, so no layer can render as a page on71 this origin.72- **Text from strangers is capped.** Comments mean anyone with a Gitea73 account can put text on the site. Issue, pull and comment bodies are cut74 at 32 KB and a thread shows its newest 100 comments, saying how many it75 left out. `TestUserTextLimits`.7677Checked and fine: path handling (dot segments, `//` and NUL refused; tree78entries with `.`/`..`/empty segments skipped; only regular files served; no79open redirect through `base_path`), the HTML allowlist (`javascript:`80through entities, control characters or leading spaces fails URL parsing81and is dropped; the CSP blocks inline script anyway), git invocations82(`--end-of-options`, literal pathspecs, no prompts or helpers, http(s) only,83bare mirrors so no submodule or checkout hooks), registry layer reading84(64 MB compressed, 16 KB per file, streamed, 30 s timeout), the token (never85logged, never in config.json, never sent elsewhere), and the scripts86(`theme.js` only accepts `[a-z]+` from the cookie).8788## Accepted risks8990- Issue, pull, comment and release bodies can embed https images (the CSP91 allows `img-src https:`). With comments, that includes strangers'92 tracking pixels; `no-referrer` hides the page, not the visitor's IP.93- Anyone with a Gitea account can write issues and comments that show up94 here (sanitized and capped). Gitea is tailnet-only with sign-ups off, so95 that's only accounts you create.96- README headings get automatic `id`s, so a heading could share an id with97 a page element. The page's own elements come first, so `copy.js` still98 finds them; the worst case is a mis-scrolled anchor.99- A repo with a file `x` and a directory `x.html` side by side makes its blob100 pages collide, and the build fails. It only affects your own repos and101 shows up as a build error, never as wrong content.102- Builds load whole blobs (up to 50 MB) and patches into memory. That's fine103 for your own repos, but it isn't a defence against hostile repos.104105## Open items (need the real environment)1061071. Run the image on the host: read-only root, uid 10001, healthcheck.1082. `docker pull daum.dev/daniel/<image>` through Pangolin and Cloudflare.1093. Open pages in a browser and confirm there are no CSP console errors.1104. Check Gitea's settings allow anonymous reads (`REQUIRE_SIGNIN_VIEW = false`).1115. `govulncheck` v1.10.0 on 2026-11-23 (Go 1.27.4, goldmark 1.8.7, chroma112 2.27.0): no vulnerabilities found. Run it again before each release113 (`go run golang.org/x/vuln/cmd/govulncheck@latest ./...`; older114 releases crash on Go 1.27's standard library), and rebuild the image115 for new Go, Alpine and git releases (`just digests`).1166. Compose now sets `mem_limit`/`memswap_limit` 512m, `cpus` 1.0 and117 `pids_limit` 256. Watch the first builds for an OOM kill.