go-security-audit
Skill72 starsChanged 4 months agoMITView on GitHub
Security review for Go applications: input validation, SQL injection, authentication/authorization, secrets management, TLS, OWASP Top 10, and secure coding patterns. Use when performing security reviews, checking for vulnerabilities, hardening Go services, or reviewing auth implementations. Trigger examples: "security review", "check vulnerabilities", "OWASP", "SQL injection", "input validation", "secrets management", "auth review". Not for: dependency CVEs (go-dependency-audit), concurrency safety (go-concurrency-review).
- Reads credentials
In this repository36 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- .cursor/rules/go-skills.mdcCursor rule
- go-api-designSkill
- go-architecture-reviewSkill
- go-cliSkill
- go-dependency-injectionSkill
- go-design-patternsSkill
- go-graphqlSkill
- go-grpcSkill
- go-interface-designSkill
- go-openapiSkill
- go-project-layoutSkill
- go-code-reviewSkill
- go-coding-standardsSkill
- go-contextSkill
- go-data-structuresSkill
- go-documentationSkill
- go-error-handlingSkill
- go-modernizeSkill
- go-databaseSkill
- go-concurrency-reviewSkill
- go-defensive-codingSkill
- go-observabilitySkill
- go-performance-reviewSkill
- go-troubleshootingSkill
- go-test-qualitySkill
- go-test-table-drivenSkill
- git-commitSkill
- go-binary-sizeSkill
- go-ciSkill
- go-dependency-auditSkill
- go-refactoringSkill
- go-semantic-toolsSkill
- go-skills-routerSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
13 rules. About 0 are common, 9 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈9
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 39
Before manual review, run the automated scanners and fold their output into the findings (skip any that is not installed and note it):
- Distinctive: line 58
Run one pass per concern: (a) input validation + injection, (b) authentication/authorization, (c) secrets + crypto, (d) TLS + security …
- Distinctive: line 61
If your environment supports delegating work to parallel sub-agents or tasks, assign each pass to one — the passes don't overlap.
- Very specific: line 64
Every finding must cite file.go:line, the vulnerable input path, and a concrete fix.
- Distinctive: line 74
Read a reference file only when the section below is not enough.
- Distinctive: line 93
ALWAYS pass values as query parameters.
- Distinctive: line 123
Check ownership, not only role: a valid token for user A must not read user B's row.
- Very specific: line 134
Read them from the environment or a secrets manager, keep .env, *.pem, *.key and credentials.json in .gitignore, and run gitleaks detect in …
- Very specific: line 145
NEVER InsecureSkipVerify: true outside a test.
- Distinctive: line 170
No SQL injection vectors (all queries parameterized)
- Very specific: line 171
No hardcoded secrets/keys/tokens
- Distinctive: line 172
No plaintext password storage
- Distinctive: line 173
No disabled TLS certificate verification
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Go Security Audit
Security is not a feature — it's a property. Every line of code either maintains it or degrades it.
Operating Modes
Pick the mode that matches the request before starting:
- Targeted check — a single concern ("is this query injectable?", "review this auth middleware"). Apply only the relevant sections.
- Diff audit — audit the changed lines of a PR or working tree for every concern below.
- Full audit (default for "security review the service") — sweep the codebase using the parallel passes in "Auditing Large Codebases".
Run the Scanners First
Before manual review, run the automated scanners and fold their output into the findings (skip any that is not installed and note it):
govulncheck ./... # known CVEs actually reachable from your code
gosec ./... # static analysis for insecure patterns
go vet ./... # includes some security-relevant checksScanners find the known patterns; the manual passes below find the logic flaws they cannot.
Auditing Large Codebases
Each numbered section below is an independent audit pass. For codebases beyond ~20 files:
- Locate the attack surface first: HTTP/gRPC handlers, CLI entry points, queue consumers, and anything parsing external input.
- Run one pass per concern: (a) input validation + injection, (b) authentication/authorization, (c) secrets + crypto, (d) TLS + security headers + rate limiting, (e) logging hygiene.
- If your environment supports delegating work to parallel sub-agents or tasks, assign each pass to one — the passes don't overlap. Otherwise run them sequentially.
- Every finding must cite
file.go:line, the vulnerable input path, and a concrete fix. Aggregate into one report sorted by severity.
Detailed reference material, loaded on demand:
references/injection.md— boundary validation, sanitization, parameterized and dynamic queries.references/auth-and-transport.md— passwords, JWT, authorization middleware, secrets, TLS, headers, rate limiting.
Read a reference file only when the section below is not enough.
1. Input Validation
Validate at the boundary, before the value reaches any business code:
- Cap the request body with
http.MaxBytesReader— an unbounded decoder is a memory exhaustion vector. - Decode into a typed struct, then validate it. A decode that succeeds is not a value that is valid.
- Reject rather than repair. Reply with the status code, not with the internal error text.
- Sanitize anything rendered back as HTML (
bluemonday), parse emails withnet/mail, and reject URLs whose scheme is nothttp/https.
Examples in references/injection.md.
2. SQL Injection Prevention
ALWAYS pass values as query parameters. There is no safe amount of string concatenation:
// ✅ Good — parameterized
row := db.QueryRowContext(ctx, "SELECT id, name FROM users WHERE email = $1", email)
// ❌ CRITICAL — SQL injection
query := "SELECT * FROM users WHERE email = '" + email + "'"
query := fmt.Sprintf("SELECT * FROM users WHERE id = %s", id)Dynamic filters are built by appending placeholders ($1, $2, …) and
collecting the values into an args slice — never by interpolating the value
itself. Table and column names cannot be parameterized: allowlist them
against a fixed set.
Examples in references/injection.md.
3. Authentication & Authorization
- Hash passwords with
bcrypt(or argon2id). NEVER store plaintext, NEVER use MD5/SHA — they are fast, which is the wrong property here. - Compare with
bcrypt.CompareHashAndPassword, which is constant-time. Hand-rolled comparisons leak timing. - Validate every JWT claim that matters: signature with the expected
algorithm,
exp,iss,aud. Rejectalg: noneand never hardcode the signing key. - Authorize per request in middleware, reading the identity from the request context. An endpoint with no role check is a public endpoint.
- Check ownership, not only role: a valid token for user A must not read user B's row.
Examples in references/auth-and-transport.md.
4. Secrets Management
- 🔴 NEVER hardcode secrets, tokens, or API keys in source code
- 🔴 NEVER commit secrets to git (even in "test" files)
- 🔴 NEVER log secrets, tokens, or passwords
Read them from the environment or a secrets manager, keep .env, *.pem,
*.key and credentials.json in .gitignore, and run gitleaks detect in
CI so a leak fails the build instead of ageing in history.
Examples in references/auth-and-transport.md.
5. Transport, Headers and Rate Limiting
- Set
X-Content-Type-Options: nosniff,X-Frame-Options: DENY, aContent-Security-Policy, and HSTS on every response. - TLS:
MinVersion: tls.VersionTLS12and an explicit cipher suite list. NEVERInsecureSkipVerify: trueoutside a test. - Rate limit auth endpoints, public APIs, and anything expensive, keyed per client rather than globally.
Examples in references/auth-and-transport.md.
6. Logging Security
Log the identifier, never the credential:
// ❌ CRITICAL
log.Printf("user login: email=%s password=%s", email, password)
log.Printf("request body: %v", req) // may contain secrets
// ✅ Good — redacted
logger.Info("auth completed", slog.String("user_id", userID))Whole-struct logging is the common leak: a %v on a request struct prints
whatever field someone adds next sprint.
Security Audit Checklist
Critical (🔴 BLOCKER)
- No SQL injection vectors (all queries parameterized)
- No hardcoded secrets/keys/tokens
- No plaintext password storage
- No disabled TLS certificate verification
- Request body size limited
- JWT signature verified,
alg: nonerejected
Important (🟡 WARNING)
- Input validation on all external data
- Rate limiting on auth and public endpoints
- Security headers set on all responses
- CORS configured restrictively
- Error messages don't leak internals
- Audit logging for auth events
Recommended (🟢 SUGGESTION)
govulncheckin CI pipelinegitleaksfor secret scanning- Structured logging with redaction
- Dependency pinning with verified checksums
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

