[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7BQE3D1H45ANCXAWCS55CDK":3,"skill-same:01M7BQE3D1H45ANCXAWCS55CDK":63},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":6,"ownerHtmlUrl":29,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":30,"install":31,"resources":44},"01M7BQE3D1H45ANCXAWCS55CDK","go-security",null,"Use when writing or reviewing Go code that touches untrusted input, secrets, or credentials — SQL, shell, or template injection, path traversal, SSRF, cookies and security headers, password hashing, TLS settings, token comparison, or what may appear in a log line. Also use when a handler accepts a file name, URL, or command argument from a client, or when asked to find \"vulnerabilities\", even if the user never says \"security\". Does not cover the os.Root and crypto\u002Frand mechanics (see go-defensive) or the dependency CVE scan in the gate (see go-linting).","h0rn3t\u002Fgolang-skills","h0rn3t","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F1213719?v=4","01M7BQBDJ8D4P5W7EQHBD464BX","Eugene Shershen","01M7BQBDJXMTCKNCEDKVEYDRGA",7,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fh0rn3t\u002Fgolang-skills\u002Fblob\u002Fmain\u002Fskills\u002Fgo-security\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: go-security\ndescription: Use when writing or reviewing Go code that touches untrusted input, secrets, or credentials — SQL, shell, or template injection, path traversal, SSRF, cookies and security headers, password hashing, TLS settings, token comparison, or what may appear in a log line. Also use when a handler accepts a file name, URL, or command argument from a client, or when asked to find \"vulnerabilities\", even if the user never says \"security\". Does not cover the os.Root and crypto\u002Frand mechanics (see go-defensive) or the dependency CVE scan in the gate (see go-linting).\n---\n\n# Go Security\n\n> Compatibility: Baseline Go 1.27 (see [COMPATIBILITY.md](..\u002Fgo-style-core\u002Freferences\u002FCOMPATIBILITY.md)). `os.Root` and\n> `crypto\u002Fpbkdf2`, `crypto\u002Fhkdf`, `crypto\u002Fsha3` are Go 1.24+;\n> `http.NewCrossOriginProtection` Go 1.25+; `crypto\u002Fsubtle`, `html\u002Ftemplate`,\n> and `net\u002Fnetip` are long-standing stdlib.\n\nA vulnerability is a trust boundary nobody named. Before writing or reviewing,\nanswer three questions: **where does untrusted data enter**, **which sensitive\noperation does it reach** (query, shell, file path, URL fetch, HTML, log), and\n**what is the blast radius if the defense fails**. Every rule below is one of\nthose paths, with the standard-library defense that closes it.\n\n## Resource Routing\n\n- `references\u002FINJECTION.md` - Read when untrusted data reaches SQL, `os\u002Fexec`, a template or a template's source, a file path, an outbound URL, a redirect, or a decompressor, or is served back as a download.\n- `references\u002FSECRETS-AND-CRYPTO.md` - Read when handling passwords, a login or reset flow, tokens, API keys, webhook signatures, TLS configuration, or choosing a hash or cipher.\n- `references\u002FACCESS-CONTROL.md` - Read when code decides who may act: auth middleware and route registration, the tenant a query uses, batch, export, import, or background jobs, a cache, model tool calls, mTLS, gRPC, or queue identity, an OAuth login, or CORS with credentials.\n- `references\u002FREVIEW.md` - Read when asked to audit or find vulnerabilities, or when writing up and ranking a security finding inside a review.\n\n## Quick Reference\n\n| Threat | Defense | Caught by |\n|---|---|---|\n| SQL injection | `QueryContext(ctx, q, args...)` placeholders; identifiers from a `switch` over known names | `gosec` G201\u002FG202, and G701 for a request value in the query text |\n| Foreign row by ID | `AND org_id =` the caller's tenant, a parameter beside the ID ([INJECTION.md](references\u002FINJECTION.md#sql)); a foreign ID is `sql.ErrNoRows` | review |\n| Tenant from the client | The tenant the middleware checked is the one the query uses; no `OrgID` in the request type ([ACCESS-CONTROL.md](references\u002FACCESS-CONTROL.md#the-tenant-the-check-saw)) | review |\n| Route outside the auth wrapper | Wrap the whole mux once and list the public patterns in the wrapper ([ACCESS-CONTROL.md](references\u002FACCESS-CONTROL.md#authenticate-the-whole-mux)) | review |\n| Auth that fails open | Every branch answers and returns: a store or verifier error is `503`, never anonymous; an empty allowlist denies | review |\n| Batch, export, import, background job | Authorize each item as the requesting principal when the effect happens ([ACCESS-CONTROL.md](references\u002FACCESS-CONTROL.md#every-door-to-the-same-effect)) | review |\n| Cache shared across tenants | The tenant in the key: `struct{ org, id string }`, not the ID alone | review |\n| Quota, balance, or one-time code checked then spent | One conditional `UPDATE … WHERE` or a locked row ([go-database](..\u002Fgo-database\u002FSKILL.md#transactions)) | review — `-race` sees no race between two transactions |\n| Model output, tool-call arguments | Untrusted input; the tool handler authorizes as the user the agent acts for ([ACCESS-CONTROL.md](references\u002FACCESS-CONTROL.md#model-output-and-tool-calls)) | review |\n| Command injection | `exec.CommandContext(ctx, \"gzip\", \"--keep\", \"--\", name)`: argv, no shell, `--` before input | `gosec` G204, which fires on this safe form too: suppress it on that line with the reason, as in [Injection](#injection) |\n| XSS | `html\u002Ftemplate` (contextual escaping) | `gosec` G203 (unsafe `template.HTML`), G705 (a request value written to the response) |\n| Template written by a client | Never `Parse` client text: it calls any exported method on the data; fixed placeholders ([INJECTION.md](references\u002FINJECTION.md#html-and-templates)) | review — `gosec` G708 sees a request value in `text\u002Ftemplate`'s `Parse` only, not `html\u002Ftemplate`'s |\n| Path traversal | `root.Open(name)` on an `os.Root` opened once at startup ([go-defensive](..\u002Fgo-defensive\u002FSKILL.md#confine-filesystem-access) owns the form) | review — `gosec` G703 reports a request value in `os.Open` and passes `root.Open`; G304 fires on every variable path, so the bundled config excludes it |\n| Upload served inline | `Content-Disposition: attachment`, `X-Content-Type-Options: nosniff`, a `Content-Type` you derived; or a separate origin | review |\n| SSRF | Hostname allowlist by whole label: `host == d` or `strings.HasSuffix(host, \".\"+d)`, re-checked on every redirect in `CheckRedirect`; else a `net.Dialer.Control` that rejects, on the dialed address, `netip.Addr.IsPrivate()`\u002Floopback and the CGNAT and NAT64 prefixes those methods miss ([INJECTION.md](references\u002FINJECTION.md#arbitrary-public-destinations)) | review — `gosec` G704 reports the request either way ([below](#a-taint-finding-on-a-defended-line)) |\n| Decompression bomb | `io.LimitReader` on the `gzip.Reader`, not only `MaxBytesReader` on the body; the same cap on a fetched response body | review — `gosec` G110 sees `io.Copy` from the reader, not `io.ReadAll` |\n| Duration or count from input | Parse, then clamp to a server [min, max]; 0 and huge are both attacks | review |\n| Open redirect | One leading `\u002F`; reject `\u002F\u002F`, `\\`, and control characters; or an allowlist of hosts | review — `gosec` G710 reports the redirect either way ([below](#a-taint-finding-on-a-defended-line)) |\n| Predictable tokens | `crypto\u002Frand.Text()` \u002F `rand.Read` | `gosec` G404 |\n| Timing leak on compare | `subtle.ConstantTimeCompare(a, b) == 1` | review |\n| Webhook signature | HMAC over the raw body bytes and the signed timestamp, `hmac.Equal`, a tolerance window, decode only after ([SECRETS-AND-CRYPTO.md](references\u002FSECRETS-AND-CRYPTO.md#inbound-webhook-signatures)) | review |\n| Account enumeration at login | A dummy hash for an unknown user, one error for both failures, a semaphore on concurrent hashes ([SECRETS-AND-CRYPTO.md](references\u002FSECRETS-AND-CRYPTO.md#passwords)) | review |\n| Weak password hash | argon2id (or `crypto\u002Fpbkdf2` when stdlib-only) | review — G401 and the G501\u002FG505 import blocklists catch MD5\u002FSHA1 only, not `sha256.Sum256(password)` |\n| `InsecureSkipVerify: true` | Never outside a test against a local self-signed server; `RootCAs` for a private CA | `gosec` G402 |\n| `MinVersion` | Leave unset (1.2 is the default) unless the service is TLS 1.3-only | `gosec` G402 |\n| `CurvePreferences` | No list: the default has `X25519MLKEM768`, `SecP256r1MLKEM768`, and `SecP384r1MLKEM1024`. A list that omits any is a finding, fixed by deleting it, not reordering it (order is ignored); only opt-in `MLKEM1024` needs a list ([SECRETS-AND-CRYPTO.md](references\u002FSECRETS-AND-CRYPTO.md#tls)) | review |\n| CSRF | `http.NewCrossOriginProtection().Handler(mux)` | review |\n| CORS with credentials | Exact-origin allowlist, `Vary: Origin`; the same list in `AddTrustedOrigin` ([HTTP Surface](#http-surface)) | review |\n| Secret in a log, `fmt`, or JSON | The secret type in [go-logging](..\u002Fgo-logging\u002FSKILL.md#what-not-to-log), which covers an exported struct field; a struct with the secret in an unexported field prints itself without it (same section) | review |\n| Detail returned in an error | Status + generic text; detail stays server-side | review |\n| Known CVE in deps | `govulncheck .\u002F...` (gate) | gate |\n\nApply a row's defense **at the boundary**, once — not at every call site\ndownstream, where it is forgotten.\n\n`gosec` is in the baseline `.golangci.yml`; a finding it raises is a gate\nfailure, not advice. See [go-linting](..\u002Fgo-linting\u002FSKILL.md). A row marked\n`review` has no tool, or a tool that sees one shape of it; a clean `gosec`\nrun does not clear it.\n\n### A taint finding on a defended line\n\n`gosec`'s taint rules (G701–G710) follow a request value to a sink and cannot\nsee the check in between: G704 reports a client URL fetched after the\nallowlist or through `publicClient`, G710 a redirect after `localRedirect`,\nand G120 a `ParseMultipartForm` under `MaxBytesReader`. Once the defense is\nin the code, suppress on the reported line with that defense as the reason —\na fragment of three handlers; never suppress first and defend later:\n\n```go\nreq, err := http.NewRequestWithContext(ctx, http.MethodGet, target, nil) \u002F\u002Fnolint:gosec \u002F\u002F G704: client dials through a Control that rejects private ranges\nresp, err := client.Do(req)                                              \u002F\u002Fnolint:gosec \u002F\u002F G704: the same client\nhttp.Redirect(w, r, next, http.StatusSeeOther)                           \u002F\u002Fnolint:gosec \u002F\u002F G710: next passed localRedirect\nerr := r.ParseMultipartForm(1 \u003C\u003C 20)                                     \u002F\u002Fnolint:gosec \u002F\u002F G120: body capped by MaxBytesReader above\n```\n\n## Injection\n\nThe defense is always the same shape: hand data to an API that knows it is\ndata. String assembly is what turns data into code.\n\n```go\n\u002F\u002F ✗ Bad — the shell re-parses ref; \"main; rm -rf \u002F\" is one argument to sh\nout, err := exec.Command(\"sh\", \"-c\", \"git log \"+ref).Output()\n\n\u002F\u002F ✓ Good — argv, no shell; option parsing ends before ref, so \"--output=x\" stays a revision\nout, err := exec.CommandContext(ctx, \"git\", \"log\", \"--end-of-options\", ref, \"--\").Output() \u002F\u002Fnolint:gosec \u002F\u002F G204: fixed program, argv, options end before ref\n```\n\n`--end-of-options` is git's spelling, because `--` already separates\nrevisions from paths there; every other program takes `--` before the first\nargument built from input, as in the Quick Reference row.\n\n## Secrets\n\n- Read secrets from the environment or a mounted file at startup; never from\n  a literal, a flag default, or a committed config. Fail fast when missing.\n- Verify a signed token the client presents (JWT, a signed cookie) with a\n  fixed algorithm allowlist and keys you already hold: `kid` only chooses\n  among those keys, and `alg`, `jku`, or `x5u` inside the token never choose\n  either. Reject a token without `exp`, check `exp` against the server clock,\n  and check `iss` and `aud` against fixed values.\n- Keep secrets out of errors: never `fmt.Errorf(\"auth %s: %w\", token, err)`.\n\nKey derivation, TLS defaults, and cookie flags in\n[SECRETS-AND-CRYPTO.md](references\u002FSECRETS-AND-CRYPTO.md).\n\n## HTTP Surface\n\n[go-http](..\u002Fgo-http\u002FSKILL.md) owns the server construction; the security\nitems it carries are `ReadHeaderTimeout`, `MaxBytesReader` on every decoded\nbody, `MaxHeaderValueCount`, and `http.NewCrossOriginProtection`. Add here:\n\n```go\nhttp.SetCookie(w, &http.Cookie{\n    Name: \"__Host-session\", Value: id, \u002F\u002F the prefix: browsers enforce Secure, Path=\u002F, no Domain\n    HttpOnly: true, Secure: true, SameSite: http.SameSiteLaxMode,\n    Path: \"\u002F\", MaxAge: 3600,\n})\n```\n\n`gosec` G124 reports a cookie missing any of `Secure`, `HttpOnly`, or\n`SameSite`.\n\nCORS relaxes the same-origin policy, so the allowlist is the whole defense:\nexact origins, never a reflected `Origin` or `\"null\"` beside\n`Allow-Credentials`, and the same list trusted in `CrossOriginProtection`\n([ACCESS-CONTROL.md](references\u002FACCESS-CONTROL.md#cors-with-credentials) has\nthe middleware).\n\n- `net\u002Fhttp\u002Fpprof` and `expvar` register on `http.DefaultServeMux` in `init`,\n  so one blank import anywhere in the binary publishes them on every server\n  whose `Handler` is nil. Serve the public listener from your own mux and\n  mount the debug handlers on a separate internal listener — they leak heap\n  contents and goroutine stacks. `gosec` G108 reports the `pprof` blank\n  import wherever it is, the internal listener included: suppress it there\n  with the listener as the reason.\n- `X-Forwarded-For` is client-writable and append-only: join every\n  `r.Header.Values(\"X-Forwarded-For\")` line and take the rightmost entry that\n  is not one of your own proxies; `r.Header.Get` returns only the first line,\n  which the client wrote when a proxy adds its own. With no proxy in front,\n  `r.RemoteAddr`.\n\n## Review Mode\n\nAn audit traces data flow from every input to its first sink, checks every\nQuick Reference row marked `review`, and ranks each finding critical to low by\nwhat the evidence shows: [REVIEW.md](references\u002FREVIEW.md).\n\n## Related Skills\n\n- [go-database](..\u002Fgo-database\u002FSKILL.md): placeholder queries, identifier allowlists.\n- [go-logging](..\u002Fgo-logging\u002FSKILL.md): `LogValuer` and what never reaches a log line.\n- [go-resilience](..\u002Fgo-resilience\u002FSKILL.md): rate limits, duplicate delivery, and idempotency keys.\n- [go-troubleshooting](..\u002Fgo-troubleshooting\u002FSKILL.md): a crash or hang rather than a known vulnerability.\n","# Go Security\n\n> Compatibility: Baseline Go 1.27 (see [COMPATIBILITY.md](..\u002Fgo-style-core\u002Freferences\u002FCOMPATIBILITY.md)). `os.Root` and\n> `crypto\u002Fpbkdf2`, `crypto\u002Fhkdf`, `crypto\u002Fsha3` are Go 1.24+;\n> `http.NewCrossOriginProtection` Go 1.25+; `crypto\u002Fsubtle`, `html\u002Ftemplate`,\n> and `net\u002Fnetip` are long-standing stdlib.\n\nA vulnerability is a trust boundary nobody named. Before writing or reviewing,\nanswer three questions: **where does untrusted data enter**, **which sensitive\noperation does it reach** (query, shell, file path, URL fetch, HTML, log), and\n**what is the blast radius if the defense fails**. Every rule below is one of\nthose paths, with the standard-library defense that closes it.\n\n## Resource Routing\n\n- `references\u002FINJECTION.md` - Read when untrusted data reaches SQL, `os\u002Fexec`, a template or a template's source, a file path, an outbound URL, a redirect, or a decompressor, or is served back as a download.\n- `references\u002FSECRETS-AND-CRYPTO.md` - Read when handling passwords, a login or reset flow, tokens, API keys, webhook signatures, TLS configuration, or choosing a hash or cipher.\n- `references\u002FACCESS-CONTROL.md` - Read when code decides who may act: auth middleware and route registration, the tenant a query uses, batch, export, import, or background jobs, a cache, model tool calls, mTLS, gRPC, or queue identity, an OAuth login, or CORS with credentials.\n- `references\u002FREVIEW.md` - Read when asked to audit or find vulnerabilities, or when writing up and ranking a security finding inside a review.\n\n## Quick Reference\n\n| Threat | Defense | Caught by |\n|---|---|---|\n| SQL injection | `QueryContext(ctx, q, args...)` placeholders; identifiers from a `switch` over known names | `gosec` G201\u002FG202, and G701 for a request value in the query text |\n| Foreign row by ID | `AND org_id =` the caller's tenant, a parameter beside the ID ([INJECTION.md](references\u002FINJECTION.md#sql)); a foreign ID is `sql.ErrNoRows` | review |\n| Tenant from the client | The tenant the middleware checked is the one the query uses; no `OrgID` in the request type ([ACCESS-CONTROL.md](references\u002FACCESS-CONTROL.md#the-tenant-the-check-saw)) | review |\n| Route outside the auth wrapper | Wrap the whole mux once and list the public patterns in the wrapper ([ACCESS-CONTROL.md](references\u002FACCESS-CONTROL.md#authenticate-the-whole-mux)) | review |\n| Auth that fails open | Every branch answers and returns: a store or verifier error is `503`, never anonymous; an empty allowlist denies | review |\n| Batch, export, import, background job | Authorize each item as the requesting principal when the effect happens ([ACCESS-CONTROL.md](references\u002FACCESS-CONTROL.md#every-door-to-the-same-effect)) | review |\n| Cache shared across tenants | The tenant in the key: `struct{ org, id string }`, not the ID alone | review |\n| Quota, balance, or one-time code checked then spent | One conditional `UPDATE … WHERE` or a locked row ([go-database](..\u002Fgo-database\u002FSKILL.md#transactions)) | review — `-race` sees no race between two transactions |\n| Model output, tool-call arguments | Untrusted input; the tool handler authorizes as the user the agent acts for ([ACCESS-CONTROL.md](references\u002FACCESS-CONTROL.md#model-output-and-tool-calls)) | review |\n| Command injection | `exec.CommandContext(ctx, \"gzip\", \"--keep\", \"--\", name)`: argv, no shell, `--` before input | `gosec` G204, which fires on this safe form too: suppress it on that line with the reason, as in [Injection](#injection) |\n| XSS | `html\u002Ftemplate` (contextual escaping) | `gosec` G203 (unsafe `template.HTML`), G705 (a request value written to the response) |\n| Template written by a client | Never `Parse` client text: it calls any exported method on the data; fixed placeholders ([INJECTION.md](references\u002FINJECTION.md#html-and-templates)) | review — `gosec` G708 sees a request value in `text\u002Ftemplate`'s `Parse` only, not `html\u002Ftemplate`'s |\n| Path traversal | `root.Open(name)` on an `os.Root` opened once at startup ([go-defensive](..\u002Fgo-defensive\u002FSKILL.md#confine-filesystem-access) owns the form) | review — `gosec` G703 reports a request value in `os.Open` and passes `root.Open`; G304 fires on every variable path, so the bundled config excludes it |\n| Upload served inline | `Content-Disposition: attachment`, `X-Content-Type-Options: nosniff`, a `Content-Type` you derived; or a separate origin | review |\n| SSRF | Hostname allowlist by whole label: `host == d` or `strings.HasSuffix(host, \".\"+d)`, re-checked on every redirect in `CheckRedirect`; else a `net.Dialer.Control` that rejects, on the dialed address, `netip.Addr.IsPrivate()`\u002Floopback and the CGNAT and NAT64 prefixes those methods miss ([INJECTION.md](references\u002FINJECTION.md#arbitrary-public-destinations)) | review — `gosec` G704 reports the request either way ([below](#a-taint-finding-on-a-defended-line)) |\n| Decompression bomb | `io.LimitReader` on the `gzip.Reader`, not only `MaxBytesReader` on the body; the same cap on a fetched response body | review — `gosec` G110 sees `io.Copy` from the reader, not `io.ReadAll` |\n| Duration or count from input | Parse, then clamp to a server [min, max]; 0 and huge are both attacks | review |\n| Open redirect | One leading `\u002F`; reject `\u002F\u002F`, `\\`, and control characters; or an allowlist of hosts | review — `gosec` G710 reports the redirect either way ([below](#a-taint-finding-on-a-defended-line)) |\n| Predictable tokens | `crypto\u002Frand.Text()` \u002F `rand.Read` | `gosec` G404 |\n| Timing leak on compare | `subtle.ConstantTimeCompare(a, b) == 1` | review |\n| Webhook signature | HMAC over the raw body bytes and the signed timestamp, `hmac.Equal`, a tolerance window, decode only after ([SECRETS-AND-CRYPTO.md](references\u002FSECRETS-AND-CRYPTO.md#inbound-webhook-signatures)) | review |\n| Account enumeration at login | A dummy hash for an unknown user, one error for both failures, a semaphore on concurrent hashes ([SECRETS-AND-CRYPTO.md](references\u002FSECRETS-AND-CRYPTO.md#passwords)) | review |\n| Weak password hash | argon2id (or `crypto\u002Fpbkdf2` when stdlib-only) | review — G401 and the G501\u002FG505 import blocklists catch MD5\u002FSHA1 only, not `sha256.Sum256(password)` |\n| `InsecureSkipVerify: true` | Never outside a test against a local self-signed server; `RootCAs` for a private CA | `gosec` G402 |\n| `MinVersion` | Leave unset (1.2 is the default) unless the service is TLS 1.3-only | `gosec` G402 |\n| `CurvePreferences` | No list: the default has `X25519MLKEM768`, `SecP256r1MLKEM768`, and `SecP384r1MLKEM1024`. A list that omits any is a finding, fixed by deleting it, not reordering it (order is ignored); only opt-in `MLKEM1024` needs a list ([SECRETS-AND-CRYPTO.md](references\u002FSECRETS-AND-CRYPTO.md#tls)) | review |\n| CSRF | `http.NewCrossOriginProtection().Handler(mux)` | review |\n| CORS with credentials | Exact-origin allowlist, `Vary: Origin`; the same list in `AddTrustedOrigin` ([HTTP Surface](#http-surface)) | review |\n| Secret in a log, `fmt`, or JSON | The secret type in [go-logging](..\u002Fgo-logging\u002FSKILL.md#what-not-to-log), which covers an exported struct field; a struct with the secret in an unexported field prints itself without it (same section) | review |\n| Detail returned in an error | Status + generic text; detail stays server-side | review |\n| Known CVE in deps | `govulncheck .\u002F...` (gate) | gate |\n\nApply a row's defense **at the boundary**, once — not at every call site\ndownstream, where it is forgotten.\n\n`gosec` is in the baseline `.golangci.yml`; a finding it raises is a gate\nfailure, not advice. See [go-linting](..\u002Fgo-linting\u002FSKILL.md). A row marked\n`review` has no tool, or a tool that sees one shape of it; a clean `gosec`\nrun does not clear it.\n\n### A taint finding on a defended line\n\n`gosec`'s taint rules (G701–G710) follow a request value to a sink and cannot\nsee the check in between: G704 reports a client URL fetched after the\nallowlist or through `publicClient`, G710 a redirect after `localRedirect`,\nand G120 a `ParseMultipartForm` under `MaxBytesReader`. Once the defense is\nin the code, suppress on the reported line with that defense as the reason —\na fragment of three handlers; never suppress first and defend later:\n\n```go\nreq, err := http.NewRequestWithContext(ctx, http.MethodGet, target, nil) \u002F\u002Fnolint:gosec \u002F\u002F G704: client dials through a Control that rejects private ranges\nresp, err := client.Do(req)                                              \u002F\u002Fnolint:gosec \u002F\u002F G704: the same client\nhttp.Redirect(w, r, next, http.StatusSeeOther)                           \u002F\u002Fnolint:gosec \u002F\u002F G710: next passed localRedirect\nerr := r.ParseMultipartForm(1 \u003C\u003C 20)                                     \u002F\u002Fnolint:gosec \u002F\u002F G120: body capped by MaxBytesReader above\n```\n\n## Injection\n\nThe defense is always the same shape: hand data to an API that knows it is\ndata. String assembly is what turns data into code.\n\n```go\n\u002F\u002F ✗ Bad — the shell re-parses ref; \"main; rm -rf \u002F\" is one argument to sh\nout, err := exec.Command(\"sh\", \"-c\", \"git log \"+ref).Output()\n\n\u002F\u002F ✓ Good — argv, no shell; option parsing ends before ref, so \"--output=x\" stays a revision\nout, err := exec.CommandContext(ctx, \"git\", \"log\", \"--end-of-options\", ref, \"--\").Output() \u002F\u002Fnolint:gosec \u002F\u002F G204: fixed program, argv, options end before ref\n```\n\n`--end-of-options` is git's spelling, because `--` already separates\nrevisions from paths there; every other program takes `--` before the first\nargument built from input, as in the Quick Reference row.\n\n## Secrets\n\n- Read secrets from the environment or a mounted file at startup; never from\n  a literal, a flag default, or a committed config. Fail fast when missing.\n- Verify a signed token the client presents (JWT, a signed cookie) with a\n  fixed algorithm allowlist and keys you already hold: `kid` only chooses\n  among those keys, and `alg`, `jku`, or `x5u` inside the token never choose\n  either. Reject a token without `exp`, check `exp` against the server clock,\n  and check `iss` and `aud` against fixed values.\n- Keep secrets out of errors: never `fmt.Errorf(\"auth %s: %w\", token, err)`.\n\nKey derivation, TLS defaults, and cookie flags in\n[SECRETS-AND-CRYPTO.md](references\u002FSECRETS-AND-CRYPTO.md).\n\n## HTTP Surface\n\n[go-http](..\u002Fgo-http\u002FSKILL.md) owns the server construction; the security\nitems it carries are `ReadHeaderTimeout`, `MaxBytesReader` on every decoded\nbody, `MaxHeaderValueCount`, and `http.NewCrossOriginProtection`. Add here:\n\n```go\nhttp.SetCookie(w, &http.Cookie{\n    Name: \"__Host-session\", Value: id, \u002F\u002F the prefix: browsers enforce Secure, Path=\u002F, no Domain\n    HttpOnly: true, Secure: true, SameSite: http.SameSiteLaxMode,\n    Path: \"\u002F\", MaxAge: 3600,\n})\n```\n\n`gosec` G124 reports a cookie missing any of `Secure`, `HttpOnly`, or\n`SameSite`.\n\nCORS relaxes the same-origin policy, so the allowlist is the whole defense:\nexact origins, never a reflected `Origin` or `\"null\"` beside\n`Allow-Credentials`, and the same list trusted in `CrossOriginProtection`\n([ACCESS-CONTROL.md](references\u002FACCESS-CONTROL.md#cors-with-credentials) has\nthe middleware).\n\n- `net\u002Fhttp\u002Fpprof` and `expvar` register on `http.DefaultServeMux` in `init`,\n  so one blank import anywhere in the binary publishes them on every server\n  whose `Handler` is nil. Serve the public listener from your own mux and\n  mount the debug handlers on a separate internal listener — they leak heap\n  contents and goroutine stacks. `gosec` G108 reports the `pprof` blank\n  import wherever it is, the internal listener included: suppress it there\n  with the listener as the reason.\n- `X-Forwarded-For` is client-writable and append-only: join every\n  `r.Header.Values(\"X-Forwarded-For\")` line and take the rightmost entry that\n  is not one of your own proxies; `r.Header.Get` returns only the first line,\n  which the client wrote when a proxy adds its own. With no proxy in front,\n  `r.RemoteAddr`.\n\n## Review Mode\n\nAn audit traces data flow from every input to its first sink, checks every\nQuick Reference row marked `review`, and ranks each finding critical to low by\nwhat the evidence shows: [REVIEW.md](references\u002FREVIEW.md).\n\n## Related Skills\n\n- [go-database](..\u002Fgo-database\u002FSKILL.md): placeholder queries, identifier allowlists.\n- [go-logging](..\u002Fgo-logging\u002FSKILL.md): `LogValuer` and what never reaches a log line.\n- [go-resilience](..\u002Fgo-resilience\u002FSKILL.md): rate limits, duplicate delivery, and idempotency keys.\n- [go-troubleshooting](..\u002Fgo-troubleshooting\u002FSKILL.md): a crash or hang rather than a known vulnerability.\n",{"name":5,"description":7},"main","59ac8ac7a0dd394878aaa0a7a7ecbc227356739f","skills\u002Fgo-security",2,"https:\u002F\u002Fgithub.com\u002Fh0rn3t\u002Fgolang-skills","https:\u002F\u002Fgithub.com\u002Fh0rn3t","2026-11-14 04:23:12",{"source":8,"skillName":5,"commands":32,"prompt":42,"zipAvailable":43},[33,36,39],{"tool":34,"command":35},"npx","npx skills add h0rn3t\u002Fgolang-skills --skill go-security",{"tool":37,"command":38},"bunx","bunx skills add h0rn3t\u002Fgolang-skills --skill go-security",{"tool":40,"command":41},"pnpm","pnpm dlx skills add h0rn3t\u002Fgolang-skills --skill go-security","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fh0rn3t\u002Fgolang-skills\u002Fblob\u002Fmain\u002Fskills\u002Fgo-security\u002FSKILL.md",true,[45,51,55,59],{"path":46,"resourceType":47,"resourceTypeDesc":48,"sizeBytes":49,"sourceHtmlUrl":50},"references\u002FACCESS-CONTROL.md","REFERENCE","参考文档",12241,"https:\u002F\u002Fgithub.com\u002Fh0rn3t\u002Fgolang-skills\u002Fblob\u002Fmain\u002Fskills\u002Fgo-security\u002Freferences\u002FACCESS-CONTROL.md",{"path":52,"resourceType":47,"resourceTypeDesc":48,"sizeBytes":53,"sourceHtmlUrl":54},"references\u002FINJECTION.md",14128,"https:\u002F\u002Fgithub.com\u002Fh0rn3t\u002Fgolang-skills\u002Fblob\u002Fmain\u002Fskills\u002Fgo-security\u002Freferences\u002FINJECTION.md",{"path":56,"resourceType":47,"resourceTypeDesc":48,"sizeBytes":57,"sourceHtmlUrl":58},"references\u002FREVIEW.md",3512,"https:\u002F\u002Fgithub.com\u002Fh0rn3t\u002Fgolang-skills\u002Fblob\u002Fmain\u002Fskills\u002Fgo-security\u002Freferences\u002FREVIEW.md",{"path":60,"resourceType":47,"resourceTypeDesc":48,"sizeBytes":61,"sourceHtmlUrl":62},"references\u002FSECRETS-AND-CRYPTO.md",13863,"https:\u002F\u002Fgithub.com\u002Fh0rn3t\u002Fgolang-skills\u002Fblob\u002Fmain\u002Fskills\u002Fgo-security\u002Freferences\u002FSECRETS-AND-CRYPTO.md",[64,71,78,85,92,99],{"skillNo":65,"name":66,"nameZh":6,"description":67,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":68,"categories":69,"keywords":70,"publishedAt":19},"01M7BQEMJBPJWY6CCGVKW27SH0","go-troubleshooting","Use when investigating a bug or ticket in a Go service whose cause is unknown — wrong or missing results, tenant-specific behavior, a regression, stage\u002Fprod\u002FCI differences, a panic, hang, deadlock, leak, unexplained CPU\u002FRSS growth, or a flaky test. Also use for pasted stack traces, profiles, logs, or requests to find a Go issue's root cause, even without the word debug. Does not cover rewriting ticket text, implementing an already-diagnosed fix alone (use its topic skill), or optimizing a known bottleneck (see go-performance).","https:\u002F\u002Fgithub.com\u002Fh0rn3t\u002Fgolang-skills\u002Fblob\u002Fmain\u002Fskills\u002Fgo-troubleshooting\u002FSKILL.md",[],[],{"skillNo":72,"name":73,"nameZh":6,"description":74,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":75,"categories":76,"keywords":77,"publishedAt":19},"01M7BQEFVSRHNDND750SB69WD8","go-testing","Use when writing, reviewing, or improving Go test code — including table-driven tests, subtests, parallel tests, test helpers, test doubles, and assertions with cmp.Diff. Also use when a user asks to write a test for a Go function, even if they don't mention specific patterns like table-driven tests or subtests. Does not cover benchmark performance testing (see go-performance).","https:\u002F\u002Fgithub.com\u002Fh0rn3t\u002Fgolang-skills\u002Fblob\u002Fmain\u002Fskills\u002Fgo-testing\u002FSKILL.md",[],[],{"skillNo":79,"name":80,"nameZh":6,"description":81,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":82,"categories":83,"keywords":84,"publishedAt":19},"01M7BQEA2DRH6H6WFYNJYJJRQQ","go-style-core","Use when resolving Go style or language mechanics such as formatting, nesting, declarations, initialization, scope, shadowing, loops, switches, or enum zero values. API design, naming, errors, and tests have specialized skills.","https:\u002F\u002Fgithub.com\u002Fh0rn3t\u002Fgolang-skills\u002Fblob\u002Fmain\u002Fskills\u002Fgo-style-core\u002FSKILL.md",[],[],{"skillNo":86,"name":87,"nameZh":6,"description":88,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":89,"categories":90,"keywords":91,"publishedAt":19},"01M7BQDZYHG2YRJA3J26HFPKR7","go-resilience","Use when handling Go dependency failures or overload with retries, backoff\u002Fjitter, budgets, idempotency, duplicate delivery, circuit breakers, bulkheads, rate limits, backpressure, or degradation. Unknown root causes belong to go-troubleshooting.","https:\u002F\u002Fgithub.com\u002Fh0rn3t\u002Fgolang-skills\u002Fblob\u002Fmain\u002Fskills\u002Fgo-resilience\u002FSKILL.md",[],[],{"skillNo":93,"name":94,"nameZh":6,"description":95,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":96,"categories":97,"keywords":98,"publishedAt":19},"01M7BQDVG7DH2G9Z97Y8H3P3E9","go-performance","Use when optimizing slow or performance-critical Go code, allocations, string concatenation in loops, or benchmarks. Also use when writing or reviewing a cache, including implementing one from a stub — its key, its expiry, and how a miss loads. Concurrent code patterns belong to go-concurrency.","https:\u002F\u002Fgithub.com\u002Fh0rn3t\u002Fgolang-skills\u002Fblob\u002Fmain\u002Fskills\u002Fgo-performance\u002FSKILL.md",[],[],{"skillNo":100,"name":101,"nameZh":6,"description":102,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":103,"categories":104,"keywords":105,"publishedAt":19},"01M7BQDRS36WFNPVPCX3DHN459","go-packages","Use when creating or splitting Go packages, organizing imports or dependencies, or structuring a new Go project. Individual identifier naming belongs to go-naming.","https:\u002F\u002Fgithub.com\u002Fh0rn3t\u002Fgolang-skills\u002Fblob\u002Fmain\u002Fskills\u002Fgo-packages\u002FSKILL.md",[],[]]