Hardcoded Credentials

Use of Hard-coded Credentials

CWE-798 · Critical severity · Updated November 6, 2026

What it is

CWE-798 exists when credentials (API keys, database passwords, signing keys, encryption keys, OAuth secrets) are embedded in source code or configuration files committed to version control. Anyone who reads the code, decompiles a binary, or accesses the version-control history obtains the credential.

Why it matters

Hardcoded credentials are the single most common cause of accidental key exposure. Public GitHub repositories are continuously scanned by both defenders and attackers; an AWS key committed to a public repo is typically abused within minutes. Even private repositories are at risk: every employee with read access has the secret, and any historical leak (laptop loss, contractor offboarding) exposes the credential indefinitely. PCI DSS prohibits hard-coded passwords for application and system accounts that can be used for interactive login (Req 8.6.2).

Common patterns

  • AWS access key (AKIA...) or secret access key committed to a config file, even if rotated immediately.
  • Stripe, GitHub, Slack, OpenAI, or Anthropic API keys in .env files committed to git.
  • Database connection strings with embedded passwords in src/config.ts or application.properties.
  • JWT signing secrets defined inline in source rather than loaded from a secret manager.
  • OAuth client secrets in mobile-app bundles (recoverable by anyone who downloads the app).
  • SSH private keys checked into infrastructure-as-code repositories.

Languages affected

JavaScript, TypeScript, Python, Ruby, Java, Go, PHP, C#, YAML, JSON

What Deva detects

Deva includes high-confidence regex detectors for AWS access key IDs, Google API keys, GitHub personal access tokens (ghp_), Slack tokens (xox), Stripe live keys (sk_live_), and private key headers, plus a rule for passwords assigned in code. The scanner can run on save in the editor extension and as a CI step via the deva CLI, so secrets can be caught before they reach a commit.

Example

Vulnerable

import boto3

# Connect to AWS for backups
s3 = boto3.client(
    's3',
    aws_access_key_id='AKIAIOSFODNN7EXAMPLE',
    aws_secret_access_key='wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY',
    region_name='us-east-1',
)

Fixed

import os
import boto3

# Credentials are loaded automatically from environment variables, IAM role,
# IRSA (Kubernetes), or EC2 instance profile. None of these require code changes.
s3 = boto3.client('s3', region_name=os.environ.get('AWS_REGION', 'us-east-1'))

The vulnerable version embeds the AWS access key and secret directly in code. The credential is now in every clone of the repository, every CI build log that prints it, and every developer's laptop. The fix lets boto3 use its standard credential chain: environment variables, IAM role on EC2 / ECS / Lambda, IRSA on EKS, or a profile in ~/.aws/credentials. Secrets live in the deployment environment, not in source. For local development, use direnv or doppler with a secrets manager backend, not committed .env files.

Where this fits in OWASP Top 10

Compliance framework references

These references explain how the weakness relates to control topics. They do not mean Deva offers evaluation for every framework listed. CMMC evaluation and SPRS scoring are currently unavailable. See the FAQ for offered frameworks and preview status. Deva provides code-level evidence for your assessment, without certifying compliance.

FrameworkControls
OWASP Top 10:2025A07:2025 Authentication Failures
NIST 800-53 Rev 5IA-5 Authenticator Management, SC-12 Cryptographic Key Establishment and Management
PCI-DSS v4.0.18.6.2 No hard-coded passwords for accounts usable for interactive login
HIPAA Security Rule164.312(a)(2)(i) Unique User Identification
CMMC L2IA.L2-3.5.10 Cryptographically protect passwords

Related CWEs

  • CWE-259 · Use of hardcoded password specifically.
  • CWE-321 · Use of hardcoded cryptographic key.
  • CWE-522 · Insufficiently protected credentials.
  • CWE-287 · Improper authentication (often a downstream effect).

Related glossary terms