Skip to content

[M2.2e4b1] Verify browser identity and fix generated CSP nonces - #73

Merged
samuelmbabhazi merged 2 commits into
mainfrom
feat/m2.2e4b1-browser-fixture
Nov 5, 2026
Merged

samuelmbabhazi merged 2 commits into
mainfrom
feat/m2.2e4b1-browser-fixture

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

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

  • M2.2e4b1 acceptance criteria met and marked in PLAN
  • Lint, TS tests, Go tests and buf lint pass locally
  • Browser security rejection checks and production-build regression added
  • No new shell invocation or secret exposure path
  • Existing audited state-changing paths exercised without modification
  • README documents execution, isolation and remaining coverage

@samuelmbabhazi
samuelmbabhazi changed the base branch from feat/m2.2e4a-serve-web to main November 5, 2026 12:41
@samuelmbabhazi
samuelmbabhazi force-pushed the feat/m2.2e4b1-browser-fixture branch from 2e487b1 to b06200d Compare November 5, 2026 12:42
@samuelmbabhazi
samuelmbabhazi merged commit 9b9269e into main Nov 5, 2026
10 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the feat/m2.2e4b1-browser-fixture branch November 5, 2026 12:42
samuelmbabhazi added a commit that referenced this pull request Nov 5, 2026
)

## Task

[M2.2e4b2] Browser acceptance for account security, stacked on #73. No
merge requested.

## What changed and why

An uncertain token creation followed by HTTP 429 released the original
idempotency key. A subsequent retry could create a second token.
Preserve that key through rate limiting while enforcing Retry-After and
the existing four-minute replay window. A failing unit regression
reproduced the key change before the fix; a browser scenario now drops a
real committed response, throttles the retry, and verifies one token and
an actual server replay.

Extend the isolated Chromium suite with password reset and code reuse
rejection; invalidation of other sessions and earlier API tokens;
TOTP/recovery login; single-use/replaced recovery codes; token creation
and revocation; private-display expiry; concurrent security-write
prevention; and late-result suppression after leaving the route.
Independent browser contexts verify session rotation against the real
backend. Add automated accessibility checks for populated and error
states, plus an injection-shaped token name.

The recovery-code grid previously used a viewport breakpoint that
squeezed two columns into the narrower tablet content area. Size the
columns from the available container width instead. Browser measurements
now pass at 320, 390, 768, 1024 and 1440 pixels; sanitized local
captures confirm the layout at mobile/tablet/desktop widths.

## Validation

- Six Chromium scenarios pass against HTTPS, real PostgreSQL and TLS
SMTP.
- API/web lint, typecheck and production builds pass; 103 API and 51
Angular unit tests pass.
- Go tests, `buf lint`, formatting, diff checks and gitleaks commit
hooks pass.
- API integration: all 84 tests across 19 files pass on disposable
PostgreSQL databases.

## Security considerations

No backend authorization, throttling, audit or credential policy is
weakened. Fault injection operates at the browser transport around
actual committed requests; backend services remain real. Browser time
advances only to verify temporary-display expiry, without changing
server time. Assertions compare booleans/counts or hashes rather than
printing private grants, and private fill failures remain opaque. Tests
create no traces, HAR files or screenshots. No new dependency.

M2.2e4b is complete. Manual visual/accessibility inspection, independent
finish review and design-system documentation remain in M2.2e4c; this PR
does not claim full WCAG conformance or completion of M2.2 as a whole.
CodeQL remains skipped by the repository workflow; enabled CI checks are
reported below.

## Checklist

- [x] M2.2e4b2 criteria covered and PLAN updated
- [x] Lint, TS tests, Go tests and `buf lint` pass locally
- [x] Regression tests exercise the retry bug and recovery-code overflow
- [x] No new shell invocation or secret exposure path
- [x] Existing audited command paths exercised without modification
- [x] Retry semantics and test coverage documented in SPEC/README
samuelmbabhazi added a commit that referenced this pull request Nov 5, 2026
…94)

## Task

Review follow-up for #73 (M2.2e4b1). Refs #21

## What changed

- `apps/api/src/testing/postgres-image.ts` exports
`POSTGRES_TEST_IMAGE`, the same digest-pinned
`postgres:17@sha256:3b0cda93…` used by the CI service container and
`deploy/dev/compose.yml`.
- The eight Testcontainers call sites (browser/integration app helper
and seven integration specs) use it instead of the mutable `postgres:17`
tag.
- A unit test asserts the constant is digest-pinned and identical to the
reference in `.github/workflows/ci.yml` and `deploy/dev/compose.yml`, so
the three cannot drift.

## Why

THREAT_MODEL requires every tool image to be pinned to a digest. The
browser acceptance job and local integration runs pulled `postgres:17`
by tag, which a retagged or compromised upstream image could replace.

## How it was tested

- `nx run-many -t lint typecheck test -p api` in a clean worktree: 22
files, 105 tests pass, lint and typecheck clean.
- Integration and browser jobs could not run: GitHub Actions is
currently blocked by the account spending limit, and Docker is not
available in the local sandbox. CI must pass before merge.

## Security considerations

Supply-chain hardening of test infrastructure only. No runtime change.

## Checklist

- [x] Lint, TS tests pass locally
- [x] Test added (pin consistency)
- [x] No new shell invocation and no new secret exposure path
- [x] Audit events: not applicable
- [ ] CI green (blocked by billing)
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