|
| 1 | +# Security Review Skill (On-Demand) |
| 2 | + |
| 3 | +## Purpose |
| 4 | + |
| 5 | +This document defines on-demand security review guidance for code and configuration changes. |
| 6 | +It complements the always-on secure-by-default rules defined in `.github/copilot-instructions.md`. |
| 7 | + |
| 8 | +This skill applies only at development and authoring time. |
| 9 | +Runtime, host, cluster, or organizational security controls are explicitly out of scope. |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +## Security Review Trigger Points |
| 14 | + |
| 15 | +Load this security review skill when changes involve: |
| 16 | + |
| 17 | +- Authentication, session, or token logic |
| 18 | +- Authorization or resource ownership checks |
| 19 | +- Input parsing, validation, normalization, or canonicalization |
| 20 | +- File handling, deserialization, template rendering, or process execution |
| 21 | +- Logging, telemetry, secrets handling, or sensitive data paths |
| 22 | +- Dependency upgrades, lockfile changes, or CVE-related updates |
| 23 | +- Dockerfile or container base image changes |
| 24 | +- Docker Compose, Helm charts, or Kubernetes-related configuration |
| 25 | +- CI/CD workflow changes affecting build, test, release, or scanning |
| 26 | +- Privilege elevation, root execution, host mounts, or new Linux capabilities |
| 27 | + |
| 28 | +--- |
| 29 | + |
| 30 | +## AI-Generated Code Guardrails |
| 31 | + |
| 32 | +When reviewing AI-generated changes: |
| 33 | + |
| 34 | +- Treat AI output as untrusted draft code until reviewed and tested |
| 35 | +- Verify package names, APIs, images, and tools exist and originate from trusted sources |
| 36 | +- Reject suggestions that bypass or disable security controls for convenience |
| 37 | +- Require pinned versions and lockfiles for generated dependencies; prefer integrity-verified installs when supported |
| 38 | +- Never accept generated code or configs that inject secrets via source files, Dockerfile `ARG`/`ENV`, or committed templates |
| 39 | +- Reject generated install scripts that use unchecked remote execution patterns (e.g., `curl | sh`) without checksum or signature verification |
| 40 | +- Reject generated build commands that disable TLS, certificate verification, or security checks to make builds pass |
| 41 | +- Apply RCI pattern: ask the AI to review its own output for security issues, then improve; repeat 1-2 iterations |
| 42 | + |
| 43 | +--- |
| 44 | + |
| 45 | +## Secure Code Review (OSS Context) |
| 46 | + |
| 47 | +Apply when reviewing application logic, services, APIs, or libraries. |
| 48 | + |
| 49 | +### Input handling |
| 50 | + |
| 51 | +- Validate input at trust boundaries (format, type, range, length) |
| 52 | +- Avoid unsafe deserialization |
| 53 | +- Do not propagate unvalidated input across trust boundaries |
| 54 | +- Avoid command, query, or expression construction via string concatenation |
| 55 | +- Use parameterized queries for all database access |
| 56 | + |
| 57 | +### Authorization |
| 58 | + |
| 59 | +- **Keep authorization checks server-side and close to protected actions or resources** |
| 60 | +- Do not rely on client-side enforcement for access control |
| 61 | + |
| 62 | +### Error handling |
| 63 | + |
| 64 | +- Errors must not expose sensitive internal details |
| 65 | +- Avoid ignored return values or silent failures |
| 66 | + |
| 67 | +### Memory & resource safety (where applicable) |
| 68 | + |
| 69 | +- Avoid unchecked allocations and unbounded resource use |
| 70 | +- Ensure files, sockets, and handles are closed deterministically |
| 71 | + |
| 72 | +### Logging & telemetry |
| 73 | + |
| 74 | +- Do not log credentials, tokens, secrets, or PII |
| 75 | +- Logs should be actionable without exposing sensitive data |
| 76 | + |
| 77 | +### Dynamic execution |
| 78 | + |
| 79 | +- **Avoid unsafe dynamic execution patterns (`eval`, `exec`, reflection, or untrusted code execution).** |
| 80 | + |
| 81 | +### Dependency usage |
| 82 | + |
| 83 | +- Avoid shelling out when native APIs or libraries exist |
| 84 | +- Flag outdated, unmaintained, or suspicious dependencies |
| 85 | +- Prefer latest stable versions; specify exact or range-locked versions |
| 86 | + |
| 87 | +### OSS-specific review checks |
| 88 | + |
| 89 | +- Is externally observable **security-relevant behavior** documented? |
| 90 | +- Are assumptions and limitations stated explicitly for users? |
| 91 | + |
| 92 | +If uncertainty exists, flag it clearly rather than guessing or assuming safety. |
| 93 | + |
| 94 | +--- |
| 95 | + |
| 96 | +## Container Artifact Review (Development-Time) |
| 97 | + |
| 98 | +Apply when generating or reviewing: |
| 99 | + |
| 100 | +- Dockerfiles / Containerfiles |
| 101 | +- docker-compose.yml |
| 102 | +- Helm charts (templates and values) |
| 103 | + |
| 104 | +### Dockerfile |
| 105 | + |
| 106 | +- Avoid `latest` or floating tags; pin versions or digests |
| 107 | +- Prefer minimal base images |
| 108 | +- Ensure containers do not run as root |
| 109 | +- Avoid setuid or setgid binaries |
| 110 | +- Use multi-stage builds and remove build tools, package caches, and temp files from final image |
| 111 | +- Prefer `COPY` over `ADD` |
| 112 | +- Never embed secrets in `ARG`, `ENV`, or filesystem layers |
| 113 | + |
| 114 | +### Docker Compose |
| 115 | + |
| 116 | +- Avoid `privileged: true` and host networking unless explicitly justified |
| 117 | +- Do not mount the Docker socket |
| 118 | +- Restrict host filesystem mounts |
| 119 | +- Limit exposed ports and networks; prefer internal networks |
| 120 | + |
| 121 | +Concerns that depend on deployment or runtime policy should be flagged as: |
| 122 | +**"Deployment-time responsibility."** |
| 123 | + |
| 124 | +--- |
| 125 | + |
| 126 | +## Helm / Kubernetes Review (Development-Time) |
| 127 | + |
| 128 | +- Default to `runAsNonRoot: true` |
| 129 | +- Set `allowPrivilegeEscalation: false` |
| 130 | +- Prefer read-only root filesystem where feasible |
| 131 | +- Drop unnecessary Linux capabilities |
| 132 | +- Do not template secrets directly into charts |
| 133 | +- Document required runtime security assumptions |
| 134 | + |
| 135 | +Do not enforce cluster-wide, node-level, or runtime security controls. |
| 136 | + |
| 137 | +--- |
| 138 | + |
| 139 | +## Review Output Expectations |
| 140 | + |
| 141 | +- Identify which section applies (Code / Container / Helm) |
| 142 | +- Classify findings as: |
| 143 | + - Fix in artifact |
| 144 | + - Deployment/runtime responsibility |
| 145 | +- Explicitly state assumptions or uncertainty |
| 146 | +- Use severity levels: Critical / High / Medium / Low with confidence: High / Medium / Low |
| 147 | +- Include specific file/function references and recommended fixes |
| 148 | + |
| 149 | +Security review is advisory; final decisions belong to maintainers. |
0 commit comments