Secrets in Lambda Environment Variables

Lambda functions hold passwords, API keys or other secrets in environment variables, where anyone able to read the function's configuration sees them in clear text.

SeverityMedium
CVSS 3.16.5 CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N Open in the calculator
CVSS 4.07.1 CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:H/VI:N/VA:N/SC:N/SI:N/SA:N Open in the calculator
CWECWE-526: Cleartext Storage of Sensitive Information in an Environment Variable
OWASP Top 10A02:2025 Security Misconfiguration
MITRE ATT&CKT1552 Unsecured Credentials
CategoryInformation Disclosure

Description

Lambda environment variables are a convenient place for configuration, and are often used for database passwords, API keys, signing secrets and tokens for third-party services. Lambda encrypts them at rest, with an AWS managed key unless a customer managed key is set, but returns them decrypted to anyone who can read the function's configuration and, where a customer managed key is set, is allowed to decrypt with it: lambda:GetFunctionConfiguration and lambda:GetFunction return them in clear text, the Lambda console displays them, and they are usually also present in the infrastructure code, templates and pipelines that deploy the function.

Read access to function configuration is widely granted, including through broad read-only roles given to developers, support staff, auditors and monitoring tools. Inside the function, the values are ordinary process environment variables, so a code injection, path traversal or similar flaw that can read the environment (for example /proc/self/environ) also discloses them.

Whoever obtains the secrets in either way can use them directly against the systems they protect, such as databases, payment providers, email services or other APIs, usually from anywhere and without further authentication. Those systems often sit outside AWS's own access controls and logging, so their misuse may go unnoticed. The impact depends on what the secrets unlock, and is greater where the same secrets are shared across environments or functions.

The issue is identified by reviewing function configurations with aws lambda get-function-configuration or aws lambda list-functions, and with secret scanners. Prowler checks Lambda environment variables for secrets.

Remediation

Move secrets out of environment variables and into a secrets store:

  • Store secrets in AWS Secrets Manager or as SecureString parameters in Systems Manager Parameter Store, and retrieve them at runtime, for example with the AWS Parameters and Secrets Lambda Extension, which caches values to limit API calls.
  • Allow each function's execution role to read only its own secrets, and restrict who can read or change those secrets.
  • Rotate every secret that has been held in an environment variable, since it must be assumed to have been seen by everyone with read access to the function.
  • Where an environment variable must still hold a sensitive value, encrypt it with a customer managed KMS key before deployment and decrypt it in the function code, so that the console and API show only ciphertext.
  • Limit lambda:GetFunctionConfiguration and lambda:GetFunction to those who need them, and add secret scanning to deployment pipelines.

Confirm the fix by reviewing each function's configuration again and checking that no secrets remain in its environment variables or in the infrastructure code that deploys it.

References


Add This Finding to Your Library

In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.

Free trial  ·  No card required

Only need the reporting? Our reporting tool is free and open source, with the same library.


More AWS Findings

Every AWS finding