BETA O Shoulder está em beta — Os resultados às vezes podem estar incorretos. Seu feedback molda o que corrigimos a seguir. Compartilhar feedback
🔑

Use of Hard-coded Credentials

🛡️ 11 regras detectam isto

Use of Hard-coded Credentials

The product contains hard-coded credentials, such as a password or cryptographic key, which it uses for its own inbound authentication, outbound communication to external components, or encryption of internal data.

Hard-coded credentials typically create a significant hole that allows an attacker to bypass the authentication that has been configured by the product administrator. This hole might be difficult for the system administrator to detect.

Prevalência
Alta
Frequentemente explorada
Impacto
Crítico
6 regras de severidade crítica
Prevenção
Documentada
11 exemplos de correção
2 Prevenção
2 Prevenção

Como corrigir esta vulnerabilidade

Estratégias de prevenção para Hardcoded Credentials baseadas em 11 regras de detecção do Shoulder.

Django Insecure SECRET_KEY CRITICAL

Load SECRET_KEY from environment variables, never commit it to source control

+3 -1 python
  # settings.py
- SECRET_KEY = 'django-insecure-abc123def456'
+ import os
+ 
+ SECRET_KEY = os.environ['DJANGO_SECRET_KEY']
  
Hardcoded Credentials HIGH

Store all credentials in environment variables or a secrets manager, never in code

+5 -3 python
- password = "super_secret_password"
- api_key = "sk-abc123456789xyz"
- db_password = "db_p@ssw0rd_2024"
+ import os
+ 
+ password = os.environ['APP_PASSWORD']
+ api_key = os.environ['API_KEY']
+ db_password = os.environ['DB_PASSWORD']
  
Hardcoded Secrets / Credentials HIGH

Load all secrets from environment variables or a secrets manager

+5 -3 python
- SECRET_KEY = 'django-insecure-abc123def456'
- API_KEY = 'sk-proj-abc123456789'
- DATABASE_PASSWORD = 'super_secret_123'
+ import os
+ 
+ SECRET_KEY = os.environ['SECRET_KEY']
+ API_KEY = os.environ['API_KEY']
+ DATABASE_PASSWORD = os.environ['DB_PASSWORD']
  
Docker Secrets and Security Best Practices CRITICAL

Use BuildKit secrets or runtime environment variables instead of hardcoded credentials

+5 -4 dockerfile
- FROM node:24-alpine
- ENV DATABASE_PASSWORD=supersecret123
- ARG API_KEY=sk_live_abc123
- WORKDIR /app
+ # syntax=docker/dockerfile:1
+ FROM node:24-alpine
+ WORKDIR /app
+ RUN --mount=type=secret,id=db_pass \
+     cat /run/secrets/db_pass > /dev/null
  COPY . .
  
Hardcoded Secrets in Source Code CRITICAL

Load secrets from environment variables or a secrets manager instead of hardcoding

+9 -7 go
  package main
  
- const (
-     APIKey     = "sk-1234567890abcdefghijklmnop"
-     DBPassword = "superSecretPassword123"
- )
- 
- func connectDB() (*sql.DB, error) {
-     connStr := "postgres://admin:superSecretPassword123@localhost:5432/db"
+ import "os"
+ 
+ func connectDB() (*sql.DB, error) {
+     apiKey := os.Getenv("API_KEY")
+     if apiKey == "" {
+         log.Fatal("API_KEY not set")
+     }
+     dbPass := os.Getenv("DB_PASSWORD")
+     connStr := fmt.Sprintf("postgres://admin:%s@localhost:5432/db", dbPass)
      return sql.Open("postgres", connStr)
  }
  
Hardcoded Secret in Environment Variable Fallback HIGH

Never use hardcoded fallbacks for secrets; fail fast if environment variables are missing

+6 -1 javascript
- const JWT_SECRET = process.env.JWT_SECRET || 'my-insecure-secret-key';
+ function getRequiredEnv(name) {
+   const value = process.env[name];
+   if (!value) throw new Error(`Required env var ${name} is not set`);
+   return value;
+ }
+ const JWT_SECRET = getRequiredEnv('JWT_SECRET');
  
Hardcoded Credentials HIGH

Load credentials from environment variables instead of hardcoding in source code

+6 -5 javascript
- const connection = mysql.createConnection({
-   host: 'localhost',
-   user: 'root',
-   password: 'admin123',
-   database: 'myapp'
+ require('dotenv').config();
+ const connection = mysql.createConnection({
+   host: process.env.DB_HOST,
+   user: process.env.DB_USER,
+   password: process.env.DB_PASSWORD,
+   database: process.env.DB_NAME
  });
  
Hardcoded High-Entropy Secrets Detection CRITICAL

Move secrets to environment variables using dotenv or a secret manager

+2 -1 javascript
- const apiKey = 'sk_live_abc123def456ghi789';
+ require('dotenv').config();
+ const apiKey = process.env.STRIPE_API_KEY;
  
Hardcoded Secrets in Manifest CRITICAL

Use Kubernetes Secrets with secretKeyRef instead of hardcoding credentials in manifests

+4 -1 yaml
  apiVersion: v1
  kind: Pod
  spec:
    containers:
    - name: app
      env:
        - name: DB_PASSWORD
-         value: "super-secret-password"
+         valueFrom:
+           secretKeyRef:
+             name: db-secret
+             key: password
  

Práticas-chave

  • loaded from environment variables or secure secret management systems
  • stored in environment variables or secure vaults
  • stored in environment variables or secure vaults, never committed to version control
3 Detecção
3 Detecção

Encontre vulnerabilidades no seu código

Use o Shoulder para escanear seu código em busca de padrões Use of Hard-coded Credentials. 11 regras.

terminal
# Scan with Shoulder CLI
npx @shoulderdev/cli trust --cwe=798

# Or scan entire project
npx @shoulderdev/cli trust .

Regras de Detecção (11)

🟨 Javascript 5 rules
Hardcoded Secret in Environment Variable Fallback HIGH
Detects hardcoded secrets used as fallback values for environment variables. Pattern: `process.env.SECRET || 'hardcoded-value'` This is dangerous because: - If the environment variable is not set, the hardcoded value is used - Developers often forget to set env vars in production - The hardcoded fallback may be committed to version control - Creates false sense of security ("we use env vars") This is particularly common with: - JWT secrets - API keys - Database passwords - Encryption keys
Hardcoded Credentials HIGH
Detects hardcoded credentials (passwords, API keys, tokens) in database connections and configuration objects. Credentials should be loaded from environment variables or secure secret management systems. This is different from CWE-259 (weak password): - CWE-798: Any credential hardcoded in source code (security risk) - CWE-259: Specifically weak/guessable passwords Even a "strong" password is a security risk if hardcoded because: - It gets committed to version control - It's difficult to rotat
Hardcoded High-Entropy Secrets Detection CRITICAL
Detects hardcoded secrets with high entropy (randomness) that indicate real credentials. This rule uses entropy analysis to avoid false positives from: - Example/placeholder values ("keyboard cat", "your-secret-here") - Test fixtures ("test123", "fake-api-key") - Short/simple strings ("secret", "password") Only flags strings that appear to be REAL secrets: - High entropy (random-looking characters) - Sufficient length (20+ characters for API keys) - Known secret patterns (AWS keys, JWT tokens,
Hardcoded Secrets in Security Operations CRITICAL
Detects hardcoded secrets (API keys, tokens, passwords) flowing into security-sensitive operations. Uses taint analysis to track hardcoded secret strings from their definition to actual usage in authentication, API calls, or cryptographic operations. This approach reduces false positives by only flagging secrets that are actually used, not just defined in comments, examples, or unused variables.
Security Issues in Test Files LOW
Detects security anti-patterns in test files that could leak into production. While test files don't run in production, they can still pose security risks: 1. **Hard-coded credentials** - Test credentials committed to repos 2. **Real API keys** - Production keys used in tests 3. **Exposed secrets** - Secrets in test fixtures or mocks 4. **Insecure test patterns** - Patterns that might be copy-pasted to production This rule helps maintain test hygiene and prevents credential leaks.
🔷 Typescript 5 rules
Hardcoded Secret in Environment Variable Fallback HIGH
Detects hardcoded secrets used as fallback values for environment variables. Pattern: `process.env.SECRET || 'hardcoded-value'` This is dangerous because: - If the environment variable is not set, the hardcoded value is used - Developers often forget to set env vars in production - The hardcoded fallback may be committed to version control - Creates false sense of security ("we use env vars") This is particularly common with: - JWT secrets - API keys - Database passwords - Encryption keys
Hardcoded Credentials HIGH
Detects hardcoded credentials (passwords, API keys, tokens) in database connections and configuration objects. Credentials should be loaded from environment variables or secure secret management systems. This is different from CWE-259 (weak password): - CWE-798: Any credential hardcoded in source code (security risk) - CWE-259: Specifically weak/guessable passwords Even a "strong" password is a security risk if hardcoded because: - It gets committed to version control - It's difficult to rotat
Hardcoded High-Entropy Secrets Detection CRITICAL
Detects hardcoded secrets with high entropy (randomness) that indicate real credentials. This rule uses entropy analysis to avoid false positives from: - Example/placeholder values ("keyboard cat", "your-secret-here") - Test fixtures ("test123", "fake-api-key") - Short/simple strings ("secret", "password") Only flags strings that appear to be REAL secrets: - High entropy (random-looking characters) - Sufficient length (20+ characters for API keys) - Known secret patterns (AWS keys, JWT tokens,
Hardcoded Secrets in Security Operations CRITICAL
Detects hardcoded secrets (API keys, tokens, passwords) flowing into security-sensitive operations. Uses taint analysis to track hardcoded secret strings from their definition to actual usage in authentication, API calls, or cryptographic operations. This approach reduces false positives by only flagging secrets that are actually used, not just defined in comments, examples, or unused variables.
Security Issues in Test Files LOW
Detects security anti-patterns in test files that could leak into production. While test files don't run in production, they can still pose security risks: 1. **Hard-coded credentials** - Test credentials committed to repos 2. **Real API keys** - Production keys used in tests 3. **Exposed secrets** - Secrets in test fixtures or mocks 4. **Insecure test patterns** - Patterns that might be copy-pasted to production This rule helps maintain test hygiene and prevents credential leaks.
4 Sinais de Alerta
4 Sinais de Alerta

O que observar nas revisões de código

Estes padrões indicam vulnerabilidades potenciais de Use of Hard-coded Credentials. Procure-os durante revisões de código e auditorias de segurança.

🟠
Hardcoded secret used as fallback for environment variable. Code: ... If the environment variable is not set, this har javascript-env-fallback-secrets
🟠
hardcoded secrets used as fallback values for environment variables javascript-env-fallback-secrets
🟠
Hardcoded credential detected in ... Credentials should never be stored in source code. javascript-hardcoded-credentials
🟠
hardcoded credentials (passwords, API keys, tokens) in database connections and configuration object javascript-hardcoded-credentials
🟠
hardcoded passwords, API keys, tokens, and other credentials in source code python-hardcoded-credentials
🔵
Test file contains hard-coded credentials at line ... javascript-test-security-issues
🔵
security anti-patterns in test files that could leak into production javascript-test-security-issues
🔴
Django SECRET_KEY that is hardcoded, weak, or uses default values django-insecure-secret-key
🔍

Escaneie seu código para Use of Hard-coded Credentials

O Shoulder CLI encontra padrões vulneráveis em todo o seu código.