Enterprise Application Security: Defending Modern Web Apps Against OWASP Top 10 and Data Breaches
Building modern SaaS and enterprise web applications demands an engineering mindset where security is treated as a fundamental non-functional requirement — just like availability, latency, or throughput. In a world of automated vulnerability scanners, credential stuffing bots, and strict statutory penalties under regulations like India’s DPDP Act 2023 (up to ₹250 Cr for failing to implement reasonable security safeguards), application security cannot be left to a checklist before launch.
In this guide, we walk through the end-to-end security architecture of a production full-stack application built with React/Next.js, Node.js/NestJS, and PostgreSQL.
1. The Defense-in-Depth Model
Security should never rely on a single perimeter wall. A resilient architecture employs Defense-in-Depth, ensuring that if an attacker bypasses one layer, subsequent layers prevent unauthorized data exfiltration:
[Edge / CloudFront / WAF] ── TLS 1.3, DDoS Mitigation, Geo-Fencing
│
[API Gateway & Rate Limiting] ── Sliding-Window Token Bucket, IP Throttling
│
[Identity & Access (OAuth/OIDC)] ── Short-Lived RS256 JWTs, Rotating Refresh Tokens, MFA
│
[Application Boundary] ── Strict Zod Runtime Validation, ORM Parameterization
│
[Data Storage & Encryption] ── Field-Level AES-256-GCM, AWS KMS Envelope Keys
│
[Audit & Telemetry] ── Immutable Event Ledger, 6-Hour Alerting Pipeline
2. Mitigating the OWASP Top 10 at Compile & Runtime
A01: Broken Access Control
Broken access control remains the #1 web vulnerability. Never trust user-supplied IDs from URL parameters or request bodies:
// VULNERABLE: Direct object reference
const invoice = await db.invoice.findUnique({ where: { id: req.params.id } });
// SECURE: Tenant-scoped authorization check
const invoice = await db.invoice.findFirst({
where: {
id: req.params.id,
organizationId: req.user.organizationId, // Enforce tenant isolation server-side
},
});
if (!invoice) throw new NotFoundException('Invoice not found');
A02: Cryptographic Failures & Field-Level Encryption (FLE)
Encrypting the whole database disk at rest (e.g. AWS RDS encryption) is necessary but insufficient. If SQL injection occurs or compromised credentials leak a database snapshot, raw PII is exposed.
For high-sensitivity fields (Aadhaar, PAN, phone numbers, banking tokens), use envelope encryption:
- Generate a plaintext data key from AWS KMS.
- Encrypt the data key with the KMS Master Key.
- Encrypt the database field using AES-256-GCM with the plaintext key and a unique Initialization Vector (IV).
- Store the encrypted data, the IV, and the encrypted data key alongside the record.
A03: Injection (SQLi, NoSQLi, Command Injection)
Always use parameterized queries through modern ORMs (TypeORM, Prisma) or raw parameterized SQL ($1, $2). Never construct SQL queries via string concatenation or template literals.
3. Hardening API Authentication with Zero Trust
- Short-Lived Access Tokens: Issue asymmetric RS256 JWTs valid for 10 to 15 minutes.
- HttpOnly, Secure, SameSite Cookies: Never store JWTs or refresh tokens in
localStorageorsessionStoragewhere malicious third-party scripts or XSS vulnerabilities can siphon them. - Sliding-Window Rate Limiting: Enforce distributed rate limits using Redis token buckets to prevent brute-force login attempts and denial-of-wallet DDoS.
4. Audit Logging & Real-Time Telemetry
When an incident occurs, you must be able to reconstruct the sequence of events without relying on volatile application logs. Maintain an immutable audit table capturing:
actor_id(who performed the action)action(e.g.INVOICE.EXPORT,USER.DELETE)resource_id&resource_typeip_address&user_agenttimestampwith microsecond precisionstate_hash(cryptographic digest preventing database tampering)
Summary
Robust application security is an engineering discipline that protects your users, defends your brand, and ensures full compliance with statutory privacy regulations.
To conduct a security audit or implement Zero-Trust safeguards across your stack, consult with Aman Kumar Singh or review our DPDP Act 2023 Technical Architecture Guide.
Key takeaways
- Defense-in-depth requires layers: Edge WAF, Zero-Trust API authentication, strict input boundaries, and field-level database encryption.
- Mitigate Broken Access Control (OWASP A01) by enforcing tenant isolation server-side in every query, never trusting client-supplied IDs.
- Implement field-level envelope encryption (AES-256-GCM + AWS KMS) for sensitive PII to safeguard data even if a database snapshot is leaked.
- Use HttpOnly, Secure, SameSite cookies with short-lived RS256 JWTs and Redis sliding-window rate limiting.
Frequently asked questions
Is disk-level database encryption enough for DPDP and OWASP?
No. Disk-level encryption protects only against physical disk theft. Compromised database credentials or SQL injection will still expose plaintext PII. Field-level encryption is required.
Where should JWT tokens be stored on the client?
In HttpOnly, Secure, SameSite cookies to protect against Cross-Site Scripting (XSS). Avoid localStorage or sessionStorage for authentication tokens.
Related articles
Explore more on
Free tools for this topic

About the author
I'm Aman Kumar Singh, a software engineer in Noida, India building scalable full-stack products with React, Next.js, Node.js, NestJS, PostgreSQL, Redis, and AWS. I write about backend engineering, distributed systems, and system design.