@securityreviewai/securityreview-kit 0.1.49 → 0.1.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,185 @@
1
+ ---
2
+ name: guardrails-selection
3
+ description: Analyze the developer request, infer the security categories and likely threats involved, shortlist the most relevant project guardrails, then preserve the exact returned guardrail records before implementation. Use for every security-relevant code task before code is written and preserve the shortlist for the final VibeReview sync.
4
+ ---
5
+
6
+ # Guardrails Selection
7
+
8
+ Configured SRAI project name: `<SRAI_PROJECT_NAME>`
9
+
10
+ Use this skill whenever code will be created or modified and the task has any security surface.
11
+
12
+ This skill is a hard pre-write gate. Do not write, edit, patch, or generate implementation code until this skill has produced the active guardrail shortlist and the PWNISMS skill has used that shortlist for threat modelling.
13
+
14
+ This skill exists to stop the IDE from treating the full `get_guardrails` result as an unstructured blob. The workflow is:
15
+
16
+ 1. Understand the request deeply.
17
+ 2. Infer which security categories are in play.
18
+ 3. Predict the threats that might occur for this exact task.
19
+ 4. Shortlist only the guardrails that mitigate those threats.
20
+ 5. Preserve the exact shortlisted guardrails returned by the project guardrail bundle.
21
+ 6. Carry that same shortlist forward into implementation and the final VibeReview markdown sync.
22
+
23
+ Do not skip the analysis step. Do not rely on title-matching alone. Do not dump every guardrail into the final answer.
24
+
25
+ ## Inputs You Must Analyze First
26
+
27
+ Before calling `get_guardrails`, extract the actual development intent from the prompt and surrounding code:
28
+
29
+ - What is being built, changed, fixed, or refactored?
30
+ - Which components are affected: API, UI, background jobs, auth flow, webhook, file upload, admin tooling, AI agent flow, infra code, data pipeline?
31
+ - Which trust boundaries are crossed?
32
+ - Which sensitive assets are touched: tokens, credentials, sessions, PII, tenancy boundaries, audit logs, secrets, internal APIs, signed URLs, payment state, workflow approvals?
33
+ - Which technologies and patterns are involved in the existing code?
34
+ - What abuse cases are plausible if this change is implemented poorly?
35
+
36
+ You are not only selecting guardrails for the obvious functionality. You are selecting guardrails for the threats that might materialize around that functionality.
37
+
38
+ ## Category Inference Workflow
39
+
40
+ Derive a category set for the task before shortlisting guardrails. Common categories include:
41
+
42
+ - `authentication`
43
+ - `authorization`
44
+ - `session_management`
45
+ - `input_validation`
46
+ - `output_encoding`
47
+ - `secrets`
48
+ - `cryptography`
49
+ - `logging`
50
+ - `monitoring`
51
+ - `file_uploads`
52
+ - `deserialization`
53
+ - `data_access`
54
+ - `rate_limiting`
55
+ - `network`
56
+ - `client_side`
57
+ - `business_logic`
58
+ - `tenant_isolation`
59
+ - `admin_workflows`
60
+
61
+ Use both the user request and the codebase patterns to infer the category set. A task can involve multiple categories even if the prompt mentions only one feature.
62
+
63
+ Examples:
64
+
65
+ - “Add magic-link login” likely involves `authentication`, `session_management`, `cryptography`, `logging`, `rate_limiting`, and `client_side`.
66
+ - “Add org admin API to update member roles” likely involves `authorization`, `tenant_isolation`, `logging`, `business_logic`, and `data_access`.
67
+ - “Add CSV import” likely involves `input_validation`, `file_uploads`, `data_access`, `deserialization`, `logging`, and denial-of-service protections.
68
+ - “Add client-side token refresh” likely involves `authentication`, `session_management`, `client_side`, `logging`, and `cryptography`.
69
+
70
+ ## Threat Mapping Requirement
71
+
72
+ After identifying categories, infer the threat families that might occur. Use the reference file at `{{GUARDRAILS_SELECTION_SKILL_DIR}}/references/category-threat-map.md` every time you need to reason about category-to-threat mapping.
73
+
74
+ Your goal is not to enumerate every possible weakness. Your goal is to pick the threats that should influence guardrail selection for this task.
75
+
76
+ At minimum, consider whether the task can create:
77
+
78
+ - authentication bypass
79
+ - authorization bypass
80
+ - privilege escalation
81
+ - information disclosure
82
+ - repudiation gaps
83
+ - denial of service
84
+ - unsafe client-side trust
85
+ - insecure logging or audit gaps
86
+ - injection-triggered security failures
87
+ - serialization-triggered security failures
88
+ - business-logic-triggered bypasses
89
+
90
+ The shortlist should be threat-led, not catalog-led.
91
+
92
+ ## Guardrail Selection Procedure
93
+
94
+ ### Step 1: Resolve the project and load the catalog
95
+
96
+ 1. Call `find_project_by_name` with `name="<SRAI_PROJECT_NAME>"` to obtain `project_id`.
97
+ 2. Call `get_guardrails` with `project_id`.
98
+
99
+ Treat `get_guardrails` as the broad project catalog. Do not treat the whole catalog as the final set of instructions. The returned entries are already the authoritative guardrail records for this project; shortlist from those exact records and preserve their ids, titles, rule types, categories, and instructions.
100
+
101
+ Assume each returned guardrail includes the fields needed for selection, including a stable identifier for follow-up retrieval, plus:
102
+
103
+ - `title`
104
+ - `rule_type`
105
+ - `category`
106
+ - `instruction`
107
+
108
+ If an identifier is absent, fall back to the best available stable reference exposed by the tool, but prefer the real guardrail id whenever available.
109
+
110
+ ### Step 2: Build a shortlist
111
+
112
+ Shortlist guardrails using all of the following:
113
+
114
+ - direct category match with the task
115
+ - mitigation value against the likely threats you inferred
116
+ - relevance to the technologies and code paths being touched
117
+ - support for adjacent controls that prevent bypass chains
118
+ - duplication removal
119
+
120
+ Do not select a guardrail only because it sounds generally useful. Select it because it materially constrains the risky part of the current task.
121
+
122
+ Examples:
123
+
124
+ - If the task touches login, token issuance, password reset, session refresh, or identity proofing, prioritize authentication, session, crypto, logging, and brute-force defense guardrails.
125
+ - If the task changes role checks, tenant scoping, admin APIs, resource ownership, or query filters, prioritize authorization, tenant isolation, data access, business-logic, and audit guardrails.
126
+ - If the task introduces parsing, uploads, template expansion, or object hydration, prioritize input validation, file handling, deserialization, and denial-of-service guardrails.
127
+ - If the task moves security decisions into the browser or mobile client, prioritize client-side trust, token storage, server-side revalidation, and privilege-boundary guardrails.
128
+
129
+ ### Step 3: Preserve exact shortlisted guardrails
130
+
131
+ For every shortlisted existing guardrail, preserve the exact guardrail record returned by `get_guardrails`.
132
+
133
+ Implementation must be driven by that exact shortlist, not by vague memory from the broad catalog listing. Do not re-query guardrails after implementation starts unless the shortlist is missing or the task scope materially changes.
134
+
135
+ ### Step 4: Track the active shortlist in context
136
+
137
+ Maintain an explicit in-context list of the shortlisted existing guardrails that will govern the task. For each shortlisted existing guardrail, keep:
138
+
139
+ - `id`
140
+ - `title`
141
+ - `rule_type`
142
+ - `category`
143
+ - `instruction`
144
+ - `why_selected`
145
+
146
+ Also track any new guardrails created during the task as `ide_generated`.
147
+
148
+ This shortlist is the source of truth for the rest of the session.
149
+
150
+ ## Implementation Rules
151
+
152
+ Once the exact shortlist is preserved:
153
+
154
+ - Every applicable `must` guardrail is mandatory.
155
+ - Every applicable `must_not` guardrail is a hard prohibition.
156
+ - If two shortlisted guardrails appear to conflict, explain the conflict and resolve it before coding.
157
+ - If the task reveals a real gap not covered by the shortlisted existing guardrails, create an `ide_generated` guardrail and apply it immediately.
158
+
159
+ When deciding whether a guardrail applies, prefer security-preserving inclusion over risky omission. If it plausibly mitigates a realistic path to abuse for the current task, keep it in scope.
160
+
161
+ ## VibeReview Sync Contract
162
+
163
+ The final sync step must reuse the shortlist from this skill. It must not call `get_guardrails` again unless the task scope materially changed.
164
+
165
+ Before `sync_ai_ide_markdown` is called, ensure the main agent context clearly contains:
166
+
167
+ - the exact existing guardrails shortlisted earlier
168
+ - which of them were applied
169
+ - whether each one was satisfied
170
+ - any notes about partial compliance, conflicts, or rationale
171
+ - every `ide_generated` guardrail created during the task
172
+
173
+ If a guardrail was shortlisted but not fully satisfied, still include it in the handoff with `satisfied: false` and a note. Do not silently drop it.
174
+
175
+ ## Selection Quality Bar
176
+
177
+ A good selection does all of the following:
178
+
179
+ - covers the feature’s real threat surface, not just its visible functionality
180
+ - captures adjacent controls that stop bypass chains
181
+ - avoids irrelevant noise
182
+ - produces a small, defensible set of guardrails that can actually guide implementation
183
+ - leaves the final VibeReview markdown with an exact list of what the IDE selected and enforced
184
+
185
+ If your shortlist feels generic, it is probably incomplete or over-broad. Re-check the prompt, the code patterns, and the threat map.
@@ -0,0 +1,259 @@
1
+ ---
2
+ name: PWNISMS Threat Modelling
3
+ description: Security-first threat modelling workflow for code and architecture tasks. Walks all 7 PWNISMS categories, enforces vibe guardrails (secure by code), and synchronizes findings via a direct VibeReview markdown sync. Use after guardrail selection and before implementation.
4
+ ---
5
+
6
+ # PWNISMS — Security-First Threat Modelling
7
+
8
+ For EVERY security-relevant task (feature, bug fix, refactor, infra change, architecture design), run a threat model with PWNISMS.
9
+
10
+ - This is a pre-implementation gate. Do not write, edit, patch, or generate implementation code until guardrail selection has completed and this PWNISMS pass has been completed.
11
+ - Walk through all 7 categories explicitly.
12
+ - If a category is not applicable, state it briefly and move on.
13
+ - Anchor analysis to linked files, diffs, PRs, API specs, and diagrams whenever available.
14
+ - Focus on realistic threats for the current context, not exhaustive attack catalogs.
15
+
16
+ ---
17
+
18
+ ## Phase 0 — Guardrail Context
19
+
20
+ Before deep analysis, ensure the project-specific guardrail shortlist exists:
21
+
22
+ 1. Use `{{GUARDRAILS_SELECTION_SKILL_DIR}}/SKILL.md`.
23
+ 2. Resolve the project with `find_project_by_name` using `name="<SRAI_PROJECT_NAME>"`.
24
+ 3. Call `get_guardrails`, shortlist intentionally for this task, then preserve the exact returned guardrail records in context.
25
+ 4. Keep the shortlisted existing guardrails in context for implementation and the final VibeReview markdown sync.
26
+
27
+ Do not perform project-profile exploration as part of PWNISMS. The old profile tools are not part of this workflow. Ground the threat model in the user request, repository code, diffs, architecture docs the user provides, and the shortlisted guardrails.
28
+
29
+ If SRAI is not available, proceed with the user-provided context and repository evidence, then clearly note that project guardrails could not be fetched.
30
+
31
+ ---
32
+
33
+ ## Phase 1 — Inputs to Gather
34
+
35
+ Collect these quickly before deep analysis:
36
+
37
+ - **Scope**: What is changing (feature, component, service, migration, PR)?
38
+ - **Assets**: What must be protected (PII, credentials, tokens, configs, accounts, workflows)?
39
+ - **Entry points**: How data enters/leaves (HTTP, queues, schedulers, CLI, webhooks, integrations)?
40
+ - **Trust boundaries**: Where data crosses users/services/networks/privilege levels?
41
+ - **Existing guardrails**: What shortlisted project-specific dos and don'ts apply (from Phase 0)?
42
+
43
+ If the user provided specific code, diffs, or architecture artifacts, prioritize those as primary evidence.
44
+
45
+ ---
46
+
47
+ ## Phase 2 — Lightweight Workflow (PWNISMS)
48
+
49
+ 1. **Clarify scope and assumptions**
50
+ - Define the exact unit of analysis.
51
+ - State assumptions explicitly (auth model, deployment boundary, tenant model, etc.).
52
+
53
+ 2. **Map assets and flows**
54
+ - List high-value assets and critical data paths.
55
+ - List entry points and exits across trust boundaries.
56
+ - Note which assets are covered by existing guardrails and which are not.
57
+
58
+ 3. **Walk all 7 PWNISMS categories**
59
+ - Identify plausible threats for each category.
60
+ - Keep findings concrete and contextual.
61
+ - For each threat, check if an existing guardrail already addresses it.
62
+
63
+ 4. **Prioritize**
64
+ - Select the top 3-7 risks by impact and likelihood.
65
+ - Factor in existing mitigations from the codebase, user-provided context, and guardrails.
66
+
67
+ 5. **Mitigate**
68
+ - Propose concrete, implementable controls for each prioritized risk.
69
+ - Map mitigations to specific guardrails where applicable.
70
+ - If a mitigation represents a recurring pattern, propose it as a new guardrail candidate.
71
+
72
+ 6. **Summarize residual risk**
73
+ - Call out remaining risk, trade-offs, and follow-up actions.
74
+ - Call out unknowns instead of silently guessing.
75
+ - Note guardrail gaps — security patterns not yet captured by any guardrail.
76
+
77
+ ---
78
+
79
+ ## The 7 Categories (What to Check)
80
+
81
+ ### P — Product
82
+
83
+ Application and business-logic threats:
84
+
85
+ - Input validation, injection, insecure deserialization.
86
+ - Authorization gaps, privilege escalation, IDOR/BOLA.
87
+ - Business logic abuse, replay/race conditions, unsafe redirects.
88
+ - Error handling that leaks internals.
89
+ - **Guardrail check:** Are there `must` / `must_not` rules for input validation, authorization patterns, error handling?
90
+
91
+ ### W — Workload
92
+
93
+ Compute and infrastructure threats:
94
+
95
+ - Insecure container/runtime posture, over-privileged workload identity.
96
+ - Weak host/orchestrator controls and segmentation.
97
+ - Insecure data storage/backups and DB configuration.
98
+ - Queue/broker abuse and poison-message handling gaps.
99
+ - **Guardrail check:** Are there rules for container security, data-at-rest encryption, workload identity?
100
+
101
+ ### N — Network
102
+
103
+ Network and transport threats:
104
+
105
+ - Missing/weak TLS, insecure service-to-service communication.
106
+ - Exposed ports/endpoints and permissive ingress/egress.
107
+ - Weak segmentation or lateral movement paths.
108
+ - API-layer abuse controls missing (rate limits, request limits, CORS hardening).
109
+ - **Guardrail check:** Are there rules for TLS enforcement, CORS policy, rate limiting?
110
+
111
+ ### I — IAM (Identity & Access Management)
112
+
113
+ Identity and authorization threats:
114
+
115
+ - Broken authentication controls and token validation.
116
+ - Missing least-privilege RBAC/ABAC.
117
+ - Service-to-service auth gaps.
118
+ - Escalation paths across users, roles, or services.
119
+ - **Guardrail check:** Are there rules for auth mechanisms, session management, privilege boundaries?
120
+
121
+ ### S — Secrets
122
+
123
+ Credential and key management threats:
124
+
125
+ - Secrets in code, images, logs, CI output, or defaults.
126
+ - Weak rotation, revocation, or token lifetime policies.
127
+ - Over-shared secrets across components.
128
+ - Missing secret manager/KMS controls.
129
+ - **Guardrail check:** Are there `must_not` rules against hardcoded secrets, `must` rules for secret manager usage?
130
+
131
+ ### M — Monitoring (Logging & Observability)
132
+
133
+ Detection and auditability threats:
134
+
135
+ - Missing logs for auth, authorization, admin/data access events.
136
+ - Sensitive data leakage in logs.
137
+ - Missing alerts for abuse indicators.
138
+ - Incomplete audit trails or weak log integrity.
139
+ - **Guardrail check:** Are there rules for what must be logged and what must not appear in logs?
140
+
141
+ ### S — Supply Chain
142
+
143
+ Dependency and delivery threats:
144
+
145
+ - Unpinned/unverified dependencies and vulnerable packages.
146
+ - Third-party integration trust and scope overreach.
147
+ - CI/CD pipeline leakage or unreviewed build scripts.
148
+ - Unsigned/unprovenanced artifacts, missing SBOM.
149
+ - Treat AI-generated code as untrusted until validated.
150
+ - **Guardrail check:** Are there rules for dependency pinning, SBOM generation, artifact signing?
151
+
152
+ ---
153
+
154
+ ## Phase 3 — Guardrail Enforcement (Secure by Code)
155
+
156
+ After completing the PWNISMS analysis and before writing code:
157
+
158
+ 1. **Review the exact shortlisted guardrails** produced by `{{GUARDRAILS_SELECTION_SKILL_DIR}}/SKILL.md`.
159
+ 2. **Classify applicability** — For each shortlisted guardrail, determine if it applies to the current task.
160
+ 3. **Apply during code generation:**
161
+ - `must` rules → mandatory implementation requirements. Every applicable `must` guardrail must be satisfied.
162
+ - `must_not` rules → hard prohibitions. Code must never violate an applicable `must_not` guardrail.
163
+ 4. **Flag conflicts** — If a guardrail conflicts with the user's explicit instruction, flag it and ask for confirmation.
164
+ 5. **Create new guardrails on the fly** — When PWNISMS analysis or code review reveals a recurring security pattern not captured by existing guardrails, create and apply it as a new guardrail (marked `source: "ide_generated"` in the VibeReview markdown). Include `title`, `rule_type` (must/must_not), `category`, `instruction`, and rationale in the notes.
165
+
166
+ ---
167
+
168
+ ## Phase 4 — Security-First Code Generation Rules
169
+
170
+ When implementing code, enforce these baseline controls alongside project guardrails:
171
+
172
+ 1. Validate and constrain all untrusted input.
173
+ 2. Parameterize all queries and command-like invocations.
174
+ 3. Enforce least privilege for users, services, and workloads.
175
+ 4. Never hardcode secrets; use managed secret stores.
176
+ 5. Encrypt sensitive data in transit and at rest.
177
+ 6. Log security-relevant actions without leaking secrets/PII.
178
+ 7. Pin and verify dependencies and build artifacts.
179
+ 8. Return safe user errors; keep sensitive diagnostics internal.
180
+ 9. Add abuse protections (rate limits, lockouts, throttling) on exposed interfaces.
181
+
182
+ ---
183
+
184
+ ## Tailor for Architecture / Design Tasks
185
+
186
+ When discussing designs before code exists:
187
+
188
+ - Sketch a mental data flow: actors, data sent/received, storage, processing points.
189
+ - Mark trust boundaries explicitly (client-backend, backend-DB, service-service, cloud-third party).
190
+ - Identify where strong authentication/authorization is mandatory.
191
+ - Identify where encryption in transit and at rest is mandatory.
192
+ - Recommend concrete security patterns:
193
+ - Parameterized queries / ORM for DB access.
194
+ - Centralized authn/authz and role checks.
195
+ - Secrets manager / KMS for credentials and keys.
196
+ - mTLS or signed requests for service-to-service calls.
197
+ - Review existing guardrails for design-level constraints.
198
+
199
+ ---
200
+
201
+ ## Phase 5 — VibeReview Sync (Post Threat Modelling)
202
+
203
+ **MANDATORY:** After every threat modeling step that produces or modifies threat content, the main agent must update the `.vibreview/scans/*.md` artifact and call `sync_ai_ide_markdown` directly with raw markdown content.
204
+
205
+ ### What triggers the VibeReview sync
206
+
207
+ - New threat model generated (any form: scenarios, data flows, attack trees, PWNISMS analysis)
208
+ - Existing threat model updated or extended (new threats, refined mitigations, additional components)
209
+ - Guardrails applied during a code-generation task (existing or IDE-generated)
210
+
211
+ Do not call sync before implementation is complete unless the user explicitly asked only for threat modelling/design output. For coding tasks, the order is guardrail selection, PWNISMS, implementation, markdown sync.
212
+
213
+ ### What the VibeReview markdown must contain
214
+
215
+ The main agent writes a structured `.md` artifact under `.vibreview/scans/` and uploads the raw markdown string through `sync_ai_ide_markdown`. That markdown should contain:
216
+
217
+ - **Threat model findings**: threats mitigated, PWNISMS categories, severities, mitigations applied
218
+ - **Best practices achieved**: structured practice entries with `practice_name`, `description`, and `category`
219
+ - **Secure code snippets**: security-relevant code with explanations
220
+ - **Guardrails applied**: all guardrails enforced during this session — both existing ones shortlisted earlier via `get_guardrails` (`source: "existing"`) and new ones the IDE agent created on the fly (`source: "ide_generated"`), each with satisfaction status
221
+ - **Workflow metadata**: `chat_session_id`, `event_name` or `title`, required `summary`, and optional `workflow_name` / `workflow_description`
222
+
223
+ ### How to sync
224
+
225
+ 1. Read and follow `{{VIBEREVIEW_SYNC_SKILL_DIR}}/SKILL.md`.
226
+ 2. Write or update a file under `.vibreview/scans/`, ideally `.vibreview/scans/<chat_session_id>-<slugified-title-or-event-name>.md`.
227
+ 3. Put `chat_session_id`, `summary`, and either `title` or `event_name` in frontmatter.
228
+ 4. Include the required sections:
229
+ - `Best Practices Achieved`
230
+ - `Threats Mitigated`
231
+ - `Secure Code Snippets`
232
+ - `Guardrails Applied`
233
+ - `OWASP Top 10 2025 Mappings`
234
+ 5. Validate that:
235
+ - every threat entry includes `threat_name`, `pwnisms_category`, `severity`, and `mitigation_applied`
236
+ - every best-practice entry includes `practice_name`, `description`, and `category`
237
+ - every guardrail includes `title`, `rule_type`, `source`, and `satisfied`
238
+ - OWASP mappings use exact IDs and names
239
+ - snippets are grounded in actual code, not invented text
240
+ - no sibling `.md` files in `.vibreview/scans/` were read just to infer format or content
241
+ 6. Call `sync_ai_ide_markdown` directly with the finished raw markdown content. Do not pass JSON, extracted event objects, or summaries as the markdown.
242
+ 7. If sync fails, leave the artifact in `.vibreview/scans/` and report the failure clearly.
243
+
244
+ ---
245
+
246
+ ## Post-Generation Checklist
247
+
248
+ Before finalizing output, confirm:
249
+
250
+ - [ ] Scope, assumptions, and trust boundaries were explicit.
251
+ - [ ] All 7 PWNISMS categories were checked (or marked N/A explicitly).
252
+ - [ ] Top risks were prioritized by impact and likelihood.
253
+ - [ ] Mitigations are concrete and actionable.
254
+ - [ ] Residual risk and follow-up actions are stated.
255
+ - [ ] Vibe guardrails were fetched and enforced (all applicable `must`/`must_not` rules satisfied).
256
+ - [ ] Guardrail compliance summary is included in the response (existing + IDE-generated).
257
+ - [ ] The VibeReview markdown was written under `.vibreview/scans/` and `sync_ai_ide_markdown` was called successfully with raw markdown content.
258
+
259
+ If ANY box cannot be checked, you MUST flag the gap to the user with a specific remediation recommendation before finalizing the code.