Implementing least privilege and safe event handling in serverless functions
Implementing least privilege and safe event handling in serverless functions connects a security requirement to the behaviour of a real feature. The relevant controls need to remain effective across custom code, integrations and the production configuration. Understanding least privilege and safe event handling in serverless functions helps establish which security property the feature needs and where that property is actually enforced.
What does this involve?
Configuration can change an application's security boundary without changing its business code. Effective production values, inherited defaults, exposed services and operational interfaces need to be assessed together rather than as isolated files.
Serverless computing (Functions as a Service — FaaS) platforms such as AWS Lambda, Azure Functions, and Google Cloud Functions simplify application development and scaling. However, the execution model (short-lived, event-driven functions running in managed environments) introduces unique security risks compared to traditional architectures.
For AWS Lambda, use code signing configurations with allowed signing profiles and UntrustedArtifactOnDeployment set to Enforce; the default Warn setting allows deployments that fail expiry, publisher, or revocation checks. Layers added to functions with code signing enabled must also be signed by an allowed profile.
Why it matters
Consider a realistic failure: a serverless function runs with broad cloud permissions and accepts events from an unintended source.
A permissive setting can expose private information or administrative capabilities through a route the application owner did not expect. The consequence depends on how the service is actually deployed and which identities can reach it.
Implementation guidance should be applied to a real feature and its deployment. Framework defaults, custom handlers and integrated services all influence whether the intended protection remains effective.
How penetration testers check for it
Trace the relevant feature from its entry point to the data or operation it protects, including custom code and alternate paths.
- Review effective production settings and inherited defaults.
- Identify exposed management and diagnostic interfaces.
- Trace secret and connection configuration to its use.
- Compare configured policy with observed behaviour.
How to fix it
Use the appropriate maintained mechanisms and verify the result in the actual production configuration.
- Scope database/API keys to the smallest set of actions needed.
- Disable default network access unless required (e.g. outbound internet access).
- Enforce authentication and authorisation on all triggers (API Gateway, Pub/Sub, S3, IoT).
- Validate function-to-function calls with signed tokens or workload identities.
- Protect secrets and remove unnecessary diagnostic exposure.
- Check configuration drift during deployment and maintenance.
A setting should be interpreted in its environment. A deliberately public resource and an unintended private exposure can look similar until ownership, purpose and reachable operations are established.
Recheck the changed behaviour against the original failure conditions and the legitimate user journey. Keep enough evidence to show which release and configuration were verified, and include related entry points that depend on the same security decision.
Related issues
- Implementing authenticated and least-privilege MCP services
- Implementing safe error responses and exception handling
- Configuring application database access with least privilege
Read about our methodology or contact pentested.com to discuss secure development and code review.