samber/cc-skills-golang / skills/golang-security
golang-security
FlaggedSecurity best practices and vulnerability prevention for Golang — injection (SQL, command, XSS), cryptography, path traversal, SSRF and HTTP security headers, cookies, secrets management, memory safety, PII in logs, STRIDE/DREAD threat modeling, plus `gosec` SAST, race detection, and fuzz testing. Apply when writing, reviewing, or auditing Go code for security, or when touching crypto, file or network I/O, secrets, user input, or authentication. Not for non-exploitable defensive bugs such as nil panics or slice aliasing (→ See `samber/cc-skills-golang@golang-safety` skill), dependency vulnerability scanning with govulncheck (→ See `samber/cc-skills-golang@golang-dependency-management` skill), or wiring security scanners into CI pipelines (→ See `samber/cc-skills-golang@golang-continuous-integration` skill).
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 14.0 KB |
| evals/evals.json | config | 49.0 KB |
| references/architecture.md | markdown | 10.4 KB |
| references/checklist.md | markdown | 4.0 KB |
| references/cookies.md | markdown | 4.8 KB |
| references/cryptography.md | markdown | 11.0 KB |
| references/filesystem.md | markdown | 6.8 KB |
| references/injection.md | markdown | 7.3 KB |
| references/logging.md | markdown | 3.9 KB |
| references/memory-safety.md | markdown | 5.1 KB |
| references/network.md | markdown | 6.3 KB |
| references/secrets.md | markdown | 4.8 KB |
| references/third-party.md | markdown | 4.9 KB |
| references/threat-modeling.md | markdown | 8.4 KB |
references/secrets.md
View on GitHub# Secrets Management Security Rules
Hardcoded secrets, credentials, and sensitive data in source code is a major security vulnerability.
**Rules:**
1. Secrets MUST be loaded from environment variables or secret managers.
2. NEVER commit secrets to VCS.
3. `.gitignore` MUST exclude secret files (`.env`, `*.key`, `*.pem`).
---
## Table of Contents
- [Hardcoded Secrets and Credentials — Critical](#hardcoded-secrets-and-credentials--critical)
- [Hardcoded Database Passwords — Critical](#hardcoded-database-passwords--critical)
- [Secrets Storage Best Practices](#secrets-storage-best-practices)
- [Environment Variables](#environment-variables)
- [Secret Managers](#secret-managers)
- [.gitignore Patterns](#gitignore-patterns)
- [Secret Detection Patterns](#secret-detection-patterns)
- [CWE References](#cwe-references)
## Hardcoded Secrets and Credentials — Critical
**Bad:**
```go
const (
AWS_ACCESS_KEY = "AKIAIOSFODNN7EXAMPLE" // DON'T
AWS_SECRET_KEY = "wJalrXUtnFEMI/K7MDENG" // DON'T
DATABASE_PASSWORD = "SuperSecret123!" // DON'T
JWT_SECRET = "my-super-secret-jwt-key" // DON'T
)
var config = Config{
APIKey: "abc123-xyz789-secret-key", // DON'T
Secret: "my-super-secret-value", // DON'T
DatabaseURL: "user:passw0rd!@localhost:5432/db", // DON'T
}
```
**Good:**
```go
import "os"
type Config struct {
AWSAccessKey string
AWSSecretKey string
DatabasePassword string
JWTSecret string
}
func LoadConfig() (*Config, error) {
cfg := &Config{
AWSAccessKey: os.Getenv("AWS_ACCESS_KEY_ID"),
AWSSecretKey: os.Getenv("AWS_SECRET_ACCESS_KEY"),
DatabasePassword: os.Getenv("DATABASE_PASSWORD"),
JWTSecret: os.Getenv("JWT_SECRET"),
}
if cfg.JWTSecret == "" {
return nil, errors.New("JWT_SECRET is required")
}
return cfg, nil
}
```
---
## Hardcoded Database Passwords — Critical
**Bad:**
```go
// MySQL
dsn := "user:Password123!@tcp(localhost:3306)/dbname" // DON'T
// PostgreSQL
dsn := "user=postgres password=P@ssw0rd! dbname=mydb host=localhost" // DON'T
```
**Good:**
```go
// MySQL
func connectMySQL() (*sql.DB, error) {
user := os.Getenv("DB_USER")
password := os.Getenv("DB_PASSWORD")
if password == "" {
return nil, errors.New("DB_PASSWORD required")
}
host := getEnvWithDefault("DB_HOST", "localhost")
port := getEnvWithDefault("DB_PORT", "3306")
addr := net.JoinHostPort(host, port)
dsn := fmt.Sprintf("%s:%s@tcp(%s)/%s",
user, password, addr, getEnvWithDefault("DB_NAME", "mydb"))
return sql.Open("mysql", dsn)
}
// PostgreSQL
func connectPostgres() (*sql.DB, error) {
connStr := os.Getenv("DATABASE_URL")
if connStr == "" {
return nil, errors.New("DATABASE_URL required")
}
return sql.Open("postgres", connStr)
}
```
---
## Secrets Storage Best Practices
### Environment Variables
```go
type EnvSecretLoader struct{}
func (l *EnvSecretLoader) Load(required []string) (map[string]string, error) {
secrets := make(map[string]string)
missing := []string{}
for _, name := range required {
value := os.Getenv(name)
if value == "" {
missing = append(missing, name)
continue
}
secrets[name] = value
}
if len(missing) > 0 {
return nil, fmt.Errorf("missing: %v", missing)
}
return secrets, nil
}
```
### Secret Managers
```go
type SecretManager interface {
GetSecret(name string) (string, error)
}
// AWS Secrets Manager
type AWSSecretsManager struct {
client *secretsmanager.Client
}
func (m *AWSSecretsManager) GetSecret(name string) (string, error) {
result, err := m.client.GetSecretValue(context.TODO(), &secretsmanager.GetSecretValueInput{
SecretId: aws.String(name),
})
if err != nil {
return "", err
}
if result.SecretString != nil {
return *result.SecretString, nil
}
return string(result.SecretBinary), nil
}
```
### .gitignore Patterns
```
# Secrets
.env
.env.local
.env.*.local
*.key
*.pem
*.p12
*.pfx
secrets/
credentials/
```
---
## Secret Detection Patterns
| Pattern | Example |
| --------------- | ------------------------------- |
| API Keys | `Key = "sk_live_..."` |
| Passwords | `password = "..."` |
| Tokens | `token = "..."` |
| Private Keys | `BEGIN PRIVATE KEY` |
| AWS Credentials | `AWS_ACCESS_KEY_ID = "AKIA..."` |
| JWT Secrets | `jwtSecret = "..."` |
---
## CWE References
- **CWE-798**: Use of Hard-coded Credentials
- **CWE-312**: Cleartext Storage of Sensitive Information
- **CWE-532**: Insertion of Sensitive Information into Log File
- **CWE-359**: Exposure of Private Personal Information
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |