xiaohongshu
xiaohongshu
go-security-audit
Security audit for Go backend code and SDKs. Covers Go-specific vulnerabilities, common security pitfalls, and best practices. Use when auditing Go codebases.
Full skill instructions
Comprehensive security audit for Go codebases covering Go-specific vulnerabilities, common pitfalls, and security best practices.
// VULNERABLE - string formatting
query := fmt.Sprintf("SELECT * FROM users WHERE id = %s", userInput)
db.Query(query)
// SECURE - parameterized query
db.Query("SELECT * FROM users WHERE id = ?", userInput)
// Or with sqlx:
db.Get(&user, "SELECT * FROM users WHERE id = $1", userInput)
// VULNERABLE - shell expansion
cmd := exec.Command("sh", "-c", "ls " + userInput)
// SECURE - no shell, array arguments
cmd := exec.Command("ls", userInput) // userInput as single arg
// VULNERABLE - user controls path
path := filepath.Join("/uploads", userInput)
// userInput = "../../../etc/passwd"
// SECURE - validate path stays in directory
path := filepath.Join("/uploads", filepath.Base(userInput))
// Or check after resolution:
absPath, _ := filepath.Abs(path)
if !strings.HasPrefix(absPath, "/uploads/") {
return ErrInvalidPath
}
// VULNERABLE - race on shared state
var balance int64
func withdraw(amount int64) bool {
if balance >= amount { // TOCTOU race
balance -= amount
return true
}
return false
}
// SECURE - use mutex or atomic
var mu sync.Mutex
func withdraw(amount int64) bool {
mu.Lock()
defer mu.Unlock()
if balance >= amount {
balance -= amount
return true
}
return false
}
// VULNERABLE - ignored error
data, _ := ioutil.ReadFile(path) // Error ignored!
// VULNERABLE - panic in HTTP handler (DoS)
func handler(w http.ResponseWriter, r *http.Request) {
panic("oops") // Kills entire server
}
// SECURE - handle errors
data, err := ioutil.ReadFile(path)
if err != nil {
return fmt.Errorf("read config: %w", err)
}
// VULNERABLE - math/rand is predictable
import "math/rand"
token := rand.Int63()
// SECURE - crypto/rand for security
import "crypto/rand"
var token [32]byte
rand.Read(token[:])
findings:
- title: "SQL Injection via fmt.Sprintf"
severity: critical
attack_scenario: "Attacker injects SQL through userInput parameter"
preconditions: "None"
reachability: public
impact: "Database compromise"
confidence: high
cwe_id: "CWE-89"
affected_assets:
- "pkg/db/users.go:45"
taint_path: "r.URL.Query().Get('id') -> fmt.Sprintf() -> db.Query()"
db.Query(fmt.Sprintf(...))
db.Exec(string + variable)
db.Raw(userInput)
exec.Command("sh", "-c", ...)
exec.Command(userInput, ...)
os.StartProcess with user args
os.Open(userPath)
ioutil.ReadFile(userPath)
http.ServeFile without path validation
math/rand for tokens
md5.Sum for passwords
des.NewCipher (weak)
cipher.NewCBCDecrypter without MAC
http.Get(userURL) // SSRF
http.ListenAndServe with no TLS
ResponseWriter.Write without Content-Type
| Issue | Severity |
|---|---|
| SQL Injection | Critical |
| Command Injection | Critical |
| Path Traversal (read) | High |
| Path Traversal (write) | Critical |
| Race condition (security) | High |
| Weak crypto (passwords) | High |
| SSRF | High |
| Ignored security error | Medium |
| math/rand for tokens | High |
| Panic in HTTP handler | Medium |
# Static analysis
gosec ./...
staticcheck ./...
go vet ./...
# Race detection
go test -race ./...
# Dependency vulnerabilities
govulncheck ./...
Register findings and import scanner results using kyco CLI:
kyco project list
kyco project select PROJECT_ID
# Generate SARIF from gosec
gosec -fmt sarif -out gosec-results.sarif ./...
# Import into KYCo
kyco finding import gosec-results.sarif --project PROJECT_ID
# Or import semgrep results
semgrep --config auto --sarif -o semgrep.sarif .
kyco finding import semgrep.sarif --project PROJECT_ID
kyco finding create \
--title "SQL Injection via fmt.Sprintf" \
--project PROJECT_ID \
--severity critical \
--cwe CWE-89 \
--attack-scenario "Attacker injects SQL through userInput parameter" \
--assets "pkg/db/users.go:45"
kyco finding list --project PROJECT_ID
kyco gui # Opens Kanban board
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience