Token导航 LogoToken导航TokenDH.com
研究检索敏感数据github未标认证来源可访问许可证需确认审计异常

hardcoded-secrets-anti-pattern硬编码秘密反模式

Agent Skill

用于辅助安全审计、权限检查、凭据风险、认证流程和常见漏洞排查。它适合让 Agent 梳理敏感配置、检查依赖风险、分析鉴权逻辑或生成安全复核清单。使用时不能把工具输出直接当最终结论,涉及密钥、令牌、用户数据或生产系统时,应先确认最小权限、脱敏方式和操作边界。

总安装

192

周安装

8

GitHub Stars

4

下载量

64
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:hardcoded-secrets-anti-pattern(硬编码秘密反模式)
来源仓库:https://github.com/igbuend/grimbard
仓库路径:skills/hardcoded-secrets-anti-pattern
安装命令:
npx skills add https://github.com/igbuend/grimbard --skill hardcoded-secrets-anti-pattern
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/igbuend/grimbard --skill hardcoded-secrets-anti-pattern

简介

用于识别代码中硬编码的敏感信息(如 API 密钥、数据库密码),辅助安全审计与漏洞排查。

  • 适合在 Codex、Claude、Cursor 等宿主中分析鉴权逻辑、检查依赖风险或生成安全复核清单。
  • 提供错误与正确代码示例,帮助理解如何从环境变量或秘密管理器加载凭据。
  • 输出不能作为最终结论,涉及生产系统时应先确认最小权限与脱敏方式。
  • 安装通过 GitHub 仓库,使用前需评估对代码库的访问和操作影响。

SKILL.md

Hardcoded Secrets Anti-Pattern

Severity: Critical

Summary

Hardcoded secrets embed sensitive credentials (API keys, passwords, database credentials) directly in source code. Anyone with code access—developers, version control history, or attackers—can extract these secrets. AI models frequently generate hardcoded secrets, trained on public code with this common bad practice. Secrets committed to public repositories are discovered and exploited by automated bots within minutes.

The Anti-Pattern

Never store secrets, credentials, or sensitive configuration values in files tracked by version control.

BAD Code Example

# VULNERABLE: Hardcoded API keys and database credentials in the source code.
import requests
import psycopg2

# 1. Hardcoded API Key
API_KEY = "sk-live-123abc456def789ghi"

def get_weather(city):
    url = f"https://api.weatherprovider.com/v1/current?city={city}"
    headers = {"Authorization": f"Bearer {API_KEY}"}
    response = requests.get(url, headers=headers)
    return response.json()

# 2. Hardcoded Database Password
DB_HOST = "localhost"
DB_USER = "admin"
DB_PASSWORD = "my_super_secret_password_123" # Exposed in the code
DB_NAME = "main_db"

def get_db_connection():
    # The password is right here for any attacker to see.
    conn = psycopg2.connect(
        host=DB_HOST,
        database=DB_NAME,
        user=DB_USER,
        password=DB_PASSWORD
    )
    return conn

GOOD Code Example

# SECURE: Load secrets from the environment or a dedicated secrets manager.
import os
import requests
import psycopg2

# 1. API key loaded from an environment variable.
API_KEY = os.environ.get("WEATHER_API_KEY")

def get_weather(city):
    if not API_KEY:
        raise ValueError("WEATHER_API_KEY environment variable not set.")
    url = f"https://api.weatherprovider.com/v1/current?city={city}"
    headers = {"Authorization": f"Bearer {API_KEY}"}
    response = requests.get(url, headers=headers)
    return response.json()

# 2. Database credentials loaded from environment variables.
DB_HOST = os.environ.get("DB_HOST", "localhost")
DB_USER = os.environ.get("DB_USER")
DB_PASSWORD = os.environ.get("DB_PASSWORD")
DB_NAME = os.environ.get("DB_NAME")

def get_db_connection():
    # The application will fail safely if secrets are not configured in the environment.
    if not all([DB_USER, DB_PASSWORD, DB_NAME]):
        raise ValueError("Database environment variables are not fully configured.")
    conn = psycopg2.connect(
        host=DB_HOST,
        database=DB_NAME,
        user=DB_USER,
        password=DB_PASSWORD
    )
    return conn

Language-Specific Examples

JavaScript/Node.js:

// VULNERABLE: Hardcoded credentials
const stripe = require('stripe')('sk_live_abc123def456ghi789'); // Exposed!

const dbConfig = {
  host: 'localhost',
  user: 'admin',
  password: 'MyP@ssw0rd123', // Never do this!
  database: 'production_db'
};
// SECURE: Use environment variables
require('dotenv').config(); // Load .env file

const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY);

const dbConfig = {
  host: process.env.DB_HOST || 'localhost',
  user: process.env.DB_USER,
  password: process.env.DB_PASSWORD,
  database: process.env.DB_NAME
};

if (!process.env.STRIPE_SECRET_KEY || !process.env.DB_PASSWORD) {
  throw new Error('Required environment variables not set');
}

Java/Spring Boot:

// VULNERABLE: Hardcoded in application.properties
// application.properties:
// spring.datasource.password=MySecretPassword123
// aws.access.key=AKIAIOSFODNN7EXAMPLE
// SECURE: Use environment variables or secret managers
// application.properties:
// spring.datasource.password=${DB_PASSWORD}
// aws.access.key=${AWS_ACCESS_KEY}

// Or use AWS Secrets Manager
@Configuration
public class SecretsConfig {
    @Bean
    public AWSSecretsManager secretsManager() {
        return AWSSecretsManagerClientBuilder.standard()
            .withRegion("us-west-2")
            .build();
    }

    @Bean
    public String dbPassword(AWSSecretsManager secretsManager) {
        GetSecretValueRequest request = new GetSecretValueRequest()
            .withSecretId("prod/db/password");
        GetSecretValueResult result = secretsManager.getSecretValue(request);
        return result.getSecretString();
    }
}

C# (ASP.NET Core):

// VULNERABLE: Hardcoded in appsettings.json
// {
//   "ConnectionStrings": {
//     "Default": "Server=localhost;Database=mydb;User=admin;Password=Secret123;"
//   },
//   "ApiKeys": {
//     "SendGrid": "SG.abc123def456ghi789"
//   }
// }
// SECURE: Use User Secrets for dev, Azure Key Vault for production
// Startup.cs
public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    public void ConfigureServices(IServiceCollection services)
    {
        // Connection string from environment or User Secrets
        services.AddDbContext<ApplicationDbContext>(options =>
            options.UseSqlServer(
                Configuration.GetConnectionString("Default")));

        // API key from Azure Key Vault (production) or User Secrets (dev)
        services.AddSingleton<IEmailService>(sp =>
            new SendGridEmailService(Configuration["ApiKeys:SendGrid"]));
    }
}

// Set secrets:
// dotnet user-secrets set "ConnectionStrings:Default" "Server=..."
// Or use Azure Key Vault in production

Detection

  • Use secret scanning tools: Scan repository history automatically:

- gitleaks detect --source. --verbose - trufflehog git file://. --only-verified - git-secrets --scan (pre-commit hook integration)

  • Search for keywords: Grep for common patterns:

- rg -i '(password|secret|api_?key|token|credential)\s*=\s*["\']' - rg 'sk-[a-zA-Z0-9]{32,}' (OpenAI API keys)

  • Detect high-entropy strings: Identify random 32+ character strings:

- trufflehog --entropy=True - detect-secrets scan --baseline.secrets.baseline

  • Check configuration files: Audit committed configs:

- git log --all --full-history -- "*.env" "config.json" "settings.py" - Review files that should be in.gitignore

Prevention

  • Never hardcode any credentials, API keys, or secrets in your source code.
  • Use environment variables to store secrets in development and other non-production environments.
  • Use a dedicated secrets management service for production environments (e.g., AWS Secrets Manager, HashiCorp Vault, Google Secret Manager).
  • Add a .env file (or similar) to your .gitignore to prevent accidental commits of local development secrets.
  • Integrate secret scanning tools into your CI/CD pipeline and pre-commit hooks to block commits that contain secrets.
  • Implement a secret rotation policy to limit the impact of a compromised secret.

Related Security Patterns & Anti-Patterns

References

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

34.56%
按下载量换算22

Claude

27.23%
按下载量换算17

Cursor

18%
按下载量换算12

Gemini CLI

10.26%
按下载量换算7

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

未通过

权限和风险

敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills