# Hardened the application with nonce‑based CSP

Hardened the application with nonce‑based CSP, HSTS, SameSite cookies, least‑privilege database roles and server‑side entitlement re‑checks.

2025

Situation. The platform holds professional and organizational data, the kind people expect to be handled properly, so a single line of defence was never going to be enough. The working assumption has to be that the client is hostile — that anything the browser enforces can be switched off by whoever's holding the browser — and the security has to hold up anyway.

Task. The platform had to be hardened at every layer — frontend, API, database — so that security was enforced by the server independently of whatever the interface happened to allow.

Action. On the frontend, the Next.js proxy middleware — proxy.ts — sets a Content‑Security‑Policy with a per‑request nonce and strict‑dynamic, plus HSTS and SameSite cookies, so the browser is locked down about what it'll run and send. At the API, there's rate limiting, CORS, request‑size limits, input validation before anything touches the database, and logging of the security‑relevant events. In the database, the API logs in as a least‑privilege role that can only EXECUTE the app functions, the functions run SECURITY DEFINER, and everything is parameterised. And the entitlements — tier, role, organization, ship scoping — are re‑checked on the server on every request, with the frontend gates treated as UX only. The gates decide what you see; the server decides what you can do.

Result. Security doesn't depend on the UI behaving. The protections are layered to avoid relying on a single control. Server‑side authorization is designed to operate independently of client‑side checks, so the interface is not the authority for access decisions.

Role: Security Engineer
=> /categories/platform-architecture/ Categories: Platform Architecture
=> /categories/backend/ Categories: Backend Engineering
=> /categories/frontend/ Categories: Frontend Engineering
=> /categories/api/ Categories: APIs & Integration
=> /categories/databases/ Categories: Databases
=> /categories/security/ Categories: Security
=> /services/backend-development/ Services: Backend & API Development
=> /services/security-access/ Services: Security & Access Management

=> https://software.engineer.company/portfolio/hardened-the-application-with-nonce-based-csp/ This page on the web
