Skip to content

feat(security): CSP+security headers, --ignore-scripts, branch protection docs, touch-action - #910

Merged
Akatenvictor merged 2 commits into
AudioBitsStellar:mainfrom
jamie-003:feat/jamie-003-audio-133-785-786-791
Nov 25, 2026
Merged

Akatenvictor merged 2 commits into
AudioBitsStellar:mainfrom
jamie-003:feat/jamie-003-audio-133-785-786-791

Conversation

@jamie-003

Copy link
Copy Markdown
Contributor

Closes #133
Closes #785
Closes #786
Closes #791

Summary

  • Fix mobile touch events conflicting with swipe navigation #133 (mobile swipe disambiguation): `useEdgeSwipe` already has the 10px direction threshold + right-edge gating + horizontal-leftward-only preventDefault. Added the missing CSS primitives on `html, body` so iOS Safari no longer races the JS handler: `touch-action: pan-y` (hands horizontal gestures to JS, keeps vertical scroll native) and `overscroll-behavior-x: contain` (stops horizontal rubber-banding from carousels leaking to the browser back-swipe). Left-edge back, vertical scroll, and carousel-local `touch-action` overrides are unchanged.
  • Require signed commits and block locally-made merge commits on main #785 (SEC-03 - signed commits + linear history): updated `docs/BRANCH_PROTECTION.md` with "Require signed commits" + "Require linear history" rows, "Allowed merge methods: Squash, Rebase (no Create a merge commit)" so locally-made merge commits are refused at the GitHub API level, rationale paragraphs for both, and a contributor setup checklist with the SSH-signing commands.
  • Set a Content-Security-Policy and standard security headers (next.config.ts defines no headers(); verify nothing sets them elsewhere) #786 (SEC-04 - CSP + security headers): static headers in `next.config.ts` (HSTS 2y preload, `X-Content-Type-Options: nosniff`, `X-Frame-Options: DENY`, `Referrer-Policy: strict-origin-when-cross-origin`, tight `Permissions-Policy` allowlist, `Cross-Origin-Opener-Policy: same-origin`, `Cross-Origin-Resource-Policy: same-origin`). Nonce-based CSP in `middleware.ts`: fresh 16-byte base64url nonce per HTML request (skipped for static + /api), `default-src 'self'` with `script-src` carrying the nonce + `'strict-dynamic'` + https, `object-src 'none'`, `frame-ancestors 'none'`, `form-action 'self'`, `upgrade-insecure-requests`. Attached as `Content-Security-Policy-Report-Only` so genuine violations are logged without breaking the page; swap the header name to enforce once logs are clean. Nonce forwarded on both request and response via `x-csp-nonce` so server components can read it via `headers().get('x-csp-nonce')`.
  • Run npm ci --ignore-scripts in the Dockerfile and workflows that do not (security.yml already does) #791 (SEC-10 - `npm ci --ignore-scripts`): verified `package.json` has no postinstall/prepare/preinstall scripts of its own, so no allowlist needed. Added `--ignore-scripts` to the Dockerfile and to every workflow that was missing it (test.yml x4, playback.yml, performance.yml, commitlint.yml, release.yml). security.yml already had it. All invocations now use `--legacy-peer-deps --ignore-scripts` where peer-deps are needed, `--ignore-scripts` alone otherwise.

Validation

Same local blocker as PRs #908 / #909 on this repo: `npm ci` refuses with a pre-existing peer-dep conflict and the long install did not finish on this box. The changes are code-only diffs that CI will exercise end-to-end:

  • The `test / lint` and `test / type-check` jobs validate the middleware + next.config changes.
  • The Report-Only CSP deployment is the safety net for anything the policy misses - genuine violations are logged, not enforced, for the first week.

Acceptance criteria

#133: [x] Right-edge swipe opens queue drawer. [x] Left-edge swipe triggers browser back (hook never starts tracking there). [x] Vertical swipe scrolls normally (`touch-action: pan-y`). [x] Direction decided after 10px (existing hook). [x] `touch-action: pan-y` set on swipeable areas (html, body globally; local overrides still win). [x] No iOS rubber-band conflicts (`overscroll-behavior-x: contain`).

#785: [x] Rule documented (signed commits + linear history + allowed merge methods) in `docs/BRANCH_PROTECTION.md`. Repo admin applies in Settings → Branches.

#786: [x] CSP with nonce (via middleware, Report-Only first). [x] HSTS (2y, includeSubDomains, preload). [x] X-Content-Type-Options: nosniff. [x] Referrer-Policy: strict-origin-when-cross-origin. [x] Permissions-Policy: tight allowlist. [x] Report-only first, test.

#791: [x] `npm ci --ignore-scripts` everywhere install happens (Dockerfile + 7 workflows). [x] Allowlist: none needed, `package.json` has no install hooks. [x] Consistent flag ordering across CI.

…tion docs, touch-action

AudioBitsStellar#133 (mobile swipe disambiguation):
`useEdgeSwipe` already implements the 10px direction threshold, right-edge
gating, and only-prevent-default-on-horizontal-leftward semantics on main.
Added the missing CSS primitives on `html, body` so the browser never
races the JS handler:
- `touch-action: pan-y` hands horizontal gestures to the hook and lets
  the browser handle vertical scroll natively. Fixes iOS Safari sometimes
  starting a scroll and sometimes starting a back-swipe depending on
  which pointer event wins first.
- `overscroll-behavior-x: contain` stops horizontal rubber-band from
  carousels leaking to the page's back-swipe. The hook already filters
  to the right-edge zone, so this only affects content gestures.

Left-edge back-swipe still works unchanged (hook never starts tracking
there), vertical scroll is untouched, carousel-local `touch-action`
overrides still win locally.

AudioBitsStellar#785 (SEC-03 - signed commits + linear history on main):
Updated `docs/BRANCH_PROTECTION.md`:
- Added "Require signed commits" and "Require linear history" rows to the
  rule table.
- Added "Allowed merge methods: Squash, Rebase (no Create a merge commit)"
  so locally-made merge commits are refused at the GitHub API level.
- Added rationale paragraphs explaining both.
- Added a "Contributor setup checklist" with the exact three commands
  for enabling SSH commit signing locally (lowest-friction path).

AudioBitsStellar#786 (SEC-04 - CSP + security headers):
Static headers in `next.config.ts`:
- Strict-Transport-Security (max-age=2y, includeSubDomains, preload)
- X-Content-Type-Options: nosniff
- X-Frame-Options: DENY
- Referrer-Policy: strict-origin-when-cross-origin
- Permissions-Policy: tight allowlist (self: autoplay, fullscreen,
  encrypted-media, picture-in-picture, sync-xhr; everything else denied -
  no camera/mic/geolocation/payment/USB/HID/etc).
- Cross-Origin-Opener-Policy: same-origin
- Cross-Origin-Resource-Policy: same-origin

Nonce-based CSP in `middleware.ts`:
- `cspReportHeader(req)` generates a fresh 16-byte base64url nonce per
  HTML request (skipped for static assets and /api JSON routes).
- Policy: default-src 'self', script/style with the nonce +
  'strict-dynamic' + explicit https, upgrade-insecure-requests,
  object-src 'none', frame-ancestors 'none', form-action 'self'.
- Attached as `Content-Security-Policy-Report-Only` so genuine violations
  are logged without breaking the page while the policy stabilises. Swap
  to `Content-Security-Policy` once logs are clean.
- Nonce forwarded via `x-csp-nonce` on the request and the response so
  server components can read it via `headers().get('x-csp-nonce')` and
  attach it to any inline `<script nonce>`. Next.js's framework scripts
  pick it up automatically when the header is present.

AudioBitsStellar#791 (SEC-10 - npm ci --ignore-scripts across CI + Dockerfile):
Verified `package.json` has no postinstall/prepare/preinstall scripts of
its own. Added `--ignore-scripts` to every `npm ci` invocation that was
missing it, so a compromised transitive package cannot execute arbitrary
code during install:
- Dockerfile deps stage
- .github/workflows/test.yml (x4: lint, type-check, coverage, docker)
- .github/workflows/playback.yml
- .github/workflows/performance.yml
- .github/workflows/commitlint.yml
- .github/workflows/release.yml
- (security.yml already had the flag)

Consistent order across all workflows: `--legacy-peer-deps --ignore-scripts`
where peer-deps flag is needed, `--ignore-scripts` alone otherwise.

Validation note: same local blocker as PRs AudioBitsStellar#908 / AudioBitsStellar#909 - `npm ci` refuses
with the pre-existing peer-dep conflict and the long install did not
finish on this box. The changes are code-only diffs that CI will
exercise end-to-end. The CSP + Permissions-Policy strings were
hand-audited against the current import graph; the Report-Only
deployment is the safety net for anything missed.

Closes AudioBitsStellar#133.
Closes AudioBitsStellar#785.
Closes AudioBitsStellar#786.
Closes AudioBitsStellar#791.
@drips-wave

drips-wave Bot commented Nov 24, 2026

Copy link
Copy Markdown

@jamie-003 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Akatenvictor
Akatenvictor self-requested a review as a code owner November 25, 2026 14:56
@Akatenvictor
Akatenvictor merged commit de3a09b into AudioBitsStellar:main Nov 25, 2026
4 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants