secfoo 0.1.0__py3-none-any.whl
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.
Potentially problematic release.
This version of secfoo might be problematic. Click here for more details.
- secfoo/__about__.py +1 -0
- secfoo/__init__.py +3 -0
- secfoo/agents/__init__.py +4 -0
- secfoo/agents/antigravity.py +47 -0
- secfoo/agents/base.py +113 -0
- secfoo/agents/claude.py +36 -0
- secfoo/agents/cursor.py +26 -0
- secfoo/agents/gemini.py +38 -0
- secfoo/agents/registry.py +22 -0
- secfoo/cli.py +243 -0
- secfoo/config.py +21 -0
- secfoo/report/__init__.py +3 -0
- secfoo/report/markdown.py +43 -0
- secfoo/runner.py +197 -0
- secfoo/skills/__init__.py +11 -0
- secfoo/skills/definitions/deployment-readiness.md +42 -0
- secfoo/skills/definitions/prompt-review.md +44 -0
- secfoo/skills/definitions/responsible-ai-compliance.md +41 -0
- secfoo/skills/definitions/threat-assessment.md +41 -0
- secfoo/skills/loader.py +77 -0
- secfoo/skills/renderer.py +149 -0
- secfoo/storage/__init__.py +4 -0
- secfoo/storage/models.py +33 -0
- secfoo/storage/repository.py +154 -0
- secfoo/storage/schema.sql +30 -0
- secfoo/targets/__init__.py +19 -0
- secfoo/targets/github.py +35 -0
- secfoo/targets/resolver.py +50 -0
- secfoo/web/__init__.py +0 -0
- secfoo/web/app.py +19 -0
- secfoo/web/routes/__init__.py +0 -0
- secfoo/web/routes/overview.py +20 -0
- secfoo/web/routes/projects.py +22 -0
- secfoo/web/routes/runs.py +41 -0
- secfoo/web/static/design-system/README.md +108 -0
- secfoo/web/static/design-system/base.css +91 -0
- secfoo/web/static/design-system/components/alerts.css +49 -0
- secfoo/web/static/design-system/components/badges.css +48 -0
- secfoo/web/static/design-system/components/buttons.css +120 -0
- secfoo/web/static/design-system/components/cards.css +72 -0
- secfoo/web/static/design-system/components/forms.css +108 -0
- secfoo/web/static/design-system/components/modal.css +63 -0
- secfoo/web/static/design-system/components/navigation.css +79 -0
- secfoo/web/static/design-system/components/tables.css +38 -0
- secfoo/web/static/design-system/components/tabs.css +40 -0
- secfoo/web/static/design-system/demo.html +222 -0
- secfoo/web/static/design-system/design-system.css +18 -0
- secfoo/web/static/design-system/tokens.css +146 -0
- secfoo/web/templates/base.html +31 -0
- secfoo/web/templates/overview.html +48 -0
- secfoo/web/templates/project.html +25 -0
- secfoo/web/templates/run_detail.html +50 -0
- secfoo/web/templating.py +38 -0
- secfoo-0.1.0.dist-info/METADATA +73 -0
- secfoo-0.1.0.dist-info/RECORD +58 -0
- secfoo-0.1.0.dist-info/WHEEL +4 -0
- secfoo-0.1.0.dist-info/entry_points.txt +2 -0
- secfoo-0.1.0.dist-info/licenses/LICENSE +202 -0
secfoo/runner.py
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
"""Orchestrates skill x target x agent: resolves the target, renders each
|
|
2
|
+
skill's prompt, invokes the chosen agent adapter, and persists results.
|
|
3
|
+
|
|
4
|
+
Selected skills run concurrently (one thread per skill, bounded by how many
|
|
5
|
+
skills were selected) rather than one after another, since each is an
|
|
6
|
+
independent read-only pass over the same target and the slow part is
|
|
7
|
+
waiting on an external agent CLI, not local CPU work.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import re
|
|
13
|
+
from collections.abc import Callable, Iterator
|
|
14
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
15
|
+
from contextlib import contextmanager
|
|
16
|
+
from dataclasses import dataclass
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
from typing import Literal
|
|
19
|
+
|
|
20
|
+
from secfoo.agents.registry import get_adapter
|
|
21
|
+
from secfoo.config import ensure_store_dirs, run_dir
|
|
22
|
+
from secfoo.skills.loader import load_skill
|
|
23
|
+
from secfoo.skills.renderer import TargetContext, render_prompt
|
|
24
|
+
from secfoo.storage.repository import RunRepository
|
|
25
|
+
from secfoo.targets.github import clone_shallow
|
|
26
|
+
from secfoo.targets.resolver import ResolvedTarget, TargetKind, resolve_target
|
|
27
|
+
|
|
28
|
+
STDERR_EXCERPT_LIMIT = 2000
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@dataclass
|
|
32
|
+
class RunOutcome:
|
|
33
|
+
run_uuid: str
|
|
34
|
+
skill_id: str
|
|
35
|
+
skill_name: str
|
|
36
|
+
agent_id: str
|
|
37
|
+
status: str
|
|
38
|
+
exit_code: int | None
|
|
39
|
+
duration_seconds: float | None
|
|
40
|
+
report_path: str | None
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _project_display_name(resolved: ResolvedTarget) -> str:
|
|
44
|
+
if resolved.kind is TargetKind.GITHUB:
|
|
45
|
+
cleaned = resolved.display_name.rstrip("/")
|
|
46
|
+
if cleaned.endswith(".git"):
|
|
47
|
+
cleaned = cleaned[: -len(".git")]
|
|
48
|
+
match = re.search(r"github\.com[/:]([^/]+/[^/]+)$", cleaned)
|
|
49
|
+
return match.group(1) if match else cleaned
|
|
50
|
+
return Path(resolved.display_name).name or resolved.display_name
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@contextmanager
|
|
54
|
+
def _target_workdir(resolved: ResolvedTarget) -> Iterator[Path]:
|
|
55
|
+
if resolved.kind is TargetKind.GITHUB:
|
|
56
|
+
with clone_shallow(resolved.display_name) as tmp_dir:
|
|
57
|
+
yield tmp_dir
|
|
58
|
+
else:
|
|
59
|
+
assert resolved.path is not None
|
|
60
|
+
yield resolved.path
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _run_single_skill(
|
|
64
|
+
*,
|
|
65
|
+
skill_id: str,
|
|
66
|
+
project_id: int,
|
|
67
|
+
agent_id: str,
|
|
68
|
+
target_ctx: TargetContext,
|
|
69
|
+
confluence_urls: list[str],
|
|
70
|
+
depth: Literal["quick", "standard"],
|
|
71
|
+
timeout: int | None,
|
|
72
|
+
db_path,
|
|
73
|
+
on_skill_start: Callable[[str], None] | None,
|
|
74
|
+
on_skill_complete: Callable[[str, str], None] | None,
|
|
75
|
+
) -> RunOutcome:
|
|
76
|
+
skill = load_skill(skill_id)
|
|
77
|
+
prompt = render_prompt(skill, target_ctx, depth=depth)
|
|
78
|
+
|
|
79
|
+
# A fresh connection per worker thread: sqlite3 connections may not be
|
|
80
|
+
# shared across threads.
|
|
81
|
+
repo = RunRepository(db_path=db_path)
|
|
82
|
+
try:
|
|
83
|
+
run_uuid = repo.create_run(
|
|
84
|
+
project_id=project_id,
|
|
85
|
+
skill_id=skill.id,
|
|
86
|
+
skill_name=skill.name,
|
|
87
|
+
agent_id=agent_id,
|
|
88
|
+
confluence_urls=confluence_urls,
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
report_dir = run_dir(run_uuid)
|
|
92
|
+
report_dir.mkdir(parents=True, exist_ok=True)
|
|
93
|
+
prompt_path = report_dir / "prompt.md"
|
|
94
|
+
prompt_path.write_text(prompt)
|
|
95
|
+
|
|
96
|
+
if on_skill_start:
|
|
97
|
+
on_skill_start(skill.name)
|
|
98
|
+
|
|
99
|
+
adapter = get_adapter(agent_id)
|
|
100
|
+
result = adapter.run(prompt, workdir=target_ctx.local_path, timeout=timeout)
|
|
101
|
+
|
|
102
|
+
if on_skill_complete:
|
|
103
|
+
on_skill_complete(skill.name, result.status)
|
|
104
|
+
|
|
105
|
+
(report_dir / "stdout.log").write_text(result.stdout)
|
|
106
|
+
(report_dir / "stderr.log").write_text(result.stderr)
|
|
107
|
+
report_path = report_dir / "report.md"
|
|
108
|
+
report_path.write_text(result.raw_report)
|
|
109
|
+
|
|
110
|
+
repo.complete_run(
|
|
111
|
+
run_uuid,
|
|
112
|
+
status=result.status,
|
|
113
|
+
exit_code=result.exit_code,
|
|
114
|
+
duration_seconds=result.duration_seconds,
|
|
115
|
+
report_path=str(report_path),
|
|
116
|
+
prompt_path=str(prompt_path),
|
|
117
|
+
stderr_excerpt=(result.stderr or "")[:STDERR_EXCERPT_LIMIT] or None,
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
return RunOutcome(
|
|
121
|
+
run_uuid=run_uuid,
|
|
122
|
+
skill_id=skill.id,
|
|
123
|
+
skill_name=skill.name,
|
|
124
|
+
agent_id=agent_id,
|
|
125
|
+
status=result.status,
|
|
126
|
+
exit_code=result.exit_code,
|
|
127
|
+
duration_seconds=result.duration_seconds,
|
|
128
|
+
report_path=str(report_path),
|
|
129
|
+
)
|
|
130
|
+
finally:
|
|
131
|
+
repo.close()
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def execute_runs(
|
|
135
|
+
*,
|
|
136
|
+
skill_ids: list[str],
|
|
137
|
+
target: str | None,
|
|
138
|
+
confluence_urls: list[str],
|
|
139
|
+
agent_id: str,
|
|
140
|
+
depth: Literal["quick", "standard"] = "quick",
|
|
141
|
+
timeout: int | None = None,
|
|
142
|
+
repo: RunRepository | None = None,
|
|
143
|
+
on_skill_start: Callable[[str], None] | None = None,
|
|
144
|
+
on_skill_complete: Callable[[str, str], None] | None = None,
|
|
145
|
+
) -> list[RunOutcome]:
|
|
146
|
+
"""Run each skill in `skill_ids` concurrently against `agent_id`.
|
|
147
|
+
|
|
148
|
+
`on_skill_start(skill_name)` fires right before an agent CLI is invoked
|
|
149
|
+
for a skill, and `on_skill_complete(skill_name, status)` fires right
|
|
150
|
+
after -- callers (e.g. the CLI) use these to show live progress, since
|
|
151
|
+
an individual agent invocation can take minutes with no output of its
|
|
152
|
+
own. Both may be called concurrently from different threads.
|
|
153
|
+
"""
|
|
154
|
+
ensure_store_dirs()
|
|
155
|
+
owns_repo = repo is None
|
|
156
|
+
repo = repo or RunRepository()
|
|
157
|
+
try:
|
|
158
|
+
resolved = resolve_target(target)
|
|
159
|
+
project_id = repo.upsert_project(
|
|
160
|
+
identifier=resolved.display_name,
|
|
161
|
+
display_name=_project_display_name(resolved),
|
|
162
|
+
kind=resolved.kind.value,
|
|
163
|
+
)
|
|
164
|
+
db_path = repo.db_path
|
|
165
|
+
|
|
166
|
+
with _target_workdir(resolved) as workdir:
|
|
167
|
+
target_ctx = TargetContext(
|
|
168
|
+
kind=resolved.kind.value, # type: ignore[arg-type]
|
|
169
|
+
local_path=workdir,
|
|
170
|
+
display_source=resolved.display_name,
|
|
171
|
+
confluence_urls=confluence_urls,
|
|
172
|
+
)
|
|
173
|
+
with ThreadPoolExecutor(max_workers=max(1, len(skill_ids))) as pool:
|
|
174
|
+
futures = [
|
|
175
|
+
pool.submit(
|
|
176
|
+
_run_single_skill,
|
|
177
|
+
skill_id=skill_id,
|
|
178
|
+
project_id=project_id,
|
|
179
|
+
agent_id=agent_id,
|
|
180
|
+
target_ctx=target_ctx,
|
|
181
|
+
confluence_urls=confluence_urls,
|
|
182
|
+
depth=depth,
|
|
183
|
+
timeout=timeout,
|
|
184
|
+
db_path=db_path,
|
|
185
|
+
on_skill_start=on_skill_start,
|
|
186
|
+
on_skill_complete=on_skill_complete,
|
|
187
|
+
)
|
|
188
|
+
for skill_id in skill_ids
|
|
189
|
+
]
|
|
190
|
+
# Iterating futures in submission order still reflects real
|
|
191
|
+
# concurrency (each already runs in the pool); this just
|
|
192
|
+
# keeps the returned list in the order skills were requested.
|
|
193
|
+
outcomes = [f.result() for f in futures]
|
|
194
|
+
return outcomes
|
|
195
|
+
finally:
|
|
196
|
+
if owns_repo:
|
|
197
|
+
repo.close()
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from secfoo.skills.loader import Skill, SkillLoadError, load_all_skills, load_skill
|
|
2
|
+
from secfoo.skills.renderer import TargetContext, render_prompt
|
|
3
|
+
|
|
4
|
+
__all__ = [
|
|
5
|
+
"Skill",
|
|
6
|
+
"SkillLoadError",
|
|
7
|
+
"load_all_skills",
|
|
8
|
+
"load_skill",
|
|
9
|
+
"TargetContext",
|
|
10
|
+
"render_prompt",
|
|
11
|
+
]
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: deployment-readiness
|
|
3
|
+
name: Deployment Readiness
|
|
4
|
+
description: Security and operational readiness review for production deployment.
|
|
5
|
+
version: 1
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
Review this codebase for security and operational deployment readiness.
|
|
9
|
+
|
|
10
|
+
1. **CI/CD security gates.** Does the pipeline run static analysis (SAST),
|
|
11
|
+
dependency vulnerability scanning, and secret scanning before merge/
|
|
12
|
+
deploy? Are these gates blocking or advisory-only?
|
|
13
|
+
|
|
14
|
+
2. **Secrets management.** Are there any secrets, API keys, or credentials
|
|
15
|
+
committed to the repository? Is secret retrieval done via a vault or
|
|
16
|
+
parameter store rather than plaintext config or environment files
|
|
17
|
+
checked into version control?
|
|
18
|
+
|
|
19
|
+
3. **Health & rollback.** Are there health-check endpoints or equivalent
|
|
20
|
+
readiness/liveness signals? Is there a documented or automated rollback
|
|
21
|
+
strategy if a deployment fails?
|
|
22
|
+
|
|
23
|
+
4. **Observability.** Is there structured logging, metrics, and alerting
|
|
24
|
+
sufficient to detect a security incident or outage in production?
|
|
25
|
+
|
|
26
|
+
5. **Infrastructure as Code review.** If IaC is present (Terraform,
|
|
27
|
+
CloudFormation, Kubernetes manifests, etc.), check for least-privilege
|
|
28
|
+
IAM roles/policies, network segmentation, and publicly-exposed resources
|
|
29
|
+
that shouldn't be.
|
|
30
|
+
|
|
31
|
+
6. **Rate limiting & DoS protection.** Are public-facing endpoints protected
|
|
32
|
+
against abuse or denial-of-service?
|
|
33
|
+
|
|
34
|
+
7. **Backup & disaster recovery.** Is there a backup strategy for any
|
|
35
|
+
persistent data, and is recovery documented or tested?
|
|
36
|
+
|
|
37
|
+
8. **Dependency hygiene.** Are dependencies pinned to specific versions? Is
|
|
38
|
+
there a software bill of materials (SBOM) or equivalent?
|
|
39
|
+
|
|
40
|
+
9. **Container hardening.** If a Dockerfile or container manifest is
|
|
41
|
+
present, check for a non-root user, a minimal base image, and no
|
|
42
|
+
unnecessary build tools or secrets baked into the final image layer.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: prompt-review
|
|
3
|
+
name: Prompt Review
|
|
4
|
+
description: Security review of LLM prompts, tool-calling definitions, and agent behavior.
|
|
5
|
+
version: 1
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
Review this codebase for LLM prompt and agent security issues.
|
|
9
|
+
|
|
10
|
+
1. **Locate all prompt surfaces.** Find system prompts, prompt templates,
|
|
11
|
+
few-shot examples, and tool/function-calling definitions (schemas,
|
|
12
|
+
allowed tool lists, permission scopes).
|
|
13
|
+
|
|
14
|
+
2. **Check prompt injection resistance.** Identify places where untrusted
|
|
15
|
+
input (user messages, retrieved documents, tool outputs, web content) is
|
|
16
|
+
concatenated directly into instruction context without delimiters,
|
|
17
|
+
escaping, or a clear boundary between instructions and data. Flag any
|
|
18
|
+
place a downstream actor could smuggle instructions into the model's
|
|
19
|
+
context.
|
|
20
|
+
|
|
21
|
+
3. **Check tool/function-calling permission scope.** Are LLM-callable tools
|
|
22
|
+
scoped to the minimum needed (read-only where possible), or is the model
|
|
23
|
+
granted broad capabilities (arbitrary shell execution, unrestricted file
|
|
24
|
+
write, unscoped database access, outbound network calls) that go beyond
|
|
25
|
+
what the feature requires?
|
|
26
|
+
|
|
27
|
+
4. **Check human-in-the-loop / validation before side effects.** Are
|
|
28
|
+
LLM-suggested actions (shell commands, SQL queries, file writes, API
|
|
29
|
+
calls, financial transactions) validated or confirmed before execution,
|
|
30
|
+
or can the model act unattended on unvalidated output?
|
|
31
|
+
|
|
32
|
+
5. **Check for data leakage.** Are secrets, API keys, or PII ever
|
|
33
|
+
interpolated into prompts, logged in full alongside prompt/response
|
|
34
|
+
pairs, or sent to third-party model providers without the user's
|
|
35
|
+
awareness?
|
|
36
|
+
|
|
37
|
+
6. **Check guardrail robustness.** Are refusal/safety instructions
|
|
38
|
+
susceptible to being overridden by a crafted user message (jailbreak
|
|
39
|
+
patterns)? Is refusal behavior consistent, or does it rely solely on the
|
|
40
|
+
model's own judgment with no code-level backstop for high-risk actions?
|
|
41
|
+
|
|
42
|
+
7. **Check rate/cost controls.** Is there any protection against a single
|
|
43
|
+
caller triggering unbounded numbers of expensive model calls (cost or
|
|
44
|
+
availability risk)?
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: responsible-ai-compliance
|
|
3
|
+
name: Responsible AI Compliance
|
|
4
|
+
description: Checks for responsible-AI governance, transparency, and fairness practices.
|
|
5
|
+
version: 1
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
Review this codebase and any accompanying documentation for responsible AI
|
|
9
|
+
governance and compliance practices.
|
|
10
|
+
|
|
11
|
+
1. **Documentation.** Is there a model card, data card, or equivalent
|
|
12
|
+
documentation describing the model(s) used, their intended use, known
|
|
13
|
+
limitations, and training/fine-tuning data provenance?
|
|
14
|
+
|
|
15
|
+
2. **Bias & fairness.** Is there any evidence of bias or fairness testing
|
|
16
|
+
against protected characteristics? Are there known failure modes or
|
|
17
|
+
subgroups documented?
|
|
18
|
+
|
|
19
|
+
3. **Human oversight.** For high-stakes or irreversible decisions made or
|
|
20
|
+
influenced by the model, is there a human-in-the-loop review step or an
|
|
21
|
+
escalation path? Is fully autonomous action limited to lower-stakes
|
|
22
|
+
cases?
|
|
23
|
+
|
|
24
|
+
4. **Transparency to end users.** Are users clearly informed when they are
|
|
25
|
+
interacting with an AI system, and when AI has materially influenced a
|
|
26
|
+
decision that affects them?
|
|
27
|
+
|
|
28
|
+
5. **Data provenance & consent.** For any training, fine-tuning, or
|
|
29
|
+
retrieval data, is there documentation of where it came from and whether
|
|
30
|
+
appropriate consent/licensing was obtained?
|
|
31
|
+
|
|
32
|
+
6. **Framework alignment.** If the project references a specific governance
|
|
33
|
+
framework (e.g. NIST AI RMF, EU AI Act risk tiers, an internal AI policy),
|
|
34
|
+
check whether the implementation is consistent with the claimed tier or
|
|
35
|
+
requirements. If no framework is referenced at all but the system appears
|
|
36
|
+
to be a high-impact use case, flag the absence of a documented risk tier
|
|
37
|
+
as a finding.
|
|
38
|
+
|
|
39
|
+
7. **Auditability & recourse.** Is there an audit trail of significant AI
|
|
40
|
+
decisions? Is there a mechanism for a user to contest or appeal an
|
|
41
|
+
AI-influenced decision?
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: threat-assessment
|
|
3
|
+
name: Threat Assessment
|
|
4
|
+
description: Fast enterprise threat model — STRIDE, OWASP Top 10, architectural context, and a severity summary table.
|
|
5
|
+
version: 2
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
Perform a fast, enterprise-grade architectural threat assessment. This is
|
|
9
|
+
meant to run quickly — prioritize the highest-signal findings over
|
|
10
|
+
exhaustive coverage.
|
|
11
|
+
|
|
12
|
+
## Severity scale
|
|
13
|
+
Use only **High**, **Medium**, and **Low** for this assessment. Do not use
|
|
14
|
+
Critical or Informational — fold anything Critical-level into High.
|
|
15
|
+
|
|
16
|
+
## 1. Architectural context
|
|
17
|
+
In 3-5 bullet points, briefly summarize: the system's purpose, major
|
|
18
|
+
components, trust boundaries, entry points (APIs, CLI, file uploads,
|
|
19
|
+
webhooks, scheduled jobs), and where secrets/credentials are stored or
|
|
20
|
+
referenced. Keep this short — it exists to ground the findings below, not
|
|
21
|
+
to be a standalone document.
|
|
22
|
+
|
|
23
|
+
## 2. STRIDE threat modeling
|
|
24
|
+
Walk the architecture above through STRIDE: Spoofing, Tampering,
|
|
25
|
+
Repudiation, Information Disclosure, Denial of Service, Elevation of
|
|
26
|
+
Privilege. Only report a finding where there's concrete evidence in the
|
|
27
|
+
code or config — do not list generic STRIDE theory with nothing attached.
|
|
28
|
+
|
|
29
|
+
## 3. OWASP Top 10 (2021) checklist
|
|
30
|
+
Check explicitly for each of the following and report a finding wherever
|
|
31
|
+
there's evidence. Skip categories with nothing to report — do not write
|
|
32
|
+
"not found" for every category, that wastes time:
|
|
33
|
+
A01 Broken Access Control · A02 Cryptographic Failures · A03 Injection ·
|
|
34
|
+
A04 Insecure Design · A05 Security Misconfiguration · A06 Vulnerable and
|
|
35
|
+
Outdated Components · A07 Identification and Authentication Failures ·
|
|
36
|
+
A08 Software and Data Integrity Failures · A09 Security Logging and
|
|
37
|
+
Monitoring Failures · A10 Server-Side Request Forgery (SSRF)
|
|
38
|
+
|
|
39
|
+
## 4. Remediation
|
|
40
|
+
Every finding must include a concrete, actionable fix a developer could
|
|
41
|
+
implement directly — not "review this" or "consider hardening."
|
secfoo/skills/loader.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"""Loads skill definitions from Markdown files with a small hand-parsed
|
|
2
|
+
frontmatter block (id/name/description/version). Deliberately avoids a YAML
|
|
3
|
+
dependency since the schema is tiny and fixed.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
from functools import lru_cache
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
DEFINITIONS_DIR = Path(__file__).parent / "definitions"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class SkillLoadError(RuntimeError):
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@dataclass(frozen=True)
|
|
20
|
+
class Skill:
|
|
21
|
+
id: str
|
|
22
|
+
name: str
|
|
23
|
+
description: str
|
|
24
|
+
version: int
|
|
25
|
+
body: str
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _parse_frontmatter(text: str, *, source: Path) -> tuple[dict[str, str], str]:
|
|
29
|
+
if not text.startswith("---"):
|
|
30
|
+
raise SkillLoadError(f"{source}: missing frontmatter block")
|
|
31
|
+
parts = text.split("---", 2)
|
|
32
|
+
if len(parts) < 3:
|
|
33
|
+
raise SkillLoadError(f"{source}: malformed frontmatter block")
|
|
34
|
+
_, raw_frontmatter, body = parts
|
|
35
|
+
fields: dict[str, str] = {}
|
|
36
|
+
for line in raw_frontmatter.strip().splitlines():
|
|
37
|
+
if not line.strip():
|
|
38
|
+
continue
|
|
39
|
+
if ":" not in line:
|
|
40
|
+
raise SkillLoadError(f"{source}: bad frontmatter line {line!r}")
|
|
41
|
+
key, _, value = line.partition(":")
|
|
42
|
+
fields[key.strip()] = value.strip()
|
|
43
|
+
return fields, body.strip()
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _load_file(path: Path) -> Skill:
|
|
47
|
+
fields, body = _parse_frontmatter(path.read_text(), source=path)
|
|
48
|
+
try:
|
|
49
|
+
return Skill(
|
|
50
|
+
id=fields["id"],
|
|
51
|
+
name=fields["name"],
|
|
52
|
+
description=fields["description"],
|
|
53
|
+
version=int(fields["version"]),
|
|
54
|
+
body=body,
|
|
55
|
+
)
|
|
56
|
+
except KeyError as exc:
|
|
57
|
+
raise SkillLoadError(f"{path}: missing required frontmatter field {exc}") from exc
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@lru_cache(maxsize=1)
|
|
61
|
+
def load_all_skills() -> dict[str, Skill]:
|
|
62
|
+
skills: dict[str, Skill] = {}
|
|
63
|
+
for path in sorted(DEFINITIONS_DIR.glob("*.md")):
|
|
64
|
+
skill = _load_file(path)
|
|
65
|
+
if skill.id in skills:
|
|
66
|
+
raise SkillLoadError(f"duplicate skill id {skill.id!r} in {path}")
|
|
67
|
+
skills[skill.id] = skill
|
|
68
|
+
return skills
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def load_skill(skill_id: str) -> Skill:
|
|
72
|
+
skills = load_all_skills()
|
|
73
|
+
try:
|
|
74
|
+
return skills[skill_id]
|
|
75
|
+
except KeyError:
|
|
76
|
+
available = ", ".join(sorted(skills)) or "<none found>"
|
|
77
|
+
raise SkillLoadError(f"unknown skill id {skill_id!r}. Available: {available}") from None
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"""Assembles the final prompt sent to an agent CLI from a Skill + target context.
|
|
2
|
+
|
|
3
|
+
The output contract and safety preamble are defined once here and shared by
|
|
4
|
+
every skill, so the dashboard can rely on a consistent report shape
|
|
5
|
+
regardless of which skill or agent produced it.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from dataclasses import dataclass, field
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from typing import Literal
|
|
13
|
+
|
|
14
|
+
from secfoo.skills.loader import Skill
|
|
15
|
+
|
|
16
|
+
SAFETY_PREAMBLE = """\
|
|
17
|
+
You are performing a READ-ONLY security architectural review. Do not modify,
|
|
18
|
+
delete, move, or create any files in the target. Only read and analyze. Do
|
|
19
|
+
not run any commands that change state (no installs, no git commits, no
|
|
20
|
+
network calls other than fetching the reference material described below).
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
DEFAULT_EXCLUDE_PATHS = [
|
|
24
|
+
"node_modules/", ".git/", "dist/", "build/", "out/", ".next/", ".nuxt/",
|
|
25
|
+
"venv/", ".venv/", "env/", "__pycache__/", ".pytest_cache/", ".mypy_cache/",
|
|
26
|
+
".ruff_cache/", "coverage/", ".turbo/", "target/", "vendor/", ".terraform/",
|
|
27
|
+
"*.min.js", "*.min.css", "*.egg-info/", "*.lock",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
EXCLUDE_SECTION = (
|
|
31
|
+
"## Scope\n"
|
|
32
|
+
"Do not read, analyze, or enumerate files under the following paths — "
|
|
33
|
+
"they are build artifacts, dependencies, or caches, never "
|
|
34
|
+
"security-relevant, and reading them wastes time:\n"
|
|
35
|
+
+ ", ".join(f"`{p}`" for p in DEFAULT_EXCLUDE_PATHS)
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
DEPTH_GUIDANCE = {
|
|
39
|
+
"quick": (
|
|
40
|
+
"## Scan depth: QUICK\n"
|
|
41
|
+
"Time is limited — optimize for speed over exhaustiveness. Triage "
|
|
42
|
+
"fast: identify the most important 3-8 findings, prioritizing "
|
|
43
|
+
"Critical/High severity and the most security-relevant entry points "
|
|
44
|
+
"(auth, input handling, secrets, network boundaries). Do not attempt "
|
|
45
|
+
"an exhaustive file-by-file review or enumerate every instance of a "
|
|
46
|
+
"pattern — it's fine to describe a category of concern once with a "
|
|
47
|
+
"representative example rather than listing every occurrence."
|
|
48
|
+
),
|
|
49
|
+
"standard": (
|
|
50
|
+
"## Scan depth: STANDARD\n"
|
|
51
|
+
"Perform a thorough review covering the full scope of the skill's "
|
|
52
|
+
"checklist above, examining the codebase in depth rather than "
|
|
53
|
+
"sampling."
|
|
54
|
+
),
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
OUTPUT_CONTRACT = """\
|
|
58
|
+
## Required output format
|
|
59
|
+
|
|
60
|
+
Produce your assessment as a single Markdown document with EXACTLY this
|
|
61
|
+
structure (do not add extra top-level sections, do not omit any). Use only
|
|
62
|
+
the severity levels specified in the skill instructions above.
|
|
63
|
+
|
|
64
|
+
# {skill_name} Report
|
|
65
|
+
|
|
66
|
+
## Summary
|
|
67
|
+
2-4 sentence executive summary and an overall risk rating on its own line,
|
|
68
|
+
formatted as: **Overall risk rating:** <severity>.
|
|
69
|
+
|
|
70
|
+
Immediately after that, a compact findings-summary table for a fast
|
|
71
|
+
at-a-glance scan (counts only, omit rows with zero findings):
|
|
72
|
+
|
|
73
|
+
| Severity | Count |
|
|
74
|
+
|----------|-------|
|
|
75
|
+
| High | N |
|
|
76
|
+
| Medium | N |
|
|
77
|
+
| Low | N |
|
|
78
|
+
|
|
79
|
+
## Findings
|
|
80
|
+
List every finding, most severe first. For each finding use this exact
|
|
81
|
+
heading shape (the severity word in brackets is required and must match a
|
|
82
|
+
row in the summary table above):
|
|
83
|
+
|
|
84
|
+
### [SEVERITY] Finding title
|
|
85
|
+
- **Severity:** matches the summary table above
|
|
86
|
+
- **Location:** file path, component, or N/A
|
|
87
|
+
- **Description:** what the issue is and why it matters
|
|
88
|
+
- **Recommendation:** a concrete, actionable fix — not "review this"
|
|
89
|
+
|
|
90
|
+
If there are no findings for a given severity that's fine — just omit it.
|
|
91
|
+
If there are no findings at all, state that explicitly under Findings.
|
|
92
|
+
|
|
93
|
+
## Coverage Notes
|
|
94
|
+
What was reviewed, what was skipped or inaccessible (e.g. a Confluence page
|
|
95
|
+
you could not reach), and your confidence level in this assessment.
|
|
96
|
+
"""
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
@dataclass(frozen=True)
|
|
100
|
+
class TargetContext:
|
|
101
|
+
kind: Literal["local", "github"]
|
|
102
|
+
local_path: Path
|
|
103
|
+
display_source: str
|
|
104
|
+
confluence_urls: list[str] = field(default_factory=list)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _target_section(target: TargetContext) -> str:
|
|
108
|
+
lines = [
|
|
109
|
+
"## Target",
|
|
110
|
+
f"Inspect the codebase at: `{target.local_path}`",
|
|
111
|
+
]
|
|
112
|
+
if target.kind == "github":
|
|
113
|
+
lines.append(
|
|
114
|
+
f"This is a temporary shallow clone of the GitHub repository "
|
|
115
|
+
f"`{target.display_source}` — reference that URL (not the local "
|
|
116
|
+
f"temp path) in your report when identifying the target."
|
|
117
|
+
)
|
|
118
|
+
else:
|
|
119
|
+
lines.append(f"Original source path: `{target.display_source}`")
|
|
120
|
+
return "\n".join(lines)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def _confluence_section(target: TargetContext) -> str | None:
|
|
124
|
+
if not target.confluence_urls:
|
|
125
|
+
return None
|
|
126
|
+
urls = "\n".join(f"- {url}" for url in target.confluence_urls)
|
|
127
|
+
return (
|
|
128
|
+
"## Additional context (Confluence)\n"
|
|
129
|
+
"The following Confluence pages may contain relevant architectural "
|
|
130
|
+
"or compliance context. If you have MCP tooling or another means of "
|
|
131
|
+
"fetching URLs available, retrieve and incorporate them. If not, "
|
|
132
|
+
"note that gap under Coverage Notes and proceed without them:\n"
|
|
133
|
+
f"{urls}"
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def render_prompt(skill: Skill, target: TargetContext, *, depth: Literal["quick", "standard"] = "quick") -> str:
|
|
138
|
+
sections = [
|
|
139
|
+
SAFETY_PREAMBLE,
|
|
140
|
+
f"## Skill: {skill.name}\n{skill.body}",
|
|
141
|
+
DEPTH_GUIDANCE[depth],
|
|
142
|
+
_target_section(target),
|
|
143
|
+
EXCLUDE_SECTION,
|
|
144
|
+
]
|
|
145
|
+
confluence = _confluence_section(target)
|
|
146
|
+
if confluence:
|
|
147
|
+
sections.append(confluence)
|
|
148
|
+
sections.append(OUTPUT_CONTRACT.format(skill_name=skill.name))
|
|
149
|
+
return "\n\n".join(sections)
|
secfoo/storage/models.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@dataclass(frozen=True)
|
|
7
|
+
class ProjectRecord:
|
|
8
|
+
id: int
|
|
9
|
+
identifier: str
|
|
10
|
+
display_name: str
|
|
11
|
+
kind: str
|
|
12
|
+
first_seen_at: str
|
|
13
|
+
last_run_at: str
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@dataclass(frozen=True)
|
|
17
|
+
class RunRecord:
|
|
18
|
+
id: int
|
|
19
|
+
run_uuid: str
|
|
20
|
+
project_id: int
|
|
21
|
+
skill_id: str
|
|
22
|
+
skill_name: str
|
|
23
|
+
agent_id: str
|
|
24
|
+
confluence_urls: list[str]
|
|
25
|
+
status: str
|
|
26
|
+
exit_code: int | None
|
|
27
|
+
started_at: str
|
|
28
|
+
finished_at: str | None
|
|
29
|
+
duration_seconds: float | None
|
|
30
|
+
report_path: str | None
|
|
31
|
+
prompt_path: str | None
|
|
32
|
+
stderr_excerpt: str | None
|
|
33
|
+
project_display_name: str | None = None
|