Security: Secure Coding
Purpose
Eliminates vulnerabilities at the source code level. It reviews and fixes application code for injection, validation, encoding, and privilege flaws within the named scope; it does NOT configure networks, WAFs, secrets stores, or dependency scanners.
When to Use / When NOT to Use
- Use: Writing new features, security reviews, handling PII.
- NOT: Network firewall rules or WAF configuration.
- NOT: Secret storage and rotation (use
security-secrets-management).
- NOT: CVE and SBOM scanning (use
security-dependency-scanning).
- NOT: Go-specific audits with gosec/govulncheck (use
golang-audit-security).
Prerequisites & Assumptions
Scope & Context Resolution
- Supported scopes: function/method, file, directory/module, endpoint/handler, project/repository. Default when none is given: the code snippet or files presented in the prompt.
- Rule 1 - Explicit context in the prompt: The user's stated requirements, constraints, versions, targets, and scope are authoritative. Apply the skill strictly within them. MUST NOT add assumptions or expand beyond them. If a user instruction conflicts with a skill rule, follow the user and state the deviation in one line, EXCEPT security/data-loss rules, which stay mandatory (flag the conflict instead).
- Rule 2 - No extra context: Use this skill's Purpose, workflow, and rules as the sole context at the default scope. MUST NOT import unrelated requirements or assumptions.
- Rule 3 - Explicit scope: Operate ONLY inside the named scope. Out-of-scope files may be READ as evidence but MUST NOT be modified; report out-of-scope observations as notes, never as changes. Widening scope requires explicit user approval.
- Mutation boundary: Edits are limited to security fixes in the named scope. Vulnerabilities found outside it are reported as notes only.
Step-by-Step Workflow
- Resolve scope and context: Apply the section above; state the resolved scope and mutation boundary in one line at the start of the output.
- Validate all inputs at trust boundaries within the scope.
- Use parameterized queries (never string concat).
- Encode outputs based on context (HTML, JS, SQL).
- Enforce least privilege for DB/App users.
Enterprise Rules & Standards (MUST / SHOULD / MUST NOT)
- MUST: Use parameterized queries (ORM or prepared statements).
- MUST: Validate inputs strictly (allowlists over denylists).
- MUST: Stay within the resolved scope; MUST NOT modify or expand beyond it without explicit user approval.
- SHOULD: Use vetted crypto libraries (never roll own crypto).
- MUST NOT: Trust client-side validation alone.
- MUST NOT: Silently skip a vulnerability found in scope, or "fix" unrelated code to do so; flag it instead.
Examples (good vs. bad, with realistic code or output)
- Bad:
db.Query("SELECT * FROM users WHERE id = " + id)
- Good:
db.Query("SELECT * FROM users WHERE id = ?", id)
Scope handling
- Prompt: "Fix the injection risk in
GetUser only."
- Good: Parameterizes the query in
GetUser; notes that ListUsers concatenates input too.
- Bad: Rewrites the whole data layer and swaps the ORM.
Checklist (verifiable, copy-pasteable)
Common Pitfalls
- Security by obscurity.
- Custom cryptography implementations.
- Scope creep: rewriting the data layer when asked to fix one injection flaw.
References (official docs, standards)
1---2name: security-secure-coding3description: 'Preventing OWASP Top 10, input validation, secure-by-default design. Trigger: "prevent SQL injection", "secure coding checklist", "XSS prevention".'4metadata:5 source: https://skillmd.com/skills/pnguyen215/security-secure-coding6 category: security7 tags: "security, owasp, input-validation, secure-by-default, injection"8---910# Security: Secure Coding1112## Purpose1314Eliminates vulnerabilities at the source code level. It reviews and fixes application code for injection, validation, encoding, and privilege flaws within the named scope; it does NOT configure networks, WAFs, secrets stores, or dependency scanners.1516## When to Use / When NOT to Use1718- **Use**: Writing new features, security reviews, handling PII.19- **NOT**: Network firewall rules or WAF configuration.20- **NOT**: Secret storage and rotation (use `security-secrets-management`).21- **NOT**: CVE and SBOM scanning (use `security-dependency-scanning`).22- **NOT**: Go-specific audits with gosec/govulncheck (use `golang-audit-security`).2324## Prerequisites & Assumptions2526- OWASP Top 10 knowledge.2728### Scope & Context Resolution2930- **Supported scopes**: function/method, file, directory/module, endpoint/handler, project/repository. Default when none is given: the code snippet or files presented in the prompt.31- **Rule 1 - Explicit context in the prompt**: The user's stated requirements, constraints, versions, targets, and scope are authoritative. Apply the skill strictly within them. MUST NOT add assumptions or expand beyond them. If a user instruction conflicts with a skill rule, follow the user and state the deviation in one line, EXCEPT security/data-loss rules, which stay mandatory (flag the conflict instead).32- **Rule 2 - No extra context**: Use this skill's Purpose, workflow, and rules as the sole context at the default scope. MUST NOT import unrelated requirements or assumptions.33- **Rule 3 - Explicit scope**: Operate ONLY inside the named scope. Out-of-scope files may be READ as evidence but MUST NOT be modified; report out-of-scope observations as notes, never as changes. Widening scope requires explicit user approval.34- **Mutation boundary**: Edits are limited to security fixes in the named scope. Vulnerabilities found outside it are reported as notes only.3536## Step-by-Step Workflow37381. **Resolve scope and context**: Apply the section above; state the resolved scope and mutation boundary in one line at the start of the output.392. Validate all inputs at trust boundaries within the scope.403. Use parameterized queries (never string concat).414. Encode outputs based on context (HTML, JS, SQL).425. Enforce least privilege for DB/App users.4344## Enterprise Rules & Standards (MUST / SHOULD / MUST NOT)4546- **MUST**: Use parameterized queries (ORM or prepared statements).47- **MUST**: Validate inputs strictly (allowlists over denylists).48- **MUST**: Stay within the resolved scope; MUST NOT modify or expand beyond it without explicit user approval.49- **SHOULD**: Use vetted crypto libraries (never roll own crypto).50- **MUST NOT**: Trust client-side validation alone.51- **MUST NOT**: Silently skip a vulnerability found in scope, or "fix" unrelated code to do so; flag it instead.5253## Examples (good vs. bad, with realistic code or output)5455- **Bad**: `db.Query("SELECT * FROM users WHERE id = " + id)`56- **Good**: `db.Query("SELECT * FROM users WHERE id = ?", id)`5758**Scope handling**5960- **Prompt**: "Fix the injection risk in `GetUser` only."61- **Good**: Parameterizes the query in `GetUser`; notes that `ListUsers` concatenates input too.62- **Bad**: Rewrites the whole data layer and swaps the ORM.6364## Checklist (verifiable, copy-pasteable)6566- [ ] Scope and context resolved and stated.67- [ ] No changes outside the resolved scope.68- [ ] Inputs validated.69- [ ] Parameterized queries used.70- [ ] Output encoded.7172## Common Pitfalls7374- Security by obscurity.75- Custom cryptography implementations.76- Scope creep: rewriting the data layer when asked to fix one injection flaw.7778## References (official docs, standards)7980- [OWASP Secure Coding Practices](https://owasp.org/www-project-secure-coding-practices-quick-reference-guide/)