From prodsec-skills
Enforces secure coding practices in Go applications. Covers input validation, SQL injection prevention, XSS, cryptography, TLS, unsafe/cgo, and dependency scanning.
How this skill is triggered — by the user, by Claude, or both
Slash command
/prodsec-skills:go-securityThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
- Use **Go modules** for all dependency management
go.sum checksum database provides assurance against module mutationgovulncheck regularly to scan for known vulnerabilities in dependenciesstrconv, regexp) or third-party validators like go-playground/validatorUse html/template (not text/template) for rendering HTML. It applies contextual autoescaping for HTML, CSS, JavaScript, and URL contexts.
name := r.FormValue("name")
tmpl := template.Must(template.ParseGlob("page.html"))
data["Name"] = name
err := tmpl.ExecuteTemplate(w, "page", data)
Use nosurf for CSRF prevention in HTTP handlers.
Use parameterized queries. In Go, statements are prepared on the DB, not the connection:
customerName := r.URL.Query().Get("name")
db.Exec("UPDATE creditcards SET name=? WHERE customerId=?", customerName, 233)
When using db.Query() with string formatting, sanitize all input first.
crypto and golang.org/x/crypto packagesEnforce HTTPS with HSTS headers and explicit TLS server configuration:
w.Header().Add("Strict-Transport-Security", "max-age=63072000; includeSubDomains")
config := &tls.Config{ServerName: "yourServiceName"}
Always encrypt in-transit communication, even for internal services.
unsafe package bypasses Go's type system; subtle mistakes are commonunsafe unless there is no alternative (low-level system calls, performance-critical FFI)Avoid cgo when possible. Known issues:
if err != nil)When unmarshalling JSON into structs with pointer fields, unset pointers remain nil. Dereferencing them causes a panic:
type Foo struct {
Bar *Bar
}
var f Foo
json.Unmarshal([]byte(`{"other":"data"}`), &f)
// f.Bar is nil -- accessing f.Bar.Field will panic
Always check pointer fields for nil before dereferencing.
| Tool | Purpose |
|---|---|
| govulncheck | Scan dependencies for known vulnerabilities |
| golangci-lint | Aggregated linter collection |
| gosec | Go security checker |
go.sum integrity checkinggovulncheck runs in CIhtml/template is used for HTML rendering (not text/template)crypto packages are used (no custom crypto)ServerNameunsafe and cgo usage is justified, minimized, and reviewednpx claudepluginhub redhatproductsecurity/prodsec-skills --plugin prodsec-skillsAudits and secures Go code against vulnerabilities including injection, crypto misuse, filesystem risks, network threats, secrets exposure, and memory safety. Includes govulncheck tooling.
Performs security best-practice reviews for Python, JavaScript/TypeScript, and Go code; loads framework-specific guides to suggest improvements and detect vulnerabilities on explicit request.
Writes idiomatic Go code, reviews PRs, debugs tests, designs APIs, and applies security patterns. Covers table-driven tests, error wrapping, goroutines, generics, gRPC with Google AIP, golangci-lint, and slog logging.