Serverless security explained in plain terms is the work of protecting applications that run as short-lived functions on infrastructure somebody else manages, where there is no server of your own to patch or harden. The central question is whether removing servers removes security work, and the short answer is no: it moves the work, from operating systems and networks to functions, permissions, triggers and the code that connects them.
Serverless computing lets teams run code without provisioning or managing servers. A function runs when an event triggers it, such as an HTTP request or a file upload, and stops when it finishes. The cloud provider handles the servers, the operating system and the scaling. That removes a whole class of security chores, but it creates new ones, because the application is now a collection of small functions, each with its own permissions and each reachable through events. Our guide to serverless computing explains how the model works and why teams adopt it.
Key takeaways
- Serverless removes the server, not the security work: the provider secures the infrastructure, while the team secures functions, permissions and events.
- Functions are short-lived and event-driven, which limits how long an attacker can hold a foothold, but each function is a new entry point.
- Over-permissive function roles are the most common serverless weakness, because one compromised function can reach everything its role allows.
- Event injection is the serverless version of injection: malicious data arriving through a trigger can make a function act on it.
- Defence combines least privilege, input validation, secret management, logging and monitoring of every trigger.
What serverless security means
Serverless security covers the parts of a serverless application that the cloud provider does not secure for you. The provider is responsible for the physical hardware, the host operating system, and the runtime that executes functions. The team is responsible for everything else: the function code, the permissions, the data access, the APIs and the secrets.
This division of responsibility is often called the shared responsibility model, and it applies to every cloud service, not only serverless. The difference with serverless is how much of what remains is made of small, fast-moving pieces: a serverless application can have dozens of functions, each wired to several event sources, each with its own role and configuration. The attack surface is not smaller; it is differently shaped.
The shared responsibility model
Understanding who secures what is the first step. The provider patches the host, isolates functions from each other, and keeps the runtime up to date. The team must still write secure code, configure permissions correctly, protect secrets, and watch for abuse. A common mistake is assuming that because the provider manages the servers, the application is secure by default. It is not: a function with a role that can read every database table, or an API with no authentication, is insecure regardless of who manages the hardware.
The provider’s isolation is real but not absolute. Functions run in separate execution environments, and one function’s failure does not normally affect another. But if the compromised function’s role grants access to shared resources, such as a database or a storage bucket, the attacker can still cause serious harm through the permissions the team granted, not through any weakness in the provider’s isolation.
Function permissions and least privilege
The most important serverless security control is the permission each function holds. Every function runs with a role that says what it may do: which databases it can read, which storage buckets it can write to, which other functions it can call. If a function only needs to read one table, its role should allow exactly that and nothing more. This is least privilege, and it matters more in serverless than anywhere else, because each function is a separate trust decision.
In practice, teams often grant broad permissions because it is faster: a role that allows full access works for every function, so it gets copied until the whole application runs with the same over-broad role. That turns a single compromised function into a compromise of everything. The fix is to give each function its own narrow role, and to review roles regularly, because functions gain permissions as features are added and rarely lose the old ones. Our guide to cloud security covers the identity and access controls that serverless permissions build on.

Event injection and untrusted triggers
Serverless functions run when something triggers them: an HTTP request, a file arriving in storage, a message on a queue, a database change. Each trigger is an entry point, and each one can carry data an attacker controls: a file upload can contain a malicious name or crafted metadata, a queue message can contain a payload designed to confuse the function that reads it, and an HTTP request can carry the same injection attacks that have always targeted web applications.
The defence is to treat every event as untrusted input, no matter which trigger delivered it. Functions should validate the shape and content of incoming data, reject anything unexpected, and never pass event data directly into a database query, a shell command, or another service without checking it first. Functions should also fail safely: if an event is malformed, the function should log the problem and stop, rather than guessing what the event meant.
Comparing the main serverless risks
| Risk | Target | Typical harm | Main defence |
|---|---|---|---|
| Over-broad function roles | Permissions | One compromise reaches everything | Least privilege per function |
| Event injection | Triggers and payloads | Malicious data drives actions | Validate every event |
| Exposed APIs | HTTP triggers | Unauthenticated access | Authentication and throttling |
| Secrets in code | Credentials and keys | Keys leaked or stolen | Secret manager, never hard-coded |
| Denial of wallet | Billing and scaling | Attacker drives up the bill | Concurrency limits and alerts |
Secrets, dependencies and the supply chain
Functions need secrets: database passwords, API keys, tokens for other services. Those secrets must never be written into function code or stored in plain text in configuration. They belong in a secret manager, which stores credentials securely and hands them to a function at runtime. A secret that appears in code can leak through version control or logs, and once exposed it must be treated as compromised and replaced.
Functions also depend on libraries, and those libraries can contain vulnerabilities. Teams should scan dependencies regularly, update them when fixes appear, and keep the number of dependencies small, because each one is code the team did not write and cannot fully inspect. Supply chain attacks, in which a compromised library is used to attack the applications that depend on it, are a real risk, and serverless applications can accumulate many dependencies quickly. Our guide to supply chain attacks explains how these attacks work and how to defend against them.
Denial of wallet and runaway costs
Serverless platforms scale automatically, which is a strength and a risk. If an attacker can trigger a function repeatedly, the platform will keep running it, and the bill will keep growing. This is sometimes called denial of wallet: the attack does not take the application down, it makes it expensive. A function triggered by a public API or public uploads is exposed to this risk, because anyone can generate the events that cause it to run.
The defences are limits and alerts. Concurrency limits cap how many copies of a function can run at once, and throttling limits how often an API can be called. Billing alerts warn the team when spending rises unexpectedly, so a runaway cost is caught in hours rather than at the end of the month. Rate limiting and authentication on public triggers stop most abuse before it starts.
Logging, monitoring and incident response
Serverless functions are short-lived, which makes investigation harder: a function that ran for two seconds and then disappeared leaves only its logs behind. If those logs are thin, an incident becomes very hard to reconstruct. Teams should log every invocation that matters, including the trigger, the input that arrived, and the actions the function took, without logging secrets or sensitive personal data.
Monitoring should watch for the signals of an attack: a sudden rise in invocations, a spike in errors, functions accessing resources they rarely touch, or a function running far longer than usual. Incident response for serverless is mostly about permissions and triggers: disabling a compromised function’s role, blocking a malicious source, and revoking any secret that may have leaked. Because functions are small and replaceable, recovery is often faster than with a traditional server.
What good practice looks like
Good serverless security starts with an inventory of every function, trigger, permission and secret. A team that cannot list its functions cannot secure them. From that inventory, the team applies least privilege to each function, validates every event, stores secrets in a secret manager, and sets limits on public triggers. Dependencies are scanned and updated, and logging is turned on for everything that matters.
Good practice also means testing security, not just assuming it. Teams should try to call their own functions with malicious input, test what a function can reach with its role, and check that billing alerts actually fire. Serverless security is not a one-time setup: functions are added, permissions grow, and triggers change, so the review must happen regularly.
Serverless security checklist
- List every function, trigger, permission and secret in the application before securing anything.
- Give each function its own narrow role, allowing only the resources it actually needs.
- Validate every event payload, no matter which trigger delivered it, and fail safely on malformed input.
- Require authentication on public APIs and add throttling to limit abuse.
- Store all secrets in a secret manager, never in code or plain-text configuration.
- Scan function dependencies regularly and update libraries with known vulnerabilities.
- Set concurrency limits and billing alerts to catch denial-of-wallet attacks early.
- Log invocations, inputs and actions, never secrets or sensitive personal data.
- Review roles and triggers regularly, because permissions grow as features are added.
Frequently asked questions
Is serverless more secure than traditional servers?
Serverless removes some risks, such as unpatched operating systems, because the provider manages the servers. It does not remove security work: functions, permissions, triggers and secrets still need securing, and a serverless application can have more entry points than a traditional one.
What is the biggest serverless security risk?
Over-broad function permissions are the most common weakness. A function whose role allows access to every database and storage bucket turns a single compromise into a compromise of the whole application. Least privilege, applied per function, is the most important defence.
What is denial of wallet?
Denial of wallet is an attack in which someone triggers a serverless function repeatedly so that the platform keeps running it and the bill grows. Concurrency limits, throttling, authentication and billing alerts are the main defences.
Do serverless functions need input validation?
Yes. Every event that triggers a function can carry data an attacker controls, whether it arrives by HTTP, file upload, queue message or database change. Functions should validate every event and never pass event data into queries or commands unchecked.
Where should serverless secrets be stored?
Secrets belong in a secret manager, a service that stores credentials securely and supplies them to a function at runtime. They should never be written into function code or stored in plain text in configuration.
How do you investigate an incident in a serverless application?
Through logs, because the functions themselves are gone by the time an incident is noticed. Teams should log invocations, triggers, inputs and actions, and monitor for unusual patterns such as invocation spikes. Good logging is what makes serverless incidents possible to reconstruct.
The bottom line
Serverless security explained in one line is this: the provider secures the servers, but the team still secures everything that makes the application theirs: narrow permissions, validation of every event, secrets kept out of code, limits on public triggers, and logging that makes incidents possible to reconstruct.







