Skip to content

Security hardening: root middleware auth backstop, CORS for v1 API, npm CVE fixes - #12

Draft
ejay-dev with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-security-issues-github
Draft

Security hardening: root middleware auth backstop, CORS for v1 API, npm CVE fixes#12
ejay-dev with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-security-issues-github

Conversation

Copilot AI commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

Addresses remaining open findings from the March 2026 codebase security audit. The three items below were the only findings not yet remediated.

H-2 — Root middleware.ts (auth backstop)

No centralized auth enforcement existed; every route had to self-protect. Added middleware.ts at project root:

  • Page routes (/app/*, /admin/*, /onboarding/*, /workspace-recovery/*): redirects unauthenticated users to /auth/signin?next=<path>
  • API routes (/api/*): returns 401 for unauthenticated requests; explicit allowlist covers public endpoints (health, auth, billing webhook, SSO, SCIM, trust-packet, cron, debug)
  • Session refresh: uses @supabase/ssr createServerClient + getUser() on every request — prevents session spoofing via stale JWTs
  • x-verified-ip header: prefers x-real-ip/cf-connecting-ip over user-controlled x-forwarded-for, so downstream rate limiters can trust it
  • CORS preflight: handles OPTIONS /api/v1/* returning 204 directly in middleware
// Public API allowlist (no session required)
const PUBLIC_API_PREFIXES = [
  '/api/health', '/api/auth', '/api/billing/webhook',
  '/api/sso', '/api/trust-packet', '/api/scim', '/api/debug', ...
];

L-6 — CORS headers for /api/v1/ routes

The external REST API had no Access-Control-* headers, blocking browser-based integrators. Added via next.config.ts:

{
  source: '/api/v1/:path*',
  headers: [
    { key: 'Access-Control-Allow-Origin', value: '*' },
    { key: 'Access-Control-Allow-Methods', value: 'GET, POST, PUT, PATCH, DELETE, OPTIONS' },
    { key: 'Access-Control-Allow-Headers', value: 'Authorization, Content-Type, X-Requested-With' },
    { key: 'Access-Control-Max-Age', value: '86400' },
  ],
}

Wildcard origin is intentional: per the CORS spec it prevents the browser from sending cookies, so integrators must authenticate via ****** (Supabase JWT). No CSRF exposure.

npm CVEs — npm audit fix

Reduced vulnerability count from 20 → 17. Remaining 17 are all in dev-only testing tools (backstopjs, pa11y, pa11y-ci, puppeteer) that cannot be resolved without major-version breaking changes to the test toolchain; no production impact.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@vercel

vercel Bot commented Mar 13, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
forma-os Error Error Mar 13, 2026 10:45pm
formaos Error Error Mar 13, 2026 10:45pm

Co-authored-by: ejay-dev <230797402+ejay-dev@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix 23 security issues in GitHub audit Security hardening: root middleware auth backstop, CORS for v1 API, npm CVE fixes Mar 13, 2026
Copilot AI requested a review from ejay-dev March 13, 2026 22:14
ejay-dev added a commit that referenced this pull request May 13, 2026
, #14) (#87)

Three related findings from docs/audit/2026-05-13-marketing-audit.md:

- #12 MED: 20 page titles over 60 chars (Google truncates ~60)
- #13 MED: 13 meta descriptions over 170 chars (truncates ~155-160)
- #14 MED: 10 meta descriptions under 100 chars (wasted SERP)

Each rewrite mirrors the page's existing positioning - no new claims,
no scope shift. Approach per category:

- Long titles: collapse the brand suffix and the trailing qualifier
  ("Healthcare Compliance Platform - Clinical Governance &
  Accreditation | FormaOS" 78c -> "Healthcare Compliance Platform |
  FormaOS" 40c).
- Long descriptions: drop redundant trailing fluff while keeping the
  vertical-list and value claim (homepage 219c -> 151c).
- Short descriptions: expand from one-line summaries to ~130-150c
  using the page's actual content (trust/sla 89c -> 129c).

Where a page also had openGraph/twitter description overrides, both
were updated so social previews and SERP stay aligned.

Verified post-rewrite: zero titles >60, zero descriptions >170,
zero descriptions <100. tsc --noEmit clean.

Co-authored-by: ejaz <ejaz@local>
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
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.

2 participants