Skip to content

[M2.2e4a] Serve browser assets with strict CSP and same-origin identity - #72

Merged
samuelmbabhazi merged 1 commit into
mainfrom
feat/m2.2e4a-serve-web
Nov 5, 2026
Merged

samuelmbabhazi merged 1 commit into
mainfrom
feat/m2.2e4a-serve-web

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

Production now serves the Angular build from the API process, matching ADR 0009 and keeping cookie/CSRF requests on one origin. The default directory is dist/apps/web/browser; WEB_DIST_DIR supports packaged layouts. Missing/invalid builds fail startup with opaque diagnostics and close the application. The OpenAPI-only generator still needs no web build.

Serving uses a bounded startup snapshot of public asset types, with no request-time filesystem path resolution. API paths, dotfiles, maps, metadata and traversal targets never become SPA responses. Hashed bundles are immutable; index HTML is no-store with a fresh CSP nonce. Inline build scripts/styles are disabled, and the web CSP allows same-origin assets, nonce-bound component styles and Angular's reviewed Trusted Types policies.

Validation: API/web lint, typecheck, tests and builds pass (102 API unit tests, 50 Angular tests). Five new real-HTTP tests cover nonces/cache headers, GET/HEAD navigation, API boundaries, forbidden files/traversal, snapshots, symlinks and size limits. The actual production index contains no inline script/style and retains its nonce placeholder. Real-browser CSP/identity acceptance follows in M2.2e4b. No new dependency.

The development example/docs now use the actual browser origin on port 4200; existing .env files must update that setting as documented. Stacked on #71. This PR stays draft until browser acceptance; no merge requested.

  • M2.2e4a service/configuration criteria
  • HTTP security regressions and production builds
  • Plan/spec/development instructions updated
  • Real-browser CSP and identity acceptance (M2.2e4b)

@samuelmbabhazi
samuelmbabhazi force-pushed the feat/m2.2e3d-token-screens branch from ee2d72f to f60fd32 Compare November 5, 2026 12:41
@samuelmbabhazi
samuelmbabhazi changed the base branch from feat/m2.2e3d-token-screens to main November 5, 2026 12:41
@samuelmbabhazi
samuelmbabhazi marked this pull request as ready for review November 5, 2026 12:41
@samuelmbabhazi
samuelmbabhazi merged commit d3000e3 into main Nov 5, 2026
9 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the feat/m2.2e4a-serve-web branch November 5, 2026 12:42
samuelmbabhazi added a commit that referenced this pull request Nov 5, 2026
## Task

[M2.2e4b1] Real-browser identity acceptance. Stacked on #72; review the
prerequisite stack before merging. No merge requested.

## What changed and why

The production Angular build normalizes `ngCspNonce` to lowercase and
copies its placeholder onto generated script/style tags. The server
previously rejected that real build at startup. Accept the normalized
attribute and replace every placeholder with the same fresh per-response
nonce; retain strict CSP and add a focused HTTP regression test.

Add `pnpm test:browser` and a CI job running pinned Chromium against
production assets and a real Nest API, disposable PostgreSQL, and local
TLS SMTP. The suite covers all six public forms, signup → delivered
verification code → login → logout, secure session/CSRF cookies,
missing-CSRF and foreign-Origin rejection, empty browser storage,
secret-free navigation URLs, strict CSP execution, error focus,
automated WCAG rules, and horizontal overflow at 320/390/768/1024/1440
pixels. Account security receives an automated accessibility check after
login.

## How it was tested

- Chromium: both acceptance scenarios pass against real HTTPS,
PostgreSQL and SMTP.
- Workspace lint, typecheck and TypeScript tests: all seven projects
pass, including 103 API unit tests and 50 Angular tests.
- API integration: 84 tests across 19 files pass with disposable
databases and Nx dotenv loading disabled.
- Production API/web builds, Go tests, `buf lint`, formatting and `git
diff --check` pass.
- Commit hooks pass, including gitleaks. CI status is reported by the
checks; CodeQL is currently skipped by the repository workflow.

## Security considerations

The browser fixture always creates its own database, including when a
developer `DATABASE_URL` is inherited. It restores overridden
environment values, shuts down resources in reverse order and sends mail
only to the loopback TLS fixture. Self-signed HTTPS acceptance is
confined to the isolated browser context. Browser requests to other
origins are blocked. No traces, HAR files or screenshots are recorded;
private fill failures and accessibility assertions avoid serializing
credentials. No new product mutation or audit path is introduced.

Development-only dependencies: Playwright 1.64.1 (Apache-2.0) and
@axe-core/playwright 4.14.0 (MPL-2.0), pinned in manifests and lockfile.

Password-reset, MFA/recovery and token-management browser workflows,
failure/retry/private-grant checks, manual visual/accessibility
inspection and design documentation remain explicitly unchecked in PLAN
M2.2e4b2/M2.2e4c. Automated accessibility checks do not establish full
WCAG conformance. This is the final PR in the current work session, as
requested.

## Checklist

- [x] M2.2e4b1 acceptance criteria met and marked in PLAN
- [x] Lint, TS tests, Go tests and `buf lint` pass locally
- [x] Browser security rejection checks and production-build regression
added
- [x] No new shell invocation or secret exposure path
- [x] Existing audited state-changing paths exercised without
modification
- [x] README documents execution, isolation and remaining coverage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant