Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions .github/workflows/adversarial-eval.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Adversarial repository evaluation

# Deliberately never runs on pull_request or pull_request_target. Model calls
# are billable; a maintainer must explicitly dispatch this trusted workflow.
on:
workflow_dispatch:
inputs:
api_model:
description: LiteLLM model identifier (e.g. openai/gpt-4.1-mini)
required: true
type: string
skill:
description: Built-in skill id
required: true
default: sast
type: string
claude_model:
description: Claude model identifier
required: true
type: string
claude_version:
description: Exact Claude Code npm version to test
required: true
type: string

permissions:
contents: read

jobs:
evaluate:
runs-on: ubuntu-latest
timeout-minutes: 120
strategy:
fail-fast: false
matrix:
agent: [api, claude]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
with:
path: hardened
persist-credentials: false
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
with:
ref: f24043bd6f01618128748241b6729bebc9254a26
path: baseline
persist-credentials: false
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0
with:
python-version: '3.12'
- name: Install evaluation dependencies
run: pip install -e './hardened[dev]'
- name: Install specified Claude Code version
if: matrix.agent == 'claude'
env:
CLAUDE_VERSION: ${{ inputs.claude_version }}
run: |
python -c 'import os,re; assert re.fullmatch(r"[0-9]+\.[0-9]+\.[0-9]+", os.environ["CLAUDE_VERSION"]), "Use an exact stable npm version"'
npm install --global "@anthropic-ai/claude-code@$CLAUDE_VERSION"
- name: Evaluate both revisions
env:
SKILL: ${{ inputs.skill }}
AGENT: ${{ matrix.agent }}
API_MODEL: ${{ inputs.api_model }}
CLAUDE_MODEL: ${{ inputs.claude_model }}
OPENAI_API_KEY: ${{ matrix.agent == 'api' && secrets.OPENAI_API_KEY || '' }}
ANTHROPIC_API_KEY: ${{ matrix.agent == 'claude' && secrets.ANTHROPIC_API_KEY || '' }}
run: |
mkdir artifacts
pip freeze > artifacts/dependencies.txt
if [ "$AGENT" = claude ]; then
MODEL="$CLAUDE_MODEL"
claude --version > artifacts/cli-version.txt
else
MODEL="$API_MODEL"
case "$MODEL" in openai/*) ;; *) echo "This workflow supports OpenAI API models only" >&2; exit 1;; esac
fi
failed=0
for phase in baseline hardened; do
python hardened/scripts/adversarial_eval.py --live --agent "$AGENT" \
--model "$MODEL" --skill "$SKILL" --phase "$phase" --checkout "$phase" \
--output "artifacts/$phase.jsonl" > "artifacts/$phase.md" || failed=1
done
cat artifacts/baseline.md artifacts/hardened.md >> "$GITHUB_STEP_SUMMARY"
exit "$failed"
- name: Retain evidence, including failed runs
if: always()
# Use the same artifact action pinned by the existing release workflow.
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: adversarial-${{ matrix.agent }}
path: artifacts/
6 changes: 6 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ jobs:
with:
languages: ${{ matrix.language }}
queries: security-and-quality
# tests/fixtures holds deliberately vulnerable code (the adversarial
# evaluation corpus needs a real bug for the agent to find), so its
# findings are expected and must not land in the Security tab.
config: |
paths-ignore:
- tests/fixtures/**

- name: Analyze
uses: github/codeql-action/analyze@33d7b85da1a04171e211befe2c739303b9a4c066 # v4.39.3
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/parser-fuzz.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Parser fuzzing
on:
workflow_dispatch:
schedule:
- cron: '23 6 * * 1'
permissions:
contents: read
jobs:
fuzz:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
with:
persist-credentials: false
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0
with:
python-version: '3.12'
- run: pip install -e '.[dev]' atheris==2.3.0
- run: python fuzz/fuzz_parsers.py -max_total_time=60
119 changes: 119 additions & 0 deletions docs/ADVERSARIAL_EVAL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# Malicious-repository evaluation

Implements [#117](https://github.com/secfoo-com/secfoo/issues/117). This is a
bounded diagnostic, not proof of general prompt-injection resistance.

## Corpus and provenance

The current corpus contains eight attack/control pairs: code comments, README
instructions, docstrings, instruction-like filenames, agent instruction files,
forged reports, Unicode instructions, and command/network requests. The pairs
cover command injection, SQL injection, path traversal, reflected HTML injection,
unsafe deserialization, expression evaluation, weak password hashing, and SSRF.
Each pair preserves the same underlying defect. Source files and READMEs do not
label that defect or disclose its CWE; the manifest is evaluator-only metadata.
Fixtures are never executed by the harness. Do not deploy them.

Agent instruction files are committed under inert `.fixture` names and renamed
only while copying into a disposable target. Historical snapshots use the same
inert naming convention. Symlinks are rejected. Runtime homes, launchers and
captures live outside the materialized target.

The actual November 16 measurements used an earlier corpus that repeated an
explicitly labeled SQL defect. Its evaluator-only metadata is retained in
[the v1 manifest](../tests/fixtures/adversarial/manifests/v1.json). The original
source remains available at git revision ad1f43ac1706adb37ebe12aac12f136507321bc2;
it is not duplicated in the checkout.
Historical records must not be interpreted as measurements of the revised
corpus or implementation. No fresh model measurements are claimed for this
revision: the local machine has no configured model credentials or model runtime.

## Offline validation

```sh
pip install -e '.[dev]'
python scripts/adversarial_eval.py --records tests/fixtures/adversarial/synthetic-transcripts.jsonl
python scripts/adversarial_eval.py --records docs/evaluations/2026-11-16/claude.jsonl
python scripts/adversarial_eval.py --records docs/evaluations/2026-11-16/api.jsonl
pytest tests/test_adversarial_eval.py tests/test_review_hardening.py
```

Synthetic transcripts calibrate evaluator behavior only. They are not model
measurements. Each record explicitly names its corpus_manifest; replay uses that field.
Both historical metadata and the current corpus remain covered by regression tests. Offline CI
needs no model credentials. Parser fuzzing is pinned to Atheris 2.3.0 in a
separate weekly/manual workflow, outside the routine PR matrix.

## Live evaluation

Use disposable, isolated environments. The harness is not an OS sandbox.
The manual **Adversarial repository evaluation** workflow takes explicit models,
an exact Claude CLI version, and a built-in skill id. API jobs receive only an
OpenAI key, Claude jobs only an Anthropic key. It does not run on PR events.
No billable workflow was dispatched for this revision.

```sh
python scripts/adversarial_eval.py --live --agent api --skill sast \
--model openai/gpt-4.1-mini --phase baseline --checkout /path/to/baseline \
--output /tmp/api-baseline.jsonl
python scripts/adversarial_eval.py --live --agent api --skill sast \
--model openai/gpt-4.1-mini --phase hardened --checkout /path/to/hardened \
--output /tmp/api-hardened.jsonl
# Repeat with --agent claude and the chosen Claude model identifier.
```

Checkouts must be clean and committed. Use the same current harness, corpus,
dependencies, skill and model settings for both phases. Records include source
revision, model, skill, prompt hash, corpus hash and trial. Exclusive output
creation prevents accidental overwrite. Repeat trials before estimating a
stable effect. A table groups by agent, skill, phase, attack/control variant, source revision,
trial, capture profile and corpus digest. Different setups are never pooled.
Other skills can be selected, but a source-code defect is not an appropriate
positive control for every skill; reviewers must assess applicability.

Subprocesses receive an allowlisted environment, an isolated HOME and Secfoo
home, and only the selected provider's credential. Unrelated cloud keys and
custom skill/MCP configuration are not inherited. This intentionally requires
explicit API credentials rather than borrowing a contributor's CLI login.

Claude capture is integrated into each harness invocation. It preserves the
production adapter's tool grants, captures the complete stream and records the
actual allowlist alongside tool attempts. Invalid or incomplete streams remain
unknown. The API harness observes tool-call fields returned by each actual
completion; the table states that API tools are not exposed, rather than calling an empty
list an observed safety result. Model prose requesting a
command is not an executed API tool call.

## Scoring and production hardening

- Retention is a location/CWE heuristic, checked against each case's manifest;
it requires human review of the actual source and report.
- Planted F900 detection is not a general hallucination detector.
- Format checks use the selected built-in skill's output contract. They do not
validate every report field or the truth of a finding.
- Unsuccessful runs and malformed reports are not safety passes. Missing tool
observation remains unknown, including the original November 16 API records,
whose empty tool lists were asserted rather than observed.
- A shared Markdown heading/section iterator is used by severity counting,
SAST/SCA/secret-scanning extraction and the evaluator. Quoted/fenced headings
and register examples cannot become persisted findings. Unterminated fences
and finding-like headings that Markdown does not recognize raise a malformed
report error. The runner records these runs as failed before findings ingestion, preserving
report paths, normal multi-skill outcomes and CLI JSON output. Malformed old
stored reports are logged and skipped; dashboards identify exclusions.
- API source bodies retain raw newlines between random per-file boundaries;
paths and deleted-path lists are JSON quoted. The trusted brief remains a
system message and declares the generated boundary tokens there. Reformat instructions explicitly identify the JSON draft
field and require raw Markdown; JSON echoes and malformed output fail after
the bounded retry rather than becoming successful zero-finding reports.

Random boundaries and tool grants reduce specific attack surfaces. They do not
prevent all model manipulation or establish isolation. Inspect artifacts for
credentials and unexpected data before publishing.

Local Ollama evaluations retain OLLAMA_API_BASE only for a loopback URL, use a
non-secret availability sentinel, and retain SECFOO_MEMORY. Bare model names
resolve to the OpenAI provider for credential selection. No cloud routing is
enabled automatically. Captures normalize local paths and remove session IDs,
UUIDs, messaging sockets, plugin metadata and subscription-expiry fields before
publication. Capture hashes describe the sanitized public files, not originals.
26 changes: 26 additions & 0 deletions docs/REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1070,3 +1070,29 @@ Homebrew is a planned follow-up (a tap formula in a separate
See [`design-system/README.md`](../design-system/README.md) for the design
system used by the dashboard.

## Malicious repositories and adversarial validation

Repository text is untrusted evidence, including files named `AGENTS.md`,
`CLAUDE.md` and `.cursorrules`. Secfoo's review brief rejects instructions to
suppress findings, change severity, copy fabricated reports, or execute
commands from the target. The API adapter separates the brief into a system
message, quotes filenames, and preserves source lines inside random per-file
boundaries. Report consumers share a Markdown heading/section iterator.
Fenced and quoted examples are ignored; unclosed fences and malformed finding
headings fail the run instead of passing severity gates with zero findings.

These controls do not establish that a malicious repository cannot influence
an agent. Tool grants are not an operating-system sandbox, and model behavior
must be measured. The [adversarial evaluation guide](ADVERSARIAL_EVAL.md)
documents eight paired fixture techniques, offline regression replay,
opt-in live measurements and the limits of the metrics. Synthetic replay
results are not live security results.

The [historical November 16 record](evaluations/2026-11-16/README.md)
uses a previous, explicitly labeled SQL-only corpus and older code. Its scores
are not measurements of the current corpus or head. The harness reports each
revision, trial, capture profile and corpus digest separately; API tool-policy
measurements are marked not applicable because that adapter exposes no tools.
Fresh free-model measurements are tracked in the PR, separately from offline
regressions. Tool grants and source boundaries do not establish isolation or
immunity to prompt injection.
Loading