[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7CSM0HDF61NT9G4D73FTQYG":3,"skill-same:01M7CSM0HDF61NT9G4D73FTQYG":50},{"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":27,"commitSha":28,"skillDirectory":29,"forksCount":30,"repositoryHtmlUrl":31,"repositoryHomepageUrl":32,"ownerHtmlUrl":33,"ownerBlogUrl":6,"ownerDescription":34,"updatedAt":35,"install":36,"resources":49},"01M7CSM0HDF61NT9G4D73FTQYG","go-security-pitfalls",null,"Use when reviewing Go changes - net\u002Fhttp and Fiber handlers, database\u002Fsql and GORM queries, os\u002Fexec, filepath and os.Root, html\u002Ftemplate, crypto, TLS and SSH clients, JSON binding","makifbaysal\u002Ftasktrooper","makifbaysal","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F25031940?v=4","01M7CRG3ZCSYZSSEVDMW3DEYC8","Mehmet Akif Baysal","01M7CRG401FJ8YAXH5ER730XYV",122,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fsecurity-agent\u002Fskills\u002Fgo-security-pitfalls\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: go-security-pitfalls\ncategory: security\ndescription: Use when reviewing Go changes - net\u002Fhttp and Fiber handlers, database\u002Fsql and GORM queries, os\u002Fexec, filepath and os.Root, html\u002Ftemplate, crypto, TLS and SSH clients, JSON binding\ntech_stack: Go\nsource: original; informed by trailofbits\u002Fskills (CC BY-SA 4.0, ideas only, own wording); gosec rule ids, Go standard library and GORM security documentation cited, not reproduced\n---\n# Go Security Pitfalls\n\n## Overview\n\nGo removes whole classes of bugs (memory safety, implicit shell, unsafe default deserialization), which makes the remaining ones look innocent: a `fmt.Sprintf` in a query builder, a `HasPrefix` path check, a `template.HTML` conversion. Memory-safety findings in pure Go are excluded; `unsafe` and cgo are the exception.\n\n## 1. SQL: database\u002Fsql, sqlx, GORM (CWE-89)\n\n```go\n\u002F\u002F ❌\ndb.QueryContext(ctx, fmt.Sprintf(\"SELECT * FROM tasks WHERE owner = '%s'\", owner))\n\u002F\u002F ✅\ndb.QueryContext(ctx, \"SELECT * FROM tasks WHERE owner = $1\", owner)\n```\n\nGORM accepts raw SQL in more places than people expect:\n\n```go\n\u002F\u002F ❌ all of these take SQL text\ndb.Where(fmt.Sprintf(\"name = '%s'\", name)).Find(&users)\ndb.Order(r.URL.Query().Get(\"sort\")).Find(&users)   \u002F\u002F ORDER BY injection\ndb.First(&user, r.PathValue(\"id\"))                \u002F\u002F a string id is used as an inline condition\ndb.Raw(\"SELECT … \" + filter).Scan(&rows)\n\u002F\u002F ✅\ndb.Where(\"name = ?\", name).Find(&users)\ndb.Order(clause.OrderByColumn{Column: clause.Column{Name: sortCols[key]}}).Find(&users)\ndb.First(&user, \"id = ?\", id)\n```\n\n## 2. Commands: os\u002Fexec (CWE-78, CWE-88)\n\n`exec.Command` never invokes a shell — unless you pass `sh -c`. With separate args the risk is argument injection:\n\n```go\n\u002F\u002F ❌ shell\nexec.Command(\"sh\", \"-c\", \"git clone \"+repoURL).Run()\n\u002F\u002F ❌ no shell, but repoURL = \"--upload-pack=…\" is an option\nexec.Command(\"git\", \"clone\", repoURL, dir).Run()\n\u002F\u002F ✅\nexec.Command(\"git\", \"clone\", \"--\", repoURL, dir).Run()\n```\n\nAlso check `cmd.Env` built from request data (`NODE_OPTIONS`, `LD_PRELOAD`, `GIT_SSH_COMMAND` — injection-and-dangerous-sinks).\n\n## 3. Paths: filepath, os.Root (CWE-22)\n\n```go\n\u002F\u002F ❌ lexical check: a symlink inside base escapes it, and\n\u002F\u002F    \"\u002Fsrv\u002Fdata-other\u002Fx\" passes HasPrefix(p, \"\u002Fsrv\u002Fdata\")\np := filepath.Join(base, name)\nif !strings.HasPrefix(p, base) { … }\n\n\u002F\u002F ✅ Go 1.24+: lookups confined to the root, symlinks included\nroot, err := os.OpenRoot(base)\nf, err := root.Open(name)\n\u002F\u002F ✅ older Go: reject anything non-local before joining\nif !filepath.IsLocal(name) { return errBadPath }\n```\n\n`http.FileServer(http.Dir(dir))` blocks `..` but follows symlinks inside `dir` and serves dotfiles — a finding when `dir` is the repo root or an upload directory. Archive extraction: check `filepath.IsLocal(hdr.Name)` per entry.\n\n## 4. Templates (CWE-79)\n\n- `html\u002Ftemplate` escapes by context; `text\u002Ftemplate` does not — rendering HTML with `text\u002Ftemplate` is XSS when data is user-controlled.\n- Conversions switch escaping off: `template.HTML(userBio)`, `template.JS(…)`, `template.URL(…)`, `template.HTMLAttr(…)` on user data.\n- `template.New(\"x\").Parse(userText)` — the user writes the template (server-side template injection; with registered funcs that touch the system, worse).\n\n## 5. JSON Binding (CWE-915)\n\n```go\n\u002F\u002F ❌ the request decodes straight into the domain type, Role and OrgID included\nvar u domain.User\njson.NewDecoder(r.Body).Decode(&u)\n\u002F\u002F ✅ a request DTO with only client-settable fields, mapped explicitly\nvar req struct{ Name, Email string }\njson.NewDecoder(r.Body).Decode(&req)\n```\n\n`encoding\u002Fjson` matches keys case-insensitively and lets the last duplicate win: a gateway or validator that checks `\"role\"` misses `\"ROLE\"`. Relevant only when a different component validates the raw JSON.\n\n## 6. Crypto and Transport (CWE-295, CWE-338)\n\n- `math\u002Frand` \u002F `math\u002Frand\u002Fv2` for tokens → `crypto\u002Frand` (`rand.Text()` in Go 1.24+).\n- `tls.Config{InsecureSkipVerify: true}` on a production client.\n- `ssh.InsecureIgnoreHostKey()` → MITM on every SSH connection (CWE-322).\n- Secret comparison: `subtle.ConstantTimeCompare` \u002F `hmac.Equal` (a note at most when missing).\n\n## 7. HTTP Handlers and Middleware\n\n- A route added on the bare router\u002Fapp instead of the authenticated group (security-diff-review-method).\n- `http.Redirect(w, r, r.URL.Query().Get(\"next\"), http.StatusFound)` — open redirect; high confidence only.\n- Client IP from `X-Forwarded-For` or a Fiber\u002FEcho\u002FGin proxy-header setting without a trusted-proxy list, used for an allowlist or an auth decision.\n- An error from the authorization lookup that falls through to the handler (fail open).\n- Outbound `http.Client` fetching user URLs: use a dialer `Control` check and `Proxy: nil` (ssrf-and-url-allowlists).\n\n## 8. unsafe and cgo\n\n`unsafe.Pointer` arithmetic, `unsafe.Slice`\u002F`unsafe.String` over attacker-sized buffers, and C code reached through cgo are memory-unsafe again — trace sizes and lengths from input (native-memory-safety-and-ffi has the bounds, integer and cgo pointer rules).\n\n## Common Mistakes\n\n- Reporting `exec.Command(bin, args...)` as shell injection.\n- Reporting `db.Query(\"… $1\", v)` or GORM `Where(\"x = ?\", v)` as SQL injection.\n- Reporting `gopkg.in\u002Fyaml.v3` or `encoding\u002Fgob` as unsafe deserialization — they do not instantiate arbitrary types.\n- Reporting races between goroutines on non-security state, or integer-conversion lint hits (gosec G115) with no attacker-controlled size.\n\n## Red Flags\n\n- `fmt.Sprintf` feeding `Query`, `Exec`, `Raw`, `Where`, `Order`, `Group`, `Having`.\n- `\"sh\", \"-c\"` \u002F `\"bash\", \"-c\"` in `exec.Command`.\n- `strings.HasPrefix` on a joined path.\n- `template.HTML(` around anything not a constant.\n- `InsecureSkipVerify: true`, `InsecureIgnoreHostKey()`, `math\u002Frand` near \"token\" or \"secret\".\n\n## References (names and links only)\n\n[Go security best practices](https:\u002F\u002Fgo.dev\u002Fdoc\u002Fsecurity\u002Fbest-practices) · [os.Root (Go 1.24)](https:\u002F\u002Fgo.dev\u002Fblog\u002Fosroot) · [gosec rules](https:\u002F\u002Fgithub.com\u002Fsecurego\u002Fgosec#available-rules) · [GORM security](https:\u002F\u002Fgorm.io\u002Fdocs\u002Fsecurity.html) · [govulncheck](https:\u002F\u002Fgo.dev\u002Fdoc\u002Fsecurity\u002Fvuln\u002F)\n","# Go Security Pitfalls\n\n## Overview\n\nGo removes whole classes of bugs (memory safety, implicit shell, unsafe default deserialization), which makes the remaining ones look innocent: a `fmt.Sprintf` in a query builder, a `HasPrefix` path check, a `template.HTML` conversion. Memory-safety findings in pure Go are excluded; `unsafe` and cgo are the exception.\n\n## 1. SQL: database\u002Fsql, sqlx, GORM (CWE-89)\n\n```go\n\u002F\u002F ❌\ndb.QueryContext(ctx, fmt.Sprintf(\"SELECT * FROM tasks WHERE owner = '%s'\", owner))\n\u002F\u002F ✅\ndb.QueryContext(ctx, \"SELECT * FROM tasks WHERE owner = $1\", owner)\n```\n\nGORM accepts raw SQL in more places than people expect:\n\n```go\n\u002F\u002F ❌ all of these take SQL text\ndb.Where(fmt.Sprintf(\"name = '%s'\", name)).Find(&users)\ndb.Order(r.URL.Query().Get(\"sort\")).Find(&users)   \u002F\u002F ORDER BY injection\ndb.First(&user, r.PathValue(\"id\"))                \u002F\u002F a string id is used as an inline condition\ndb.Raw(\"SELECT … \" + filter).Scan(&rows)\n\u002F\u002F ✅\ndb.Where(\"name = ?\", name).Find(&users)\ndb.Order(clause.OrderByColumn{Column: clause.Column{Name: sortCols[key]}}).Find(&users)\ndb.First(&user, \"id = ?\", id)\n```\n\n## 2. Commands: os\u002Fexec (CWE-78, CWE-88)\n\n`exec.Command` never invokes a shell — unless you pass `sh -c`. With separate args the risk is argument injection:\n\n```go\n\u002F\u002F ❌ shell\nexec.Command(\"sh\", \"-c\", \"git clone \"+repoURL).Run()\n\u002F\u002F ❌ no shell, but repoURL = \"--upload-pack=…\" is an option\nexec.Command(\"git\", \"clone\", repoURL, dir).Run()\n\u002F\u002F ✅\nexec.Command(\"git\", \"clone\", \"--\", repoURL, dir).Run()\n```\n\nAlso check `cmd.Env` built from request data (`NODE_OPTIONS`, `LD_PRELOAD`, `GIT_SSH_COMMAND` — injection-and-dangerous-sinks).\n\n## 3. Paths: filepath, os.Root (CWE-22)\n\n```go\n\u002F\u002F ❌ lexical check: a symlink inside base escapes it, and\n\u002F\u002F    \"\u002Fsrv\u002Fdata-other\u002Fx\" passes HasPrefix(p, \"\u002Fsrv\u002Fdata\")\np := filepath.Join(base, name)\nif !strings.HasPrefix(p, base) { … }\n\n\u002F\u002F ✅ Go 1.24+: lookups confined to the root, symlinks included\nroot, err := os.OpenRoot(base)\nf, err := root.Open(name)\n\u002F\u002F ✅ older Go: reject anything non-local before joining\nif !filepath.IsLocal(name) { return errBadPath }\n```\n\n`http.FileServer(http.Dir(dir))` blocks `..` but follows symlinks inside `dir` and serves dotfiles — a finding when `dir` is the repo root or an upload directory. Archive extraction: check `filepath.IsLocal(hdr.Name)` per entry.\n\n## 4. Templates (CWE-79)\n\n- `html\u002Ftemplate` escapes by context; `text\u002Ftemplate` does not — rendering HTML with `text\u002Ftemplate` is XSS when data is user-controlled.\n- Conversions switch escaping off: `template.HTML(userBio)`, `template.JS(…)`, `template.URL(…)`, `template.HTMLAttr(…)` on user data.\n- `template.New(\"x\").Parse(userText)` — the user writes the template (server-side template injection; with registered funcs that touch the system, worse).\n\n## 5. JSON Binding (CWE-915)\n\n```go\n\u002F\u002F ❌ the request decodes straight into the domain type, Role and OrgID included\nvar u domain.User\njson.NewDecoder(r.Body).Decode(&u)\n\u002F\u002F ✅ a request DTO with only client-settable fields, mapped explicitly\nvar req struct{ Name, Email string }\njson.NewDecoder(r.Body).Decode(&req)\n```\n\n`encoding\u002Fjson` matches keys case-insensitively and lets the last duplicate win: a gateway or validator that checks `\"role\"` misses `\"ROLE\"`. Relevant only when a different component validates the raw JSON.\n\n## 6. Crypto and Transport (CWE-295, CWE-338)\n\n- `math\u002Frand` \u002F `math\u002Frand\u002Fv2` for tokens → `crypto\u002Frand` (`rand.Text()` in Go 1.24+).\n- `tls.Config{InsecureSkipVerify: true}` on a production client.\n- `ssh.InsecureIgnoreHostKey()` → MITM on every SSH connection (CWE-322).\n- Secret comparison: `subtle.ConstantTimeCompare` \u002F `hmac.Equal` (a note at most when missing).\n\n## 7. HTTP Handlers and Middleware\n\n- A route added on the bare router\u002Fapp instead of the authenticated group (security-diff-review-method).\n- `http.Redirect(w, r, r.URL.Query().Get(\"next\"), http.StatusFound)` — open redirect; high confidence only.\n- Client IP from `X-Forwarded-For` or a Fiber\u002FEcho\u002FGin proxy-header setting without a trusted-proxy list, used for an allowlist or an auth decision.\n- An error from the authorization lookup that falls through to the handler (fail open).\n- Outbound `http.Client` fetching user URLs: use a dialer `Control` check and `Proxy: nil` (ssrf-and-url-allowlists).\n\n## 8. unsafe and cgo\n\n`unsafe.Pointer` arithmetic, `unsafe.Slice`\u002F`unsafe.String` over attacker-sized buffers, and C code reached through cgo are memory-unsafe again — trace sizes and lengths from input (native-memory-safety-and-ffi has the bounds, integer and cgo pointer rules).\n\n## Common Mistakes\n\n- Reporting `exec.Command(bin, args...)` as shell injection.\n- Reporting `db.Query(\"… $1\", v)` or GORM `Where(\"x = ?\", v)` as SQL injection.\n- Reporting `gopkg.in\u002Fyaml.v3` or `encoding\u002Fgob` as unsafe deserialization — they do not instantiate arbitrary types.\n- Reporting races between goroutines on non-security state, or integer-conversion lint hits (gosec G115) with no attacker-controlled size.\n\n## Red Flags\n\n- `fmt.Sprintf` feeding `Query`, `Exec`, `Raw`, `Where`, `Order`, `Group`, `Having`.\n- `\"sh\", \"-c\"` \u002F `\"bash\", \"-c\"` in `exec.Command`.\n- `strings.HasPrefix` on a joined path.\n- `template.HTML(` around anything not a constant.\n- `InsecureSkipVerify: true`, `InsecureIgnoreHostKey()`, `math\u002Frand` near \"token\" or \"secret\".\n\n## References (names and links only)\n\n[Go security best practices](https:\u002F\u002Fgo.dev\u002Fdoc\u002Fsecurity\u002Fbest-practices) · [os.Root (Go 1.24)](https:\u002F\u002Fgo.dev\u002Fblog\u002Fosroot) · [gosec rules](https:\u002F\u002Fgithub.com\u002Fsecurego\u002Fgosec#available-rules) · [GORM security](https:\u002F\u002Fgorm.io\u002Fdocs\u002Fsecurity.html) · [govulncheck](https:\u002F\u002Fgo.dev\u002Fdoc\u002Fsecurity\u002Fvuln\u002F)\n",{"name":5,"source":24,"category":25,"tech_stack":26,"description":7},"original; informed by trailofbits\u002Fskills (CC BY-SA 4.0, ideas only, own wording); gosec rule ids, Go standard library and GORM security documentation cited, not reproduced","security","Go","main","910394a0b6db9fc8c9a8f36328ec421d3ebd8b38","catalog\u002Fagents\u002Fsecurity-agent\u002Fskills\u002Fgo-security-pitfalls",18,"https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper","https:\u002F\u002Ftasktrooper.ai","https:\u002F\u002Fgithub.com\u002Fmakifbaysal","Senior Software Developer","2026-11-15 04:50:29",{"source":8,"skillName":5,"commands":37,"prompt":47,"zipAvailable":48},[38,41,44],{"tool":39,"command":40},"npx","npx skills add makifbaysal\u002Ftasktrooper --skill go-security-pitfalls",{"tool":42,"command":43},"bunx","bunx skills add makifbaysal\u002Ftasktrooper --skill go-security-pitfalls",{"tool":45,"command":46},"pnpm","pnpm dlx skills add makifbaysal\u002Ftasktrooper --skill go-security-pitfalls","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fsecurity-agent\u002Fskills\u002Fgo-security-pitfalls\u002FSKILL.md",true,[],[51,57,64,71,78,85],{"skillNo":52,"name":53,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":54,"categories":55,"keywords":56,"publishedAt":19},"01M7CSVEPQW6J6TD6CS2T5FPNZ","visual-craft","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fui-designer\u002Fskills\u002Fvisual-craft\u002FSKILL.md",[],[],{"skillNo":58,"name":59,"nameZh":6,"description":60,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":61,"categories":62,"keywords":63,"publishedAt":19},"01M7CSVAQG91ETHQ0HBNZDG5FR","ux-copy","Use when you write any words a user reads in a mockup or a hand-off - content language and voice, buttons, labels, errors, empty states, confirmations, numbers and dates, and the longest-string check","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fui-designer\u002Fskills\u002Fux-copy\u002FSKILL.md",[],[],{"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},"01M7CSV6H0J38659NDXHJQ8396","screen-mockup-html","Use when you draw screens as the design task's HTML mockup - ONE canvas document holding every screen and every variant side by side, the sanitizer-safe recipe, phone and wide frames, the states grid, static control states, and the loopback self-check with screenshots at 375, 768 and 1440 attached to the task","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fui-designer\u002Fskills\u002Fscreen-mockup-html\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},"01M7CSV3JFRF3BM3XK52M7YEYR","performance-awareness","How the performance score moves for your role. Use when the score context shows a declining trend, or before handing off work you have not self-checked against every criterion.","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fui-designer\u002Fskills\u002Fperformance-awareness\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},"01M7CSTZDH00YRF5SCT7BRT9QD","design-variants","Use when a screen design needs variants - how many, variants as side-by-side rows on the one canvas, what makes two variants genuinely different, recommending one, how the human's choice is read, and narrowing to the chosen one in revision","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fui-designer\u002Fskills\u002Fdesign-variants\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},"01M7CSTV6P3SM3PAE28DB0RF77","design-system-authoring","Use when you derive, change or extend a design system - where tokens live per stack, the DTCG token tree, role-based names for both themes, base vs layer vs drift, the DESIGN.md section order, the inventory format, the contrast check and the lint every proposal returns","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fui-designer\u002Fskills\u002Fdesign-system-authoring\u002FSKILL.md",[],[]]