Go security
Rewrite of samber/cc-skills-golang golang-security @ 22c58a55. Not a vendor paste. SKILL only — no evals/, no scripts/, no references/. Compatible with security-hardening: LLM output is untrusted; the system prompt is not a boundary.
language-router picks one Go skill per turn: this skill, golang-safety or golang-testing. Each Go concern may be its own item.
Iron law
Every trust-boundary crossing gets a control in code. Validate input, parameterize queries, encode for the sink, fail closed. Upstream validation adjusts severity; it does not dismiss the finding.
Three questions
- Trust boundary — where does untrusted data enter? (HTTP, uploads, env, other services' rows)
- Attacker control — which inputs reach SQL, shell, HTML, paths, crypto, or outbound HTTP?
- Blast radius — leak, RCE, auth bypass, or DoS if this layer fails?
Always
| Rule |
Go move |
| Parameterize every query |
database/sql / pgx placeholders ($1 / ?). Allowlist identifiers (ORDER BY, columns). Never concat user text into SQL. |
| Exec without a shell |
exec.Command(bin, args...). Never sh -c / bash -c with user text. |
| Encode for the HTML sink |
html/template (auto-escape). html.EscapeString if you must Fprintf. |
| Scope file paths |
Go 1.24+: os.Root. Older: filepath.IsLocal + filepath.Rel. Never Clean + HasPrefix alone. |
| Authenticated crypto |
AES-256-GCM or ChaCha20-Poly1305. Fresh nonce per seal. crypto/rand, not math/rand. |
| Slow password hashes |
Argon2id preferred; bcrypt OK. Not MD5 / SHA-1 / bare SHA-256. |
| Constant-time secrets |
crypto/subtle.ConstantTimeCompare or hmac.Equal. Not ==. |
| TLS 1.2+ and verify certs |
MinVersion: tls.VersionTLS12. No InsecureSkipVerify. SSH: FixedHostKey, not InsecureIgnoreHostKey. |
| Timeouts on HTTP servers |
ReadTimeout / WriteTimeout / IdleTimeout / MaxHeaderBytes. |
| Secure session cookies |
HttpOnly, Secure, SameSite=Lax or Strict. |
| Secrets from env or a manager |
Fail closed if required secret is empty. |
| Generic client errors |
Log details server-side. No stack traces, DSNs, or SQL text to clients. |
| Server-side authn/z |
Every handler. Do not trust X-Forwarded-For / X-Is-Admin. |
| Race-sensitive shared state |
sync.Mutex / channels. Prove with go test -race (golang-testing). |
Ask first
| Topic |
Why it is a stop |
| New auth / session shape |
Trust-boundary widen — same as security-hardening |
| New egress or SSRF-shaped fetch |
Outbound URL from user input needs an allowlist + no link-local / metadata |
| Uploads / zip extract |
ZipSlip, zip bombs, special files |
| Public pprof / debug mux |
/debug/pprof is a leak if reachable |
SameSite=None or cookie Domain |
CSRF / cross-site widening |
Skipping -race or fuzz on a security-touching change |
Proof belongs with golang-testing |
| Review/audit growing write or deploy tools |
Review skills should not write — read, report |
Record the decision on the LLD or ticket. Do not self-except.
Never
| Never |
Why |
| SQL / command / HTML string-built from user or model text |
Injection (CWE-89 / 78 / 79) |
| Hardcoded secrets, DSNs, or JWT keys in source |
History is forever |
math/rand for tokens, IDs, or nonces |
Predictable |
| DES, RC4, MD5, SHA-1, AES-ECB, or reused GCM nonce |
Broken or catastrophic |
Ignoring crypto / encrypt errors (_, _ = …) |
Fail-open |
| Rolling your own crypto |
Use stdlib / x/crypto |
gob of untrusted input |
Unsafe deserialization |
Bind 0.0.0.0 or public mesh from a one-off |
Network becomes the client |
World-writable files (0777 / 0666) |
Data-class fail |
| PII, tokens, or passwords in logs |
security-hardening Never |
| Personal finance, mail, password stores, or extra hosts without the operator |
Host / account locks |
Copy evals/ or scripts/ into this skill dir |
INTAKE quarantine |
| Install the samber pack / marketplace sync |
Dual routers; pin stays |
Host and personal-account locks are Never, not Ask first.
Modes
- Review — start at the diff, then trace call sites and data flow. A vuln may live outside the hunk. Read, report, escalate. Do not grow write/merge tools to “finish the review.”
- Audit — cover five domains: (1) injection, (2) crypto and secrets, (3) web / headers / cookies, (4) authn/z, (5) races that break authz. Score DREAD; one fix = one PR. Do not dump a mixed-concern patch.
- Coding — write behind Always. Optionally grep new code for concat-SQL,
sh -c, InsecureSkipVerify, and hardcoded keys while implementing.
Research before reporting
Do not flag a snippet in isolation.
- Trace the value to its origin (user, constant, internal).
- Check upstream validation / allowlists / type parse.
- Note remaining defenses (middleware,
os.Root, parameterized store).
- Report with adjusted severity, not a silent skip. If you downgrade, leave a short
// security: comment naming the control.
Defense in depth: every layer still protects itself. A concat reachable only through parseUserID() int is medium, not dismissed.
Severity (DREAD)
| Level |
Score |
Meaning |
| Critical |
8–10 |
RCE, full breach, credential theft — fix now |
| High |
6–7.9 |
Auth bypass, broken crypto, significant leak — this PR / sprint |
| Medium |
4–5.9 |
Session / timing / defense weakening — next pass |
| Low |
1–3.9 |
Best-practice drift — opportunistic |
Escalate Critical/High to the operator. Do not bury them in a follow-up with no ticket ID.
STRIDE at the boundary
For each crossing: spoofing (authn), tampering (integrity), repudiation (audit log), disclosure (encrypt / no PII logs), DoS (timeouts / rate limits), elevation (authz). Score with DREAD. Do not treat STRIDE as a substitute for the security LLD/PR gate.
Compact rules
Injection / SSRF. Placeholders for values; allowlist for identifiers. Dynamic IN = generated $n plus bound args (sqlx.In + Rebind). Block file:, link-local, and metadata hosts on outbound URLs. Prefer JSON with a typed struct over gob / interface{}.
Filesystem. os.Root for user paths and zip extract. Cap decompressed size; treat limit-hit as error, not io.EOF. Temps via os.CreateTemp + 0600. Dirs 0750, secret files 0600.
HTTP. Allowlist redirect hosts; reject javascript: / data:. No public net/http/pprof. Reject XML DTD / ENTITY. Headers as the app requires (HSTS, CSP, frame, nosniff) — same bar as security-hardening.
Cookies. Session cookies: HttpOnly + Secure + SameSite. Cookie-store keys from env, not literals.
Logging. Structured fields (log/slog). Never %+v a struct that holds a password or token.
Not this skill. Nil panics, typed-nil interfaces, append aliasing → golang-safety. Table-driven tests, t.Parallel, fuzz harness → golang-testing. govulncheck / lockfile audit → tester CI + dependency review, not an install step here.
Tooling (no skill scripts)
go test -race ./...
go test -fuzz=Fuzz
gosec / govulncheck belong in tester hooks when security asks — do not go install them as this skill’s job and do not copy vendor installers.
Roles
| Role |
Owns |
Does not own |
| security |
This gate at LLD/PR for Go boundaries; skill intake |
Writing product tests |
| builder |
Implementing behind Always; loading the one Go skill language-router picks |
Self-excepting “just this query” |
| tester |
-race / SAST hooks when they appear |
Skipping security because CI is green |
| manager |
After-act |
Blessing a ship that skipped the gate |
Workers do not bypass security; see Roles. A green gofmt is not a security clear.
Red flags
- “The input is validated upstream, so concat is fine”
- “
filepath.Clean + prefix is enough”
- “
InsecureSkipVerify is only for staging”
- “
math/rand is fine for a reset token”
- “I’ll log the whole user struct”
- “Review will just apply the fix”
- “Install the samber pack to get Go security”
Stop. Classify. Ask or never — do not ship.
Upstream pin
Intent: samber/cc-skills-golang skills/golang-security @ 22c58a55a0a799b901aa251172923180bad9e010 (MIT). Body is a rewrite. See SOURCES.md.
1---2name: golang-security3description: use this when writing, reviewing, or auditing Go for exploitable issues — injection, crypto, path, SSRF, cookies, secrets, PII in logs, authn/z — not nil/slice bugs (golang-safety) or test-harness design (golang-testing).4metadata:5 source: https://skillmd.com/skills/alexderz/golang-security6---78# Go security910Rewrite of samber/cc-skills-golang `golang-security` @ `22c58a55`. **Not** a vendor paste. **SKILL only** — no `evals/`, no `scripts/`, no `references/`. Compatible with `security-hardening`: **LLM output is untrusted**; the system prompt is not a boundary.1112[`language-router`](../language-router/SKILL.md#map) picks one Go skill per turn: this skill, `golang-safety` or `golang-testing`. Each Go concern may be its own item.1314## Iron law1516**Every trust-boundary crossing gets a control in code.** Validate input, parameterize queries, encode for the sink, fail closed. Upstream validation adjusts severity; it does not dismiss the finding.1718## Three questions19201. **Trust boundary** — where does untrusted data enter? (HTTP, uploads, env, other services' rows)212. **Attacker control** — which inputs reach SQL, shell, HTML, paths, crypto, or outbound HTTP?223. **Blast radius** — leak, RCE, auth bypass, or DoS if this layer fails?2324## Always2526| Rule | Go move |27| --- | --- |28| Parameterize every query | `database/sql` / `pgx` placeholders (`$1` / `?`). Allowlist identifiers (`ORDER BY`, columns). Never concat user text into SQL. |29| Exec without a shell | `exec.Command(bin, args...)`. Never `sh -c` / `bash -c` with user text. |30| Encode for the HTML sink | `html/template` (auto-escape). `html.EscapeString` if you must `Fprintf`. |31| Scope file paths | Go 1.24+: `os.Root`. Older: `filepath.IsLocal` + `filepath.Rel`. Never `Clean` + `HasPrefix` alone. |32| Authenticated crypto | AES-256-GCM or ChaCha20-Poly1305. Fresh nonce per seal. `crypto/rand`, not `math/rand`. |33| Slow password hashes | Argon2id preferred; bcrypt OK. Not MD5 / SHA-1 / bare SHA-256. |34| Constant-time secrets | `crypto/subtle.ConstantTimeCompare` or `hmac.Equal`. Not `==`. |35| TLS 1.2+ and verify certs | `MinVersion: tls.VersionTLS12`. No `InsecureSkipVerify`. SSH: `FixedHostKey`, not `InsecureIgnoreHostKey`. |36| Timeouts on HTTP servers | `ReadTimeout` / `WriteTimeout` / `IdleTimeout` / `MaxHeaderBytes`. |37| Secure session cookies | `HttpOnly`, `Secure`, `SameSite=Lax` or `Strict`. |38| Secrets from env or a manager | Fail closed if required secret is empty. |39| Generic client errors | Log details server-side. No stack traces, DSNs, or SQL text to clients. |40| Server-side authn/z | Every handler. Do not trust `X-Forwarded-For` / `X-Is-Admin`. |41| Race-sensitive shared state | `sync.Mutex` / channels. Prove with `go test -race` (`golang-testing`). |4243## Ask first4445| Topic | Why it is a stop |46| --- | --- |47| New auth / session shape | Trust-boundary widen — same as `security-hardening` |48| New egress or SSRF-shaped fetch | Outbound URL from user input needs an allowlist + no link-local / metadata |49| Uploads / zip extract | ZipSlip, zip bombs, special files |50| Public pprof / debug mux | `/debug/pprof` is a leak if reachable |51| `SameSite=None` or cookie `Domain` | CSRF / cross-site widening |52| Skipping `-race` or fuzz on a security-touching change | Proof belongs with `golang-testing` |53| Review/audit growing write or deploy tools | Review skills should not write — read, report |5455Record the decision on the LLD or ticket. Do not self-except.5657## Never5859| Never | Why |60| --- | --- |61| SQL / command / HTML string-built from user or model text | Injection (CWE-89 / 78 / 79) |62| Hardcoded secrets, DSNs, or JWT keys in source | History is forever |63| `math/rand` for tokens, IDs, or nonces | Predictable |64| DES, RC4, MD5, SHA-1, AES-ECB, or reused GCM nonce | Broken or catastrophic |65| Ignoring crypto / encrypt errors (`_, _ = …`) | Fail-open |66| Rolling your own crypto | Use stdlib / `x/crypto` |67| `gob` of untrusted input | Unsafe deserialization |68| Bind `0.0.0.0` or public mesh from a one-off | Network becomes the client |69| World-writable files (`0777` / `0666`) | Data-class fail |70| PII, tokens, or passwords in logs | `security-hardening` Never |71| Personal finance, mail, password stores, or extra hosts without the operator | Host / account locks |72| Copy `evals/` or `scripts/` into this skill dir | INTAKE quarantine |73| Install the samber pack / marketplace sync | Dual routers; pin stays |7475Host and personal-account locks are **Never**, not Ask first.7677## Modes7879- **Review** — start at the diff, then trace call sites and data flow. A vuln may live outside the hunk. **Read, report, escalate.** Do not grow write/merge tools to “finish the review.”80- **Audit** — cover five domains: (1) injection, (2) crypto and secrets, (3) web / headers / cookies, (4) authn/z, (5) races that break authz. Score DREAD; one fix = one PR. Do not dump a mixed-concern patch.81- **Coding** — write behind Always. Optionally grep new code for concat-SQL, `sh -c`, `InsecureSkipVerify`, and hardcoded keys while implementing.8283## Research before reporting8485Do not flag a snippet in isolation.86871. Trace the value to its origin (user, constant, internal).882. Check upstream validation / allowlists / type parse.893. Note remaining defenses (middleware, `os.Root`, parameterized store).904. Report with **adjusted severity**, not a silent skip. If you downgrade, leave a short `// security:` comment naming the control.9192Defense in depth: every layer still protects itself. A concat reachable only through `parseUserID() int` is medium, not dismissed.9394## Severity (DREAD)9596| Level | Score | Meaning |97| --- | --- | --- |98| Critical | 8–10 | RCE, full breach, credential theft — fix now |99| High | 6–7.9 | Auth bypass, broken crypto, significant leak — this PR / sprint |100| Medium | 4–5.9 | Session / timing / defense weakening — next pass |101| Low | 1–3.9 | Best-practice drift — opportunistic |102103Escalate Critical/High to the operator. Do not bury them in a follow-up with no ticket ID.104105## STRIDE at the boundary106107For each crossing: spoofing (authn), tampering (integrity), repudiation (audit log), disclosure (encrypt / no PII logs), DoS (timeouts / rate limits), elevation (authz). Score with DREAD. Do not treat STRIDE as a substitute for the **security** LLD/PR gate.108109## Compact rules110111**Injection / SSRF.** Placeholders for values; allowlist for identifiers. Dynamic `IN` = generated `$n` plus bound args (`sqlx.In` + `Rebind`). Block `file:`, link-local, and metadata hosts on outbound URLs. Prefer JSON with a typed struct over `gob` / `interface{}`.112113**Filesystem.** `os.Root` for user paths and zip extract. Cap decompressed size; treat limit-hit as error, not `io.EOF`. Temps via `os.CreateTemp` + `0600`. Dirs `0750`, secret files `0600`.114115**HTTP.** Allowlist redirect hosts; reject `javascript:` / `data:`. No public `net/http/pprof`. Reject XML DTD / `ENTITY`. Headers as the app requires (HSTS, CSP, frame, nosniff) — same bar as `security-hardening`.116117**Cookies.** Session cookies: `HttpOnly` + `Secure` + `SameSite`. Cookie-store keys from env, not literals.118119**Logging.** Structured fields (`log/slog`). Never `%+v` a struct that holds a password or token.120121**Not this skill.** Nil panics, typed-nil interfaces, `append` aliasing → `golang-safety`. Table-driven tests, `t.Parallel`, fuzz harness → `golang-testing`. `govulncheck` / lockfile audit → **tester** CI + dependency review, not an install step here.122123## Tooling (no skill scripts)124125```bash126go test -race ./...127go test -fuzz=Fuzz128```129130`gosec` / `govulncheck` belong in **tester** hooks when **security** asks — do not `go install` them as this skill’s job and do not copy vendor installers.131132## Roles133134| Role | Owns | Does not own |135| --- | --- | --- |136| **security** | This gate at LLD/PR for Go boundaries; skill intake | Writing product tests |137| **builder** | Implementing behind Always; loading the one Go skill `language-router` picks | Self-excepting “just this query” |138| **tester** | `-race` / SAST hooks when they appear | Skipping **security** because CI is green |139| **manager** | After-act | Blessing a ship that skipped the gate |140141Workers do not bypass **security**; see [Roles](../sdlc/SKILL.md#roles). A green `gofmt` is not a **security** clear.142143## Red flags144145- “The input is validated upstream, so concat is fine”146- “`filepath.Clean` + prefix is enough”147- “`InsecureSkipVerify` is only for staging”148- “`math/rand` is fine for a reset token”149- “I’ll log the whole user struct”150- “Review will just apply the fix”151- “Install the samber pack to get Go security”152153Stop. Classify. Ask or never — do not ship.154155## Upstream pin156157Intent: samber/cc-skills-golang `skills/golang-security` @ `22c58a55a0a799b901aa251172923180bad9e010` (MIT). Body is a rewrite. See [SOURCES.md](../../SOURCES.md).