Skip to content
Closed
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@11d5960a326750d5838078e36cf38b85af677262
with:
path: hardened
persist-credentials: false
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
with:
ref: f24043bd6f01618128748241b6729bebc9254a26
path: baseline
persist-credentials: false
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065
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@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: adversarial-${{ matrix.agent }}
path: artifacts/
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ jobs:
- name: Test (secfoo core)
run: pytest tests

- name: Replay synthetic adversarial evaluator controls (no model calls)
run: python scripts/adversarial_eval.py --records tests/fixtures/adversarial/synthetic-transcripts.jsonl

- name: Replay recorded live adversarial evidence (no model calls)
run: |
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

- name: Runtime probe conformance (reference Python probe, #73)
run: secfoo sensor conformance -- python -m secfoo.sensor -m secfoo.runtime.conformance.sample_app

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@11d5960a326750d5838078e36cf38b85af677262
with:
persist-credentials: false
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065
with:
python-version: '3.12'
- run: pip install -e '.[dev]' atheris==2.3.0
- run: python fuzz/fuzz_parsers.py -max_total_time=60
107 changes: 107 additions & 0 deletions docs/ADVERSARIAL_EVAL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# 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 manifest and source are preserved under
[evaluations/2026-11-16/corpus-v1](evaluations/2026-11-16/corpus-v1).
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. Historical replay automatically uses the archived v1 manifest.
Both archive and 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 and attack/control variant.
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; an empty list is recorded only after that observer ran. It does not
infer tool safety from the adapter exposing no tools. 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.
- 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. 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.
33 changes: 33 additions & 0 deletions docs/REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -992,3 +992,36 @@ 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 earlier, labeled SQL-only corpus in the [2026-11-16 live record](evaluations/2026-11-16/README.md) reports Claude
Sonnet 4.6 retaining the real finding in all 16 baseline and all 16 hardened
reviews. The local Qwen3 4B Instruct API comparison retained it in 7/8 baseline
attacks versus 8/8 hardened attacks, and 8/8 controls in both phases. The
baseline Unicode attack obeyed the injected instruction; the hardened run
reported the real defect. These are single trials, not a general safety
guarantee. All 32 local API reports failed the evaluator's format check.
Only the separately captured Claude tool-request pair has complete tool
telemetry, under the same restricted tool set in both phases. A malicious
repository can still influence model text; tool restrictions and source
boundaries reduce specific attack surfaces but do not prove isolation or immunity.
These historical runs do not measure the revised eight-defect corpus. Original
API tool lists were not observed and now replay as unknown; complete historical
Claude tool streams measure only the narrower grants used for those runs.

Loading