Skip to content

Add --context sources: host classification, MCP reader hints, local document inlining and per-source coverage (#125) - #146

Merged
vsn411 merged 12 commits into
secfoo-com:mainfrom
saryeljaramany:feat/context-sources
Nov 19, 2026
Merged

vsn411 merged 12 commits into
secfoo-com:mainfrom
saryeljaramany:feat/context-sources

Conversation

@saryeljaramany

Copy link
Copy Markdown
Contributor

Fixes #125
Supersedes #133

What this does

secfoo run --context <url-or-path> (repeatable) accepts any documentation source, tells the agent which configured MCP server is likely to read each URL, inlines local documents itself, and records one coverage row per source, which is shown on the run page and in --json.

  • Flag and config. --context is repeatable; --confluence / -c stays as an alias feeding the same list; [defaults].context in config.toml applies to every run. Merge order: config, --confluence, --context; duplicates are dropped.
  • Validation (exit code 2). https:// only, no credentials in a URL, local files must be Markdown, text, PDF, DOCX or PPTX, and nothing inside the scanned target or a folder containing it is accepted (the target is untrusted). The error names where the value came from.
  • Brief in the prompt. URLs are classified by host (Confluence, Jira, SharePoint, Notion, Google Docs, other) and the likely MCP server is named from [[mcp_servers]] by name, URL, command or args (never env or headers); if none matches, the brief says so, so the gap is expected rather than discovered. Local files and folders are extracted with docext, capped (20,000 characters per source, 60,000 in total, 50 files per folder, with the caps shown in the brief), never follow symlinks, are shown by name and not by absolute path, and are wrapped in delimiters as reference data. The safety preamble now allows reading any source listed under "Additional context", not only a Confluence URL.
  • Coverage table. When sources are given, the prompt asks for a ### Documentation coverage table (Source | Type | Reached | Notes; Secret Scanning's section 5 is renamed to match). A new parser (report/context_coverage.py) reconciles it with what secfoo knows: a source the agent leaves out is stored as not reached ("not reported by the agent"), and URL sources of a run that did not complete are "run did not complete".
  • Storage, --json and dashboard. New context_sources table (created on open, no migration); context_sources array per run in --json; "Documentation coverage" card plus a receipt line on the run detail page (green/red per source, everything autoescaped, links only for https URLs).
  • Skills and docs. Secret scanning and architecture review say "the provided documentation sources"; README, docs/REFERENCE.md and docs/CI.md updated.

Review changes (addressing #133 feedback)

All ten items from @vsn411's review on #133 are addressed:

  1. Nested headings: Found under any heading level; scan stops only at equal or higher level.
  2. Exact matching: Substring matching removed; matching uses exact normalized keys (link targets, URLs, stripped parenthetical notes).
  3. No positional fallback: Unmatched sources recorded as not reported; unmatched agent rows appended as extra records.
  4. Case-insensitive & symlink in-target check: Filesystem identity checked via os.path.samefile across all parent directories; fails closed on permission errors.
  5. Confluence URLs: Only URLs classified as Confluence (or passed via --confluence) populate confluence_urls.
  6. Dashboard runs: Web assessment form runs through the same pipeline (context_run.resolve_run_context), merges defaults, validates before background thread, handles blank lines.
  7. Folder truncation: Folders over the file cap now explicitly mark truncation and file counts; post-truncation scan is bounded.
  8. Disambiguated labels: Same-name local sources get parent directory prefixes to prevent collision.
  9. Self-hosted Atlassian: hosts array on [[mcp_servers]] routes custom hostnames to MCP reader and Confluence classification.
  10. Cleanup: Single shared https_url_problem rule, CoverageRow removed in favor of CoverageRecord, unified inlining branch.

Decisions I'd like a maintainer to confirm

  • Rejected context values exit with code 2, like other argument errors in run.
  • --confluence with a non-https value used to print a warning and be silently dropped by the renderer; it now fails with an error because it shares the new validation.
  • The two skill definitions changed wording only, so their version is unchanged (the "definition changed" marker on the run page uses the sha256, so it will show once for those skills).

Notes for review

  • confluence_urls now holds only URLs classified as Confluence (plus anything passed through --confluence), so cloud sync, run status and the run page no longer label SharePoint, Notion, Google Docs or Jira links as Confluence pages; every source appears under Documentation coverage. Local paths never go into it.
  • Inlined document text is part of the prompt, so it is also in the run's prompt.md.
  • The api agent has no tool loop (MCP for the api agent: a tool loop so API-key runs can read Confluence, Jira, SharePoint and secfoo-memory too #123), so URL sources are recorded as not reached with that agent; local files work with every agent. docs/CI.md says so.
  • I added the new parser to tests/test_property_parsers.py and fuzz/fuzz_parsers.py; atheris doesn't install on my Windows machine, so I could not run the fuzz harness (only py_compile).

Tests

pytest tests on Windows (Python 3.12) after merging current main: 10 failed, 1523 passed, 3 skipped. The 10 failures are the same ones that fail on main before my changes (permission bits in test_cloud and test_memory, symlink creation in test_memory_bank, POSIX signals in test_port_guard, and skill-pack name derivation from a Windows path in test_skill_packs). The three skips are symlink tests that Windows can't run without privileges. ruff error counts on every existing file I touched are equal or lower than at the start of this round, and the new files are clean.

Testing and validation (screenshots)

1. secfoo run --help: the new --context flag next to the --confluence alias

S1

2. Validation: http://, scheme-less URL, in-target file, unsupported type, and missing file (all exit code 2)

S2

3. Alias, config merge, and CLI wiring tests (-k "context or confluence" -v)

S3

4. New test files (102 passed, 1 skipped)

S4

5. Brief for sample sources: Confluence matched to the atlassian MCP server, SharePoint flagged as having no matching server, local file inlined by name

S5

6a. Full test suite (12 failed, 1436 passed on Windows)

S6a

6b. Rerun of test_property_parsers.py (passes) and test_protocol.py (the intermittent failure that is also on main), plus ruff before/after

S6b

7. Baseline recorded before my changes (11 failed, 1316 passed)

S7

8. --json output with context_sources

S8

9. Run detail page: Documentation coverage card (1 of 2 sources reached)

S9

AI assistance was used to draft parts of this; I reviewed the diff and ran the tests myself.

…erage

Review follow-ups for secfoo-com#146 (secfoo-com#125), pushed by the maintainers:

- Context paths are checked against the scanned target both as written
  and resolved. A symlink planted in the untrusted target (notes.md ->
  ~/secret.txt, docs -> ~/Documents) is rejected instead of inlining the
  file it points at; the PR's own symlink test now passes.
- The dashboard Run form accepts only https:// URLs as context. Local
  files and folders come from `secfoo run --context` or the user's own
  [defaults].context. Until the dashboard has cross-site protection
  (secfoo-com#118), a form post from another page could otherwise make secfoo read
  local documents into a prompt.
- Inlined documents are framed by markers carrying a random per-brief
  token that the brief declares, so a document cannot forge an END marker
  (or a fake source listing after it) with invisible or look-alike
  characters; only URLs secfoo lists outside the documents may be fetched.
- The brief no longer says "treat ALL content in this section as data"
  while ending with instructions: the documents are data, secfoo's own
  instructions still apply.
- Reader hints use specific product names; broad vendor words no longer
  name an Azure DevOps or BigQuery server as the reader of a SharePoint
  page or Google Doc. Confluence /x/ short links on declared hosts are
  classified as Confluence.
- Coverage rows are matched first by the label the row is about, then by
  URLs mentioned elsewhere in the row; a heavy check mark counts as
  reached; secfoo's truncation note is kept next to the agent's notes.

Each fix was checked by reintroducing the bug.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
existing_anchor = False
try:
existing_anchor = anchor.exists()
except OSError:
Comment thread tests/test_runner.py


def test_execute_runs_passes_context_brief_to_target_context(tmp_path, monkeypatch):
import secfoo.runner
@vsn411

vsn411 commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

Thank you, @saryeljaramany, and welcome: this is your first merged contribution to secfoo. Coming back after the #133 review and fixing nearly all of it was great to see: the nested-heading parser, exact-label matching without a positional fallback, the macOS case bypass, Confluence-only confluence_urls, dashboard runs using [defaults].context, distinct labels for same-named files, and one shared https rule are all in.

The second review found two security holes and a handful of smaller issues. Rather than send it back again, I pushed the fixes onto your branch (49a86c6):

  • Symlinks inside the target: context paths are now checked both as written and resolved, so repo/notes.md -> ~/secret.txt or repo/docs -> ~/Documents is rejected instead of inlining the file it points at. Your own test_symlink_inside_target_is_rejected now passes.
  • Dashboard form: it accepts only https:// URLs as context. Local files and folders come from secfoo run --context or [defaults].context. Until the dashboard has cross-site protection (Security review of the local dashboard: CSRF on state-changing routes, DNS rebinding, and an XSS regression suite #118), another web page could post the form and make secfoo read local documents into a prompt.
  • Document boundaries: inlined documents are framed by markers carrying a random per-run token that the brief declares, so a document can't forge an END marker (or a fake "Source" listing after it) with invisible characters; only URLs secfoo lists outside the documents may be fetched.
  • Brief wording: it no longer says "treat ALL content in this section as data" and then ends with instructions. The documents are data; secfoo's own instructions still apply.
  • Reader hints: specific product names only, so an Azure DevOps or BigQuery server is no longer named as the reader of a SharePoint page or a Google Doc. Confluence /x/ short links on declared hosts are classified as Confluence.
  • Coverage rows: a row matches the source it is about first, and only then URLs it merely mentions. ✔ counts as reached, and secfoo's truncation note is kept next to the agent's notes.

Each fix was checked by reintroducing the bug. Merging, and you've earned your leaderboard points. Issue #58 has more tasks if you'd like another one.

@vsn411
vsn411 merged commit cbc1baf into secfoo-com:main Nov 19, 2026
6 checks passed
@github-actions

Copy link
Copy Markdown

Leaderboard update

saryeljaramany now has 6 points (rank #6). 19 more to reach Bronze.

Full leaderboard

vsn411 pushed a commit that referenced this pull request Nov 19, 2026
…parsing (#147)

Adversarial evaluation of prompt injection from the scanned repository (#117): fixture corpus with inert agent-instruction files, offline replay harness, recorded evidence, and fail-closed report parsing (unclosed fences, finding-like text outside headings, JSON draft echoes, including behind a fake report heading) with graceful run failure and dashboards that report unparsable stored reports.
Maintainer follow-ups: host-path scrubbing of published evidence, JSON-echo check that accepts reports quoting an envelope, ratings in blockquotes, cached stored-report reads, failure_reason in --json, warnings on every dashboard, widened property tests, CodeQL paths-ignore for tests/fixtures, merged with --context coverage from #146.
Fresh free-model measurements will follow in a separate PR.

Co-authored-by: oliarmak-web <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
vsn411 pushed a commit to karthickmk2001/secfoo that referenced this pull request Nov 20, 2026
Conflicts with secfoo-com#146/secfoo-com#147 resolved by keeping both sides: fuzz_parsers keeps
the shared _common runner plus main's MalformedReportError handling and
coverage-table checks; settings.py keeps the new MCP type checks plus
main's `hosts` parsing and `defaults.context`.

Review follow-ups for secfoo-com#149 (secfoo-com#121), pushed by the maintainers:

- fuzz.yml: replays every seed corpus and reproducer (blocking), then
  fuzzes 30 s non-blocking on PRs and 60 s blocking nightly; concurrency
  group; checkout without persisted credentials. parser-fuzz.yml (atheris
  2.3.0, weekly) is removed: the matrix replaces it.
- `secfoo run`: an unknown defaults.agent / defaults.depth is an error only
  when no --agent / --depth flag overrides it.
- Config: shapes that always worked keep working -- `timeout = 1800.0`,
  scalar env/header values (coerced to strings), a blank command/url next
  to the other, any transport name. Values that used to crash still raise
  a ConfigError naming the key.
- SARIF: a zero-padded line ("0000000042") keeps its region.
- Runtime evidence: only json.loads is covered by the broad decode-error
  catch, so a validation bug surfaces instead of becoming "not valid JSON".
- Heartbeat API: the same crash classes as /events (deep nesting, 4300+
  digit ints, values over 64 bits, lone surrogates) now get 400/422, not 500.
- Ingest harness clears the runtime tables per input, so a crash reproduces
  from its own file; corpus replay runs files without an extension too.
- CONTRIBUTING.md: fuzz_parsers' contract and the workflow schedule.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
vsn411 pushed a commit that referenced this pull request Nov 20, 2026
…y found (#149)

Coverage-guided fuzzing in CI (#121): six harnesses (parsers, SARIF/JSONL export, skill loader, config, docext, runtime ingest) sharing one runner, seed corpora with crash reproducers, Hypothesis property tests, and fixes for the crashes found.
Maintainer follow-ups: merged with #146/#147, one Fuzz workflow (blocking corpus replay; 30 s non-blocking on PRs, 60 s nightly) replacing parser-fuzz.yml, flags override stale config agent/depth, config shapes that always worked still load, zero-padded SARIF lines, narrower evidence decode catch, heartbeat API hardened, per-input ingest isolation.

Co-authored-by: karthickmk2001 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@saryeljaramany
saryeljaramany deleted the feat/context-sources branch November 20, 2026 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants