How to secure a SaaS application before scaling: 7 concrete steps
By the QuantumSec team
SaaS security isn't a checklist you complete once before launch. It's an ongoing practice that needs to be built into the development cycle from day one. That said, there's a core set of measures every SaaS should have in place before it starts to scale: before its first enterprise customers, before a funding round, and before handling sensitive data in production.
Step 1: Build robust authentication in from the start
Authentication is the first line of defense. For a SaaS this means: using OAuth 2.0 with PKCE for third-party authorization, generating JWTs with strong secrets (HS256 with a minimum 256-bit key, or RS256), setting short expiry times (15-60 minutes for access tokens), rotating refresh tokens on every use (refresh token rotation), offering MFA as an option and requiring it for privileged accounts, and temporarily locking accounts after N failed login attempts. Avoid reinventing authentication: use providers like Auth0, Clerk, Supabase Auth or AWS Cognito if you don't have a dedicated security team.
Step 2: Design multi-tenant isolation into the architecture
Multi-tenant isolation can't be bolted on later without a major refactor. It has to be designed in from the start. The three main strategies are: a separate database per tenant (maximum isolation, higher cost), a separate schema per tenant in the same database (a good balance), or a shared table with tenant_id as a discriminator (higher IDOR risk if not managed carefully). Whichever strategy you use, every database query must include the tenant_id filter, verified at the service layer, not just the frontend. Implement Row Level Security (RLS) in PostgreSQL as an additional layer of protection.
Step 3: Secure every API with resource-level access control
Every endpoint in your API must verify two things: that the user is authenticated (authentication) and that they're allowed to access the specific resource requested (authorization). The second check is the one most often forgotten. Implement: tenant_id validation on every request, scopes on API tokens (not every token should be able to do everything), rate limiting per user and per tenant to prevent abuse, strict type and size validation of all input parameters, and disabling GraphQL introspection in production if you use GraphQL.
Step 4: Manage secrets and credentials correctly
Secrets must never live in source code, hardcoded environment variables in the repository, or API responses. Use a secrets manager: AWS Secrets Manager, HashiCorp Vault, Doppler or your cloud provider's equivalent. Rotate database and third-party service credentials periodically. Make sure your internal API keys have the minimum scopes necessary. Set up alerts with tools like GitGuardian or truffleHog to catch secrets accidentally committed to the repository.
Step 5: Validate and protect incoming and outgoing webhooks
If your SaaS receives webhooks from third parties (Stripe, GitHub, Slack, etc.), always validate the HMAC signature before processing the payload. If your SaaS sends webhooks to customers, sign your payloads with HMAC-SHA256 and document the signature header so customers can validate authenticity. Process webhooks asynchronously (message queue) and respond immediately with HTTP 200 to avoid retries. Implement idempotency keys to prevent duplicate event processing.
Step 6: Implement security logging and monitoring
Without logging there's no visibility, and without visibility you can't detect an attack in progress. Log: every authentication attempt (success and failure), changes to permissions and roles, access to sensitive data, authorization errors (403) with the user and resource requested, and billing operations. Centralize logs in a SIEM or at least a logging system with alerts (Datadog, Elastic, Cloudwatch). Set up alerts for anomalies: N failed login attempts, requests from unusual IPs, activity outside a tenant's normal hours.
Step 7: Run a pentest before every critical milestone
The measures above reduce risk, but they don't eliminate the possibility of undetected vulnerabilities. A SaaS-specialized pentest, run by external experts, catches the business-logic flaws, the cross-tenant IDORs and the authorization errors an internal team tends to miss. The ideal time for the first pentest is before launching to enterprise customers or before a funding round. From there, run a pentest annually or before major architecture changes.
FAQ
Is securing a multi-tenant SaaS different from securing a regular web application?
Yes, significantly. The main challenge in SaaS is tenant isolation: multiple customers share the same infrastructure and the same code. An authorization flaw in a regular web application affects one user. In a multi-tenant SaaS, the same flaw can expose every customer's data at once.
When should I run my SaaS's first pentest?
The first pentest should happen before launching to enterprise customers or, at the latest, when you have your first customers with sensitive data in production. Waiting until the system is fully built increases remediation cost because there's more code to change.
Can I use an automated scanning tool instead of a pentest?
Automated scanners (DAST, SAST) are a complement, not a substitute, for a pentest. They're good at catching known vulnerabilities like SQLi and XSS, but they don't catch business-logic flaws, cross-tenant IDORs or authorization issues specific to your data model. A manual, SaaS-specialized pentest covers what scanners can't.