Skip to main content
CriticalCodeOWASP A07:2021CWE-798

How to fix: Hardcoded AWS credentials in @aws-sdk

Patterns like new S3Client({ accessKeyId: 'AKIA...', secretAccessKey: '...' }) embed long-lived IAM keys directly into source. Once the source is logged or committed, the keys are compromised.

Why it matters

Leaked keys grant whoever holds them the same AWS permissions as the application, including S3, IAM, and STS.

The `code-cloud-aws-hardcoded-credentials` check verifies that the server does not expose the `cloud-aws-hardcoded-credentials` weakness in the code category. The detection runs against the response headers, body, or auxiliary probes (DNS, TLS, async fetch) as appropriate.

How to fix it

  1. 1Remove hardcoded keys; let the SDK pull credentials from the environment, IAM role, or SSO.
  2. 2Rotate the exposed credentials immediately and audit CloudTrail for misuse.
  3. 3Adopt short-lived STS tokens via AssumeRole with web identity or OIDC.

Code examples

Use IAM roles instead of hard-coded credentials

TypeScript
import { S3Client } from "@aws-sdk/client-s3";

// BAD: hard-coded credentials in source
// const s3 = new S3Client({ credentials: { accessKeyId: "AKIA...", secretAccessKey: "..." } });

// GOOD: SDK reads credentials from environment / IAM role automatically
const s3 = new S3Client({ region: "us-east-1" });
// On EC2/Lambda/ECS: attach an IAM role, no credentials needed in code

References

Detected automatically by VulnRadar. The check id is code-cloud-aws-hardcoded-credentials, stable across every scan so you can filter or diff on it.

See every code check

Questions

How severe is Hardcoded AWS credentials in @aws-sdk?
VulnRadar rates this critical severity in the code category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
Does VulnRadar check for this automatically?
Yes. It runs as part of every scan under the check id code-cloud-aws-hardcoded-credentials, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does Hardcoded AWS credentials in @aws-sdk map to?
It maps to CWE-798. In the OWASP Top 10 it falls under A07:2021.

Missing a check?

The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.

Propose a checkHow a check is built

Scan your own site for hardcoded aws credentials in @aws-sdk

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

Hardcoded AWS credentials in @aws-sdk fix | VulnRadar