go-security
Use when writing, reviewing, or auditing Go code for security. Covers input validation, SQL injection prevention, path traversal, secrets management, cryptography, HTTP security headers, and dependency scanning.
What this skill does
# Go Security
Secure coding patterns for production Go. Covers OWASP top risks as they apply to Go.
## SQL Injection Prevention
Always use parameterized queries. Never interpolate user input into SQL strings.
```go
// Wrong: SQL injection
query := "SELECT * FROM users WHERE id = '" + id + "'"
db.Query(query)
// Correct: parameterized query
db.QueryContext(ctx, "SELECT * FROM users WHERE id = $1", id)
```
This applies to all database drivers. The placeholder syntax varies (`$1` for postgres, `?` for mysql).
## Path Traversal Prevention
### os.Root (Go 1.24+)
Use `os.Root` for scoped file access. Paths are resolved within the root directory and cannot escape it.
```go
root, err := os.OpenRoot("/var/data/uploads")
if err != nil {
return err
}
defer root.Close()
// Safe: "../etc/passwd" is rejected
f, err := root.Open(userProvidedFilename)
if err != nil {
return err
}
defer f.Close()
```
### Pre-Go 1.24
Use `filepath.Clean` and verify the result stays within the intended directory:
```go
cleaned := filepath.Clean(userInput)
absPath := filepath.Join(baseDir, cleaned)
// Verify the path is still under baseDir
if !strings.HasPrefix(absPath, filepath.Clean(baseDir)+string(os.PathSeparator)) {
return fmt.Errorf("path traversal: %s", userInput)
}
```
## Input Validation
Validate all external input at system boundaries. Internal code can trust validated data.
```go
func parseUserID(raw string) (int64, error) {
id, err := strconv.ParseInt(raw, 10, 64)
if err != nil {
return 0, fmt.Errorf("invalid user ID %q: %w", raw, err)
}
if id <= 0 {
return 0, fmt.Errorf("user ID must be positive, got %d", id)
}
return id, nil
}
```
For structured input, decode into typed structs and validate fields:
```go
var req CreateUserRequest
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
http.Error(w, "invalid request body", http.StatusBadRequest)
return
}
if err := req.Validate(); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
```
## Secrets Management
Never hardcode secrets. Never log them.
```go
// Wrong: secret in source code
const apiKey = "do-not-hardcode-secrets"
// Wrong: secret in error message or log
slog.Info("connecting", "dsn", os.Getenv("DATABASE_URL"))
// Correct: read from environment, treat as opaque
dsn := os.Getenv("DATABASE_URL")
if dsn == "" {
return errors.New("DATABASE_URL is required")
}
slog.Info("connecting to database") // no secret in log
```
Use `type Secret string` with a custom `String()` method to prevent accidental logging:
```go
type Secret string
func (s Secret) String() string { return "[REDACTED]" }
func (s Secret) GoString() string { return "[REDACTED]" }
// The actual value is accessible via explicit conversion
dsn := string(cfg.DatabaseURL)
```
## Cryptography
Use the standard library. Do not implement your own crypto.
```go
import "crypto/rand"
// Generate random bytes (for tokens, nonces)
token := make([]byte, 32)
if _, err := rand.Read(token); err != nil {
return err
}
// Do NOT use math/rand for security-sensitive values
```
### Password Hashing
Use bcrypt or argon2. Never store passwords as plaintext or simple hashes.
```go
import "golang.org/x/crypto/bcrypt"
// Hash a password
hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
// Verify a password
err := bcrypt.CompareHashAndPassword(hash, []byte(password))
```
## HTTP Security
### Timeouts
Always set timeouts on HTTP servers and clients. Default zero value means no timeout.
```go
srv := &http.Server{
Addr: ":8080",
Handler: handler,
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
IdleTimeout: 120 * time.Second,
}
client := &http.Client{
Timeout: 10 * time.Second,
}
```
### Response Headers
```go
func securityHeaders(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Content-Type-Options", "nosniff")
w.Header().Set("X-Frame-Options", "DENY")
w.Header().Set("Content-Security-Policy", "default-src 'self'")
next.ServeHTTP(w, r)
})
}
```
### Close Response Bodies
Unclosed HTTP response bodies leak connections:
```go
resp, err := client.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
```
## Dependency Scanning
Keep dependencies up to date and scan for known vulnerabilities:
```bash
# Check for known vulnerabilities (built into Go)
go install golang.org/x/vuln/cmd/govulncheck@latest
govulncheck ./...
# Update all dependencies
go get -u ./...
go mod tidy
```
Run `govulncheck` in CI. It checks your code against the Go vulnerability database and only reports vulnerabilities in functions you actually call.
## Concurrency Safety
Shared mutable state without synchronization is a data race and a security risk. Use the race detector in tests:
```bash
go test -race ./...
```
Always run tests with `-race` in CI. Data races can cause memory corruption, which in certain contexts is exploitable.
Related in Backend & APIs
jfrog
IncludedInteract with the JFrog Platform via the JFrog CLI and REST/GraphQL APIs. Use this skill when the user wants to manage Artifactory repositories, upload or download artifacts, manage builds, configure permissions, manage users and groups, work with access tokens, configure JFrog CLI servers, search artifacts, manage properties, set up replication, manage JFrog Projects, run security audits or scans, look up CVE details, query exposures scan results from JFrog Advanced Security, manage release bundles and lifecycle operations, aggregate or export platform data, or perform any JFrog Platform administration task. Also use when the user mentions jf, jfrog, artifactory, xray, distribution, evidence, apptrust, onemodel, graphql, workers, mission control, curation, advanced security, exposures, or any JFrog product name.
cupynumeric-migration-readiness
IncludedPre-migration readiness assessor for porting NumPy to cuPyNumeric. Use BEFORE substantial porting work begins when the user asks whether code will scale on GPU, whether they should migrate to cuPyNumeric, which NumPy patterns transfer cleanly, what must be refactored before porting, or mentions pre-port assessment, scaling analysis, or refactor planning. Inspect the user's source code, look up NumPy usage, cross-reference the cuPyNumeric API support manifest, and distinguish distributed-scaling-friendly patterns from blockers such as unsupported APIs, scalar synchronization, host round-trips, Python/object-heavy control flow, shape/data-dependent branching, and in-place mutation hazards. Produce a verdict of READY, LIGHT REFACTOR, SIGNIFICANT REFACTOR, or NOT RECOMMENDED, with concrete refactor pointers.
alibabacloud-data-agent-skill
IncludedInvoke Alibaba Cloud Apsara Data Agent for Analytics via CLI to perform natural language-driven data analysis on enterprise databases. Data Agent for Analytics is an intelligent data analysis agent developed by Alibaba Cloud Database team for enterprise users. It automatically completes requirement analysis, data understanding, analysis insights, and report generation based on natural language descriptions. This tool supports: discovering data resources (instances/databases/tables) managed in DMS, initiating query or deep analysis sessions, real-time progress tracking, and retrieving analysis conclusions and generated reports. Use this Skill when users need to query databases, analyze data trends, generate data reports, ask questions in natural language, or mention "Data Agent", "data analysis", "database query", "SQL analysis", "data insights".
token-optimizer
IncludedReduce OpenClaw token usage and API costs through smart model routing, heartbeat optimization, budget tracking, and native 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment). Use when token costs are high, API rate limits are being hit, or hosting multiple agents at scale. The 4 executable scripts (context_optimizer, model_router, heartbeat_optimizer, token_tracker) are local-only — no network requests, no subprocess calls, no system modifications. Reference files (PROVIDERS.md, config-patches.json) document optional multi-provider strategies that require external API keys and network access if you choose to use them. See SECURITY.md for full breakdown.
resend-cli
IncludedUse this skill when the task is specifically about operating Resend from an AI agent, terminal session, or CI job via the official resend CLI: installing/authenticating the CLI, sending/listing/updating/cancelling emails, batch sends, domains and DNS, webhooks and local listeners, inbound receiving, contacts, topics, segments, broadcasts, templates, API keys, profiles, or debugging Resend CLI/API failures. Trigger on mentions of Resend CLI, `resend`, `resend doctor`, `resend emails send`, `resend domains`, `resend webhooks listen`, `resend emails receiving`, or agent-friendly terminal automation.
alibabacloud-odps-maxframe-coding
IncludedUse this skill for MaxFrame SDK development and documentation navigation on Alibaba Cloud MaxCompute (ODPS). Helps answer MaxFrame API, concept, official example, and supported pandas API questions; create data processing programs; read/write MaxCompute tables; debug jobs (remote or local); and build custom DPE runtime images. Trigger when users mention MaxFrame, MaxCompute with MaxFrame, ODPS table processing, DPE runtime, MaxFrame docs/examples, DataFrame/Tensor operations, or GPU runtime setup. Works for both English and Chinese queries about Alibaba Cloud data processing with MaxFrame.