mdan-cli 2.6.0 → 2.7.0

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,386 @@
1
+ """Security Agent (Said) - BUILD+VERIFY Phases
2
+
3
+ Responsible for security review, vulnerability assessment, and secure coding practices.
4
+ """
5
+
6
+ from crewai import Agent, Task
7
+ from typing import List, Optional
8
+ from ..tools.sql_tool import SQLTool
9
+ from ..tools.serper_tool import SerperTool
10
+ from ..tools.file_tool import FileTool
11
+
12
+
13
+ class SecurityAgent:
14
+ """Security Agent for BUILD+VERIFY phases - Security review and vulnerability assessment."""
15
+
16
+ def __init__(
17
+ self,
18
+ sql_tool: Optional[SQLTool] = None,
19
+ serper_tool: Optional[SerperTool] = None,
20
+ file_tool: Optional[FileTool] = None,
21
+ llm=None,
22
+ ):
23
+ """Initialize Security Agent.
24
+
25
+ Args:
26
+ sql_tool: SQL connector tool
27
+ serper_tool: Web search tool
28
+ file_tool: File operations tool
29
+ llm: Language model instance
30
+ """
31
+ self.sql_tool = sql_tool
32
+ self.serper_tool = serper_tool
33
+ self.file_tool = file_tool
34
+ self.llm = llm
35
+
36
+ tools = []
37
+ if sql_tool:
38
+ tools.append(sql_tool)
39
+ if serper_tool:
40
+ tools.append(serper_tool)
41
+ if file_tool:
42
+ tools.append(file_tool)
43
+
44
+ self.agent = Agent(
45
+ role="Security Engineer & Vulnerability Specialist",
46
+ goal="Ensure software security through comprehensive security reviews and vulnerability assessments",
47
+ backstory="""You are Said, an expert Security Engineer with deep knowledge of cybersecurity,
48
+ vulnerability assessment, and secure coding practices. You excel at identifying security vulnerabilities,
49
+ conducting security reviews, and implementing security best practices. You are thorough, security-conscious,
50
+ and focused on preventing security breaches before they happen.""",
51
+ verbose=True,
52
+ allow_delegation=False,
53
+ tools=tools,
54
+ llm=llm,
55
+ )
56
+
57
+ def create_security_review_task(self, codebase_context: str) -> Task:
58
+ """Create task for conducting security code review.
59
+
60
+ Args:
61
+ codebase_context: Codebase structure and implementation details
62
+
63
+ Returns:
64
+ Task for security code review
65
+ """
66
+ return Task(
67
+ description=f"""Conduct a comprehensive security code review.
68
+
69
+ Codebase Context:
70
+ {codebase_context}
71
+
72
+ Your task:
73
+ 1. Review codebase for security vulnerabilities
74
+ 2. Check for OWASP Top 10 vulnerabilities:
75
+ - Injection (SQL, NoSQL, OS command, LDAP)
76
+ - Broken Authentication
77
+ - Sensitive Data Exposure
78
+ - XML External Entities (XXE)
79
+ - Broken Access Control
80
+ - Security Misconfiguration
81
+ - Cross-Site Scripting (XSS)
82
+ - Insecure Deserialization
83
+ - Using Components with Known Vulnerabilities
84
+ - Insufficient Logging & Monitoring
85
+ 3. Review authentication and authorization implementation
86
+ 4. Check input validation and sanitization
87
+ 5. Review error handling for information disclosure
88
+ 6. Check for hardcoded secrets or credentials
89
+ 7. Review encryption and data protection
90
+ 8. Generate security review report with findings and recommendations
91
+
92
+ Output: Comprehensive security review report with vulnerability findings and remediation plan.
93
+ """,
94
+ agent=self.agent,
95
+ expected_output="Security review report with vulnerability findings, risk assessment, and remediation plan",
96
+ )
97
+
98
+ def create_vulnerability_scan_task(self, scan_context: str) -> Task:
99
+ """Create task for vulnerability scanning.
100
+
101
+ Args:
102
+ scan_context: Application and infrastructure context
103
+
104
+ Returns:
105
+ Task for vulnerability scanning
106
+ """
107
+ return Task(
108
+ description=f"""Perform vulnerability scanning on the application.
109
+
110
+ Scan Context:
111
+ {scan_context}
112
+
113
+ Your task:
114
+ 1. Configure and run vulnerability scanning tools
115
+ 2. Scan for known vulnerabilities in dependencies
116
+ 3. Scan for configuration vulnerabilities
117
+ 4. Scan for infrastructure vulnerabilities
118
+ 5. Analyze scan results and prioritize findings
119
+ 6. Generate vulnerability report with:
120
+ - Vulnerability list with severity (Critical, High, Medium, Low)
121
+ - Affected components
122
+ - Exploitability assessment
123
+ - Business impact analysis
124
+ - Remediation recommendations
125
+ 7. Create remediation timeline
126
+ 8. Document false positives
127
+
128
+ Output: Vulnerability scan report with prioritized findings and remediation plan.
129
+ """,
130
+ agent=self.agent,
131
+ expected_output="Vulnerability scan report with severity ratings and remediation timeline",
132
+ )
133
+
134
+ def create_secure_coding_task(self, coding_guidelines: str) -> Task:
135
+ """Create task for establishing secure coding guidelines.
136
+
137
+ Args:
138
+ coding_guidelines: Existing coding standards and practices
139
+
140
+ Returns:
141
+ Task for secure coding guidelines
142
+ """
143
+ return Task(
144
+ description=f"""Establish secure coding guidelines for the project.
145
+
146
+ Existing Guidelines:
147
+ {coding_guidelines}
148
+
149
+ Your task:
150
+ 1. Define secure coding principles
151
+ 2. Create guidelines for:
152
+ - Input validation and sanitization
153
+ - Output encoding
154
+ - Authentication and authorization
155
+ - Session management
156
+ - Cryptography usage
157
+ - Error handling and logging
158
+ - Data protection
159
+ - API security
160
+ 3. Provide code examples for each guideline
161
+ 4. Define security checklists for developers
162
+ 5. Create security review checklist
163
+ 6. Document common security pitfalls and how to avoid them
164
+ 7. Integrate guidelines into development workflow
165
+
166
+ Output: Comprehensive secure coding guidelines with examples and checklists.
167
+ """,
168
+ agent=self.agent,
169
+ expected_output="Secure coding guidelines document with examples and developer checklists",
170
+ )
171
+
172
+ def create_dependency_security_task(self, dependency_context: str) -> Task:
173
+ """Create task for dependency security review.
174
+
175
+ Args:
176
+ dependency_context: List of dependencies and versions
177
+
178
+ Returns:
179
+ Task for dependency security review
180
+ """
181
+ return Task(
182
+ description=f"""Review security of project dependencies.
183
+
184
+ Dependency Context:
185
+ {dependency_context}
186
+
187
+ Your task:
188
+ 1. List all project dependencies
189
+ 2. Check for known vulnerabilities in each dependency
190
+ 3. Review dependency update history
191
+ 4. Identify outdated dependencies with security fixes
192
+ 5. Assess risk of vulnerable dependencies
193
+ 6. Recommend updates or replacements
194
+ 7. Create dependency security policy
195
+ 8. Set up automated dependency scanning
196
+ 9. Document dependency maintenance process
197
+
198
+ Output: Dependency security report with update recommendations and maintenance policy.
199
+ """,
200
+ agent=self.agent,
201
+ expected_output="Dependency security report with vulnerability assessment and update recommendations",
202
+ )
203
+
204
+ def create_authentication_security_task(self, auth_context: str) -> Task:
205
+ """Create task for authentication security review.
206
+
207
+ Args:
208
+ auth_context: Authentication implementation details
209
+
210
+ Returns:
211
+ Task for authentication security review
212
+ """
213
+ return Task(
214
+ description=f"""Review and strengthen authentication security.
215
+
216
+ Authentication Context:
217
+ {auth_context}
218
+
219
+ Your task:
220
+ 1. Review authentication implementation
221
+ 2. Check for:
222
+ - Strong password policies
223
+ - Multi-factor authentication (MFA)
224
+ - Secure session management
225
+ - Proper token handling (JWT, OAuth)
226
+ - Account lockout mechanisms
227
+ - Password reset security
228
+ - Session timeout configuration
229
+ 3. Test authentication flows for vulnerabilities
230
+ 4. Review authorization implementation
231
+ 5. Check for privilege escalation vulnerabilities
232
+ 6. Test role-based access control (RBAC)
233
+ 7. Generate authentication security report with recommendations
234
+
235
+ Output: Authentication security report with findings and hardening recommendations.
236
+ """,
237
+ agent=self.agent,
238
+ expected_output="Authentication security report with vulnerability findings and hardening plan",
239
+ )
240
+
241
+ def create_data_protection_task(self, data_context: str) -> Task:
242
+ """Create task for data protection review.
243
+
244
+ Args:
245
+ data_context: Data handling and storage details
246
+
247
+ Returns:
248
+ Task for data protection review
249
+ """
250
+ return Task(
251
+ description=f"""Review data protection and privacy measures.
252
+
253
+ Data Context:
254
+ {data_context}
255
+
256
+ Your task:
257
+ 1. Identify sensitive data types (PII, financial, health, etc.)
258
+ 2. Review data encryption at rest
259
+ 3. Review data encryption in transit
260
+ 4. Check data masking and anonymization
261
+ 5. Review data retention policies
262
+ 6. Check data backup security
263
+ 7. Review GDPR/privacy compliance
264
+ 8. Check data access controls
265
+ 9. Review data logging and audit trails
266
+ 10. Generate data protection report with recommendations
267
+
268
+ Output: Data protection report with compliance assessment and recommendations.
269
+ """,
270
+ agent=self.agent,
271
+ expected_output="Data protection report with compliance assessment and security recommendations",
272
+ )
273
+
274
+ def create_api_security_task(self, api_context: str) -> Task:
275
+ """Create task for API security review.
276
+
277
+ Args:
278
+ api_context: API endpoints and implementation details
279
+
280
+ Returns:
281
+ Task for API security review
282
+ """
283
+ return Task(
284
+ description=f"""Review API security implementation.
285
+
286
+ API Context:
287
+ {api_context}
288
+
289
+ Your task:
290
+ 1. Review all API endpoints for security
291
+ 2. Check for:
292
+ - Proper authentication and authorization
293
+ - Rate limiting and throttling
294
+ - Input validation
295
+ - Output encoding
296
+ - CORS configuration
297
+ - API versioning security
298
+ - Error message information disclosure
299
+ - API key management
300
+ 3. Test for common API vulnerabilities
301
+ 4. Review API documentation for security guidance
302
+ 5. Check for sensitive data in API responses
303
+ 6. Review API logging and monitoring
304
+ 7. Generate API security report with recommendations
305
+
306
+ Output: API security report with vulnerability findings and hardening recommendations.
307
+ """,
308
+ agent=self.agent,
309
+ expected_output="API security report with vulnerability assessment and hardening plan",
310
+ )
311
+
312
+ def create_security_monitoring_task(self, monitoring_context: str) -> Task:
313
+ """Create task for security monitoring setup.
314
+
315
+ Args:
316
+ monitoring_context: Application and infrastructure context
317
+
318
+ Returns:
319
+ Task for security monitoring setup
320
+ """
321
+ return Task(
322
+ description=f"""Set up security monitoring and alerting.
323
+
324
+ Monitoring Context:
325
+ {monitoring_context}
326
+
327
+ Your task:
328
+ 1. Define security monitoring requirements
329
+ 2. Set up logging for security events:
330
+ - Authentication failures
331
+ - Authorization failures
332
+ - Suspicious activities
333
+ - Data access
334
+ - Configuration changes
335
+ 3. Configure security alerts and notifications
336
+ 4. Set up intrusion detection
337
+ 5. Configure security dashboards
338
+ 6. Define incident response procedures
339
+ 7. Set up security audit trails
340
+ 8. Document monitoring setup and procedures
341
+
342
+ Output: Security monitoring setup with alerting and incident response procedures.
343
+ """,
344
+ agent=self.agent,
345
+ expected_output="Security monitoring infrastructure with alerting and incident response documentation",
346
+ )
347
+
348
+ def create_compliance_review_task(self, compliance_context: str) -> Task:
349
+ """Create task for compliance review.
350
+
351
+ Args:
352
+ compliance_context: Compliance requirements and standards
353
+
354
+ Returns:
355
+ Task for compliance review
356
+ """
357
+ return Task(
358
+ description=f"""Review compliance with security standards and regulations.
359
+
360
+ Compliance Context:
361
+ {compliance_context}
362
+
363
+ Your task:
364
+ 1. Identify applicable compliance standards (GDPR, HIPAA, PCI-DSS, SOC2, etc.)
365
+ 2. Review current implementation against requirements
366
+ 3. Identify compliance gaps
367
+ 4. Assess risk of non-compliance
368
+ 5. Create remediation plan for gaps
369
+ 6. Document compliance controls
370
+ 7. Set up compliance monitoring
371
+ 8. Prepare compliance documentation
372
+ 9. Generate compliance report with findings and recommendations
373
+
374
+ Output: Compliance review report with gap analysis and remediation plan.
375
+ """,
376
+ agent=self.agent,
377
+ expected_output="Compliance review report with gap analysis and remediation recommendations",
378
+ )
379
+
380
+ def get_agent(self) -> Agent:
381
+ """Get the CrewAI Agent instance.
382
+
383
+ Returns:
384
+ CrewAI Agent instance
385
+ """
386
+ return self.agent