Skip to content

Personal AI, On Personal Devices

Python

feat(scan): add application data-boundary diagnostic mode (#621)

Matéo H. Petel8145597052ca
diff --git a/docs/user-guide/data-boundary-scan.md b/docs/user-guide/data-boundary-scan.md
new file mode 100644
index 00000000..60a17fa6
--- /dev/null
+++ b/docs/user-guide/data-boundary-scan.md
@@ -0,0 +1,174 @@
+# Data-boundary scan
+
+`jarvis scan --data-boundaries` reports application-level data boundaries in the
+current OpenJarvis configuration. It complements the existing host/environment
+scan, which checks OS posture such as disk encryption, cloud-sync agents, remote
+access tools, and exposed engine ports.
+
+The data-boundary scan is a configuration diagnostic. It is not a vulnerability
+scanner, a legal privacy assessment, a network monitor, or an OAuth-scope audit.
+
+## Run the scan
+
+```bash
+jarvis scan --data-boundaries
+jarvis scan --data-boundaries --json
+jarvis scan --data-boundaries --json --show-paths
+jarvis scan --data-boundaries --strict
+```
+
+`--strict` exits with status code `1` when the report contains either a `fail`
+or a `warn` finding. Use it when CI or pre-demo checks need to enforce a
+conservative local-only posture.
+
+Without `--strict`, the command always exits `0` even when fail or warn findings
+are present. This is useful for exploratory review.
+
+On a fresh `jarvis init` configuration, common warn findings include
+`server.host = "0.0.0.0"` and `telemetry.enabled = true`. Running
+`jarvis scan --data-boundaries --strict` after init therefore exits `1` until
+those defaults are tightened.
+
+Absolute paths and connector file basenames are redacted by default so JSON
+reports can be pasted into issues without revealing local usernames, mount
+points, or account labels. Use `--show-paths` only for local debugging.
+
+## What it checks
+
+The scan inspects configuration values, environment-variable presence, and the
+existence of known local runtime files. It does not read private content from
+memory databases, trace databases, connector credentials, prompt files, logs, or
+OAuth token files.
+
+The current checks cover:
+
+- cloud-capable model provider, engine, and default model settings
+- local memory context injection combined with cloud-capable inference
+- traces, telemetry, learning, training, and spec-search settings
+- automatic memory service (`tools.storage.enabled` / `[memory].enabled`)
+- deep research engine and model settings
+- security bypass flags when cloud inference is configured
+- unset `security.profile` (informational)
+- web search, browser, local file, shell, code, knowledge chunk scanning, and MCP tool surfaces
+- local knowledge.db composition with cloud-capable Deep Research targets
+- server binding and unauthenticated A2A exposure
+- channel enablement, channel credential fields, and channel credential env vars
+- skills, skill auto-sync, digest sources, and cloud speech/TTS backends such as Cartesia
+- local stores such as `knowledge.db`, `credentials.toml`, `memory.db`, `traces.db`,
+ `telemetry.db`, `scheduler.db`, embeddings, skill index, `.vault_key`, and memory files
+- connector credential files under `connectors/*.json`, without reading them
+- API-key and other runtime credential environment variables (presence only)
+- a scope note for frontend credential storage when cloud/API-key surfaces exist
+
+Configured database paths (for example `traces.db_path` or `memory.db_path`)
+are resolved from config when set, not only the default locations under the
+OpenJarvis home directory.
+
+Static Deep Research targeting uses configuration only (no request overrides):
+`deep_research.engine` or `engine.default`, and `deep_research.model` or
+`server.model` or `intelligence.default_model`.
+
+Model identifiers that contain vendor names (for example `deepseek-r1` or
+`openai/gpt-oss`) are not treated as cloud-bound when their effective engine is
+explicitly local, such as Ollama.
+
+## Status levels
+
+| Status | Meaning |
+| --- | --- |
+| `fail` | A configuration composition is likely incompatible with strict local-only use. |
+| `warn` | A configured surface may send data outside the local runtime or persist sensitive data. |
+| `info` | A relevant setting or local store exists, with no immediate fail or warn condition. |
+
+The command reports potential data paths. It does not prove that a path has been
+used during a specific run.
+
+JSON output includes `"schema_version": 1` for stable downstream parsing.
+
+## Strict local-only checklist
+
+For a conservative local-only setup, review these settings:
+
+```toml
+[analytics]
+enabled = false
+
+[traces]
+enabled = false
+
+[telemetry]
+enabled = false
+
+[agent]
+context_from_memory = false
+
+[intelligence]
+provider = ""
+preferred_engine = ""
+default_model = "" # local model name only
+
+[engine]
+default = "ollama" # or another local engine
+
+[tools]
+enabled = ""
+
+[tools.storage]
+enabled = false
+
+[tools.mcp]
+enabled = false
+servers = ""
+
+[channel]
+enabled = false
+
+[learning]
+enabled = false
+auto_update = false
+training_enabled = false
+
+[learning.spec_search]
+enabled = false
+
+[server]
+host = "127.0.0.1"
+
+[security]
+profile = "personal"
+
+[a2a]
+enabled = false
+```
+
+Also unset cloud and channel credentials from the process environment when they
+are not needed.
+
+## Scope and non-goals
+
+The scan intentionally avoids reading private data. In particular, it does not:
+
+- read connector JSON contents or OAuth scopes
+- inspect browser `localStorage` or Tauri secure storage
+- inspect frontend credential storage directly
+- inspect installed skill source code
+- intercept runtime network traffic
+- classify provider retention or training policies
+- prove that a configured path was used at runtime
+
+Frontend credential storage is tracked separately from this CLI diagnostic. If a
+cloud/API-key surface is present, the scan emits an informational scope note so
+users know that browser/Tauri credential storage must be reviewed separately.
+
+## Configuration resolution
+
+The scan follows the same explicit configuration override used by the runtime:
+if `OPENJARVIS_CONFIG` is set, that file is audited. Otherwise the scan uses
+the default OpenJarvis config path under the resolved OpenJarvis home. If the
+home directory cannot be resolved, the command reports a `config-root-error`
+finding instead of crashing.
+
+## See also
+
+- [Security](security.md) — three-layer security model (host scan, config scan, BoundaryGuard)
+- [Configuration](../getting-started/configuration.md) — full config reference
diff --git a/docs/user-guide/security.md b/docs/user-guide/security.md
index ae4d8815..af8b190c 100644
--- a/docs/user-guide/security.md
+++ b/docs/user-guide/security.md
@@ -2,6 +2,20 @@
OpenJarvis includes a security layer that scans prompts and model outputs for secrets, personally identifiable information (PII), and sensitive file paths. The system is designed to be composable: scanners run as a pipeline, and the `GuardrailsEngine` wrapper drops in front of any inference backend without changing how the rest of your code works.
+## Three layers of security review
+
+OpenJarvis separates host posture, application data boundaries, and runtime prompt guardrails:
+
+| Layer | Command / component | What it checks |
+| --- | --- | --- |
+| Host scan | `jarvis scan` | Disk encryption, cloud-sync agents, exposed engine ports, remote-access tools |
+| Data-boundary scan | `jarvis scan --data-boundaries` | Configured inference, memory, traces, channels, tools, and local stores |
+| Runtime guardrails | `GuardrailsEngine` / BoundaryGuard | Secrets, PII, and file-policy violations in live prompts and outputs |
+
+Use the host scan before storing sensitive data on the machine. Use the data-boundary scan to verify whether your `config.toml` is local-only, cloud-capable, or mixed. Use BoundaryGuard during inference when you need live redaction or blocking.
+
+See [Data Boundary Scan](data-boundary-scan.md) for the application config diagnostic and [BoundaryGuard](#guardrailsengine) below for runtime scanning.
+
---
## Overview
@@ -446,8 +460,15 @@ guarded = GuardrailsEngine(
---
+## Data boundary scan
+
+See [Data Boundary Scan](data-boundary-scan.md) for the application config diagnostic (`jarvis scan --data-boundaries`).
+
+---
+
## See Also
+- [Data Boundary Scan](data-boundary-scan.md) — application config and local-store diagnostic (`jarvis scan --data-boundaries`)
- [Architecture: Security](../architecture/security.md) — pipeline design, event flow, and file policy integration
- [API Reference: Security](../api-reference/openjarvis/security/index.md) — full class and function signatures
- [Tools](tools.md) — how `FileReadTool` uses file policy
diff --git a/mkdocs.yml b/mkdocs.yml
index f1f2753d..68988f44 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -198,6 +198,7 @@ nav:
- Benchmarks: user-guide/benchmarks.md
- System Access: user-guide/system-access.md
- Security: user-guide/security.md
+ - Data Boundary Scan: user-guide/data-boundary-scan.md
- LLM-guided spec search: user-guide/llm-guided-spec-search.md
- Leaderboard: leaderboard.md
- Roadmap: development/roadmap.md
diff --git a/src/openjarvis/__init__.py b/src/openjarvis/__init__.py
index 8339f46a..2b87f32f 100644
--- a/src/openjarvis/__init__.py
+++ b/src/openjarvis/__init__.py
@@ -4,8 +4,10 @@ from __future__ import annotations
from importlib.metadata import PackageNotFoundError
from importlib.metadata import version as _pkg_version
+from typing import TYPE_CHECKING, Any
-from openjarvis.sdk import Jarvis, JarvisSystem, MemoryHandle, SystemBuilder
+if TYPE_CHECKING:
+ from openjarvis.sdk import Jarvis, JarvisSystem, MemoryHandle, SystemBuilder
try:
__version__ = _pkg_version("openjarvis")
@@ -13,3 +15,21 @@ except PackageNotFoundError: # pragma: no cover — uninstalled source tree
__version__ = "0.0.0+unknown"
__all__ = ["Jarvis", "JarvisSystem", "MemoryHandle", "SystemBuilder", "__version__"]
+
+_SDK_EXPORTS = {"Jarvis", "JarvisSystem", "MemoryHandle", "SystemBuilder"}
+
+
+def __getattr__(name: str) -> Any:
+ """Load SDK exports lazily so lightweight CLI diagnostics can start safely."""
+ if name not in _SDK_EXPORTS:
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
+
+ from openjarvis import sdk
+
+ value = getattr(sdk, name)
+ globals()[name] = value
+ return value
+
+
+def __dir__() -> list[str]:
+ return sorted(set(globals()) | _SDK_EXPORTS)
diff --git a/src/openjarvis/cli/__init__.py b/src/openjarvis/cli/__init__.py
index 40c72491..e3d9a395 100644
--- a/src/openjarvis/cli/__init__.py
+++ b/src/openjarvis/cli/__init__.py
@@ -2,45 +2,36 @@
from __future__ import annotations
+import sys
+
import click
import openjarvis
-from openjarvis.cli._bootstrap import bootstrap_cmd
-from openjarvis.cli.add_cmd import add
-from openjarvis.cli.agent_cmd import agent
-from openjarvis.cli.ask import ask
-from openjarvis.cli.bench_cmd import bench
-from openjarvis.cli.channel_cmd import channel
-from openjarvis.cli.channels_cmd import channels
-from openjarvis.cli.chat_cmd import chat
-from openjarvis.cli.compose_cmd import compose
-from openjarvis.cli.config_cmd import config
-from openjarvis.cli.connect_cmd import connect
-from openjarvis.cli.daemon_cmd import restart, start, status, stop
-from openjarvis.cli.digest_cmd import digest
-from openjarvis.cli.doctor_cmd import doctor
-from openjarvis.cli.eval_cmd import eval_group
-from openjarvis.cli.feedback_cmd import feedback_group
-from openjarvis.cli.gateway_cmd import gateway
-from openjarvis.cli.host_cmd import host
-from openjarvis.cli.init_cmd import init
-from openjarvis.cli.memory_cmd import memory
-from openjarvis.cli.mine_cmd import mine
-from openjarvis.cli.model import model
-from openjarvis.cli.operators_cmd import operators
-from openjarvis.cli.optimize_cmd import optimize_group
-from openjarvis.cli.pearl_cmd import pearl
-from openjarvis.cli.quickstart_cmd import quickstart
-from openjarvis.cli.registry_cmd import registry
from openjarvis.cli.scan_cmd import scan
-from openjarvis.cli.scheduler_cmd import scheduler
-from openjarvis.cli.self_update_cmd import self_update
-from openjarvis.cli.serve import serve
-from openjarvis.cli.skill_cmd import skill
-from openjarvis.cli.telemetry_cmd import telemetry
-from openjarvis.cli.tool_cmd import tool
-from openjarvis.cli.vault_cmd import vault
-from openjarvis.cli.workflow_cmd import workflow
+
+
+def _invoked_command(argv: list[str]) -> str:
+ """Return the first positional CLI token after global flags."""
+ for arg in argv:
+ if arg.startswith("-"):
+ continue
+ return arg
+ return ""
+
+
+# A data-boundary scan must be able to diagnose an invalid OPENJARVIS_HOME.
+# Importing the rest of the CLI eagerly would import core.config and resolve that
+# path before the scan can turn the failure into a finding.
+_DATA_BOUNDARY_BOOTSTRAP = (
+ _invoked_command(sys.argv[1:]) == "scan" and "--data-boundaries" in sys.argv[1:]
+)
+
+
+def _should_skip_update_check(ctx: click.Context, argv: list[str]) -> bool:
+ """Return true for commands whose diagnostics should remain local-only."""
+ if "--research" in argv:
+ return True
+ return ctx.invoked_subcommand == "scan" and "--data-boundaries" in argv
@click.group(
@@ -63,11 +54,13 @@ def cli(ctx: click.Context, verbose: bool, quiet: bool) -> None:
# Check for updates on interactive commands. The banner is noise in
# demo recordings of ``jarvis ask --research``, so skip it whenever
# the research flag is in argv (cheap argv sniff — Click hasn't
- # parsed the subcommand's args yet at this point).
+ # parsed the subcommand's args yet at this point). Also skip
+ # ``jarvis scan --data-boundaries`` because it is intended to be a
+ # local application-data diagnostic with no outbound calls.
import sys
- research_mode_active = "--research" in sys.argv
- if not quiet and ctx.invoked_subcommand and not research_mode_active:
+ skip_update_check = _should_skip_update_check(ctx, sys.argv[1:])
+ if not quiet and ctx.invoked_subcommand and not skip_update_check:
import threading
from openjarvis.cli._version_check import check_for_updates
@@ -91,74 +84,111 @@ def cli(ctx: click.Context, verbose: bool, quiet: bool) -> None:
check_and_route(ctx)
-cli.add_command(init, "init")
-cli.add_command(ask, "ask")
-cli.add_command(chat, "chat")
-cli.add_command(serve, "serve")
-cli.add_command(model, "model")
-cli.add_command(memory, "memory")
-cli.add_command(mine, "mine")
-cli.add_command(pearl, "pearl")
-cli.add_command(telemetry, "telemetry")
-cli.add_command(bench, "bench")
-cli.add_command(channel, "channel")
-cli.add_command(channels, "channels")
-cli.add_command(scheduler, "scheduler")
-cli.add_command(doctor, "doctor")
-cli.add_command(agent, "agents")
-cli.add_command(workflow, "workflow")
-cli.add_command(skill, "skill")
-cli.add_command(start, "start")
-cli.add_command(stop, "stop")
-cli.add_command(restart, "restart")
-cli.add_command(status, "status")
-cli.add_command(vault, "vault")
-cli.add_command(add, "add")
-cli.add_command(operators, "operators")
-cli.add_command(eval_group, "eval")
-cli.add_command(host, "host")
-cli.add_command(quickstart, "quickstart")
-cli.add_command(optimize_group, "optimize")
-cli.add_command(feedback_group, "feedback")
-cli.add_command(compose, "compose")
-cli.add_command(gateway, "gateway")
-cli.add_command(tool, "tool")
-cli.add_command(registry, "registry")
-cli.add_command(config, "config")
cli.add_command(scan, "scan")
-cli.add_command(connect, "connect")
-cli.add_command(digest, "digest")
-# deep-research setup pulls the ingestion pipeline (embeddings/numpy). Guard it
-# so a broken or slow numpy on Windows — which can raise at IMPORT time, not
-# just ImportError (#404) — can never take down the whole CLI, including
-# `jarvis serve`. Invoking `jarvis deep-research-setup` without the deps still
-# errors clearly on demand.
-try:
- from openjarvis.cli.deep_research_setup_cmd import deep_research_setup
-
- cli.add_command(deep_research_setup, "deep-research-setup")
- cli.add_command(deep_research_setup, "research")
-except Exception as _dr_exc:
- import logging as _logging
-
- _logging.getLogger(__name__).debug("deep-research command unavailable: %s", _dr_exc)
-cli.add_command(self_update, "self-update")
-cli.add_command(bootstrap_cmd, "_bootstrap")
-
-# Gateway CLI commands (lazy import to avoid pulling starlette)
-try:
- from openjarvis.cli.auth_cmd import auth
-
- cli.add_command(auth, "auth")
-except ImportError:
- pass
-
-try:
- from openjarvis.cli.tunnel_cmd import tunnel
-
- cli.add_command(tunnel, "tunnel")
-except ImportError:
- pass
+if not _DATA_BOUNDARY_BOOTSTRAP:
+ from openjarvis.cli._bootstrap import bootstrap_cmd
+ from openjarvis.cli.add_cmd import add
+ from openjarvis.cli.agent_cmd import agent
+ from openjarvis.cli.ask import ask
+ from openjarvis.cli.bench_cmd import bench
+ from openjarvis.cli.channel_cmd import channel
+ from openjarvis.cli.channels_cmd import channels
+ from openjarvis.cli.chat_cmd import chat
+ from openjarvis.cli.compose_cmd import compose
+ from openjarvis.cli.config_cmd import config
+ from openjarvis.cli.connect_cmd import connect
+ from openjarvis.cli.daemon_cmd import restart, start, status, stop
+ from openjarvis.cli.digest_cmd import digest
+ from openjarvis.cli.doctor_cmd import doctor
+ from openjarvis.cli.eval_cmd import eval_group
+ from openjarvis.cli.feedback_cmd import feedback_group
+ from openjarvis.cli.gateway_cmd import gateway
+ from openjarvis.cli.host_cmd import host
+ from openjarvis.cli.init_cmd import init
+ from openjarvis.cli.memory_cmd import memory
+ from openjarvis.cli.mine_cmd import mine
+ from openjarvis.cli.model import model
+ from openjarvis.cli.operators_cmd import operators
+ from openjarvis.cli.optimize_cmd import optimize_group
+ from openjarvis.cli.pearl_cmd import pearl
+ from openjarvis.cli.quickstart_cmd import quickstart
+ from openjarvis.cli.registry_cmd import registry
+ from openjarvis.cli.scheduler_cmd import scheduler
+ from openjarvis.cli.self_update_cmd import self_update
+ from openjarvis.cli.serve import serve
+ from openjarvis.cli.skill_cmd import skill
+ from openjarvis.cli.telemetry_cmd import telemetry
+ from openjarvis.cli.tool_cmd import tool
+ from openjarvis.cli.vault_cmd import vault
+ from openjarvis.cli.workflow_cmd import workflow
+
+ cli.add_command(init, "init")
+ cli.add_command(ask, "ask")
+ cli.add_command(chat, "chat")
+ cli.add_command(serve, "serve")
+ cli.add_command(model, "model")
+ cli.add_command(memory, "memory")
+ cli.add_command(mine, "mine")
+ cli.add_command(pearl, "pearl")
+ cli.add_command(telemetry, "telemetry")
+ cli.add_command(bench, "bench")
+ cli.add_command(channel, "channel")
+ cli.add_command(channels, "channels")
+ cli.add_command(scheduler, "scheduler")
+ cli.add_command(doctor, "doctor")
+ cli.add_command(agent, "agents")
+ cli.add_command(workflow, "workflow")
+ cli.add_command(skill, "skill")
+ cli.add_command(start, "start")
+ cli.add_command(stop, "stop")
+ cli.add_command(restart, "restart")
+ cli.add_command(status, "status")
+ cli.add_command(vault, "vault")
+ cli.add_command(add, "add")
+ cli.add_command(operators, "operators")
+ cli.add_command(eval_group, "eval")
+ cli.add_command(host, "host")
+ cli.add_command(quickstart, "quickstart")
+ cli.add_command(optimize_group, "optimize")
+ cli.add_command(feedback_group, "feedback")
+ cli.add_command(compose, "compose")
+ cli.add_command(gateway, "gateway")
+ cli.add_command(tool, "tool")
+ cli.add_command(registry, "registry")
+ cli.add_command(config, "config")
+ cli.add_command(connect, "connect")
+ cli.add_command(digest, "digest")
+
+ # Deep Research setup pulls the ingestion pipeline (embeddings/numpy). Guard
+ # it so an import-time dependency failure cannot take down the whole CLI.
+ try:
+ from openjarvis.cli.deep_research_setup_cmd import deep_research_setup
+
+ cli.add_command(deep_research_setup, "deep-research-setup")
+ cli.add_command(deep_research_setup, "research")
+ except Exception as _dr_exc:
+ import logging as _logging
+
+ _logging.getLogger(__name__).debug(
+ "deep-research command unavailable: %s", _dr_exc
+ )
+ cli.add_command(self_update, "self-update")
+ cli.add_command(bootstrap_cmd, "_bootstrap")
+
+ # Gateway CLI commands (lazy import to avoid pulling starlette)
+ try:
+ from openjarvis.cli.auth_cmd import auth
+
+ cli.add_command(auth, "auth")
+ except ImportError:
+ pass
+
+ try:
+ from openjarvis.cli.tunnel_cmd import tunnel
+
+ cli.add_command(tunnel, "tunnel")
+ except ImportError:
+ pass
def main() -> None:
diff --git a/src/openjarvis/cli/scan_cmd.py b/src/openjarvis/cli/scan_cmd.py
index 1d7862e7..ad8c56b7 100644
--- a/src/openjarvis/cli/scan_cmd.py
+++ b/src/openjarvis/cli/scan_cmd.py
@@ -3,6 +3,7 @@
from __future__ import annotations
import json
+import os
import subprocess
import sys
from dataclasses import dataclass
@@ -11,7 +12,11 @@ from typing import Callable, List
import click
-from openjarvis.core.paths import get_config_dir
+from openjarvis.core.paths import get_config_dir, get_config_path
+from openjarvis.security.data_boundary_audit import (
+ DataBoundaryReport,
+ build_data_boundary_report,
+)
# Engine ports that should only be listening on localhost.
_ENGINE_PORTS = {11434, 8080, 8000, 30000, 1234, 52415, 18181}
@@ -441,10 +446,45 @@ _RICH_ICONS = {
"ok": "[green]\u2713[/green]",
"warn": "[yellow]![/yellow]",
"fail": "[red]\u2717[/red]",
+ "info": "[blue]i[/blue]",
"skip": "[dim]-[/dim]",
}
+def _resolve_data_boundary_config_path() -> Path:
+ env_config = os.environ.get("OPENJARVIS_CONFIG")
+ if env_config:
+ return Path(env_config).expanduser().resolve()
+ return get_config_path()
+
+
+def _load_data_boundary_config():
+ """Load config without treating missing config as active."""
+ root = None
+ root_error = ""
+ try:
+ root = get_config_dir()
+ config_path = _resolve_data_boundary_config_path()
+ except Exception as exc:
+ config_path = None
+ root_error = f"{type(exc).__name__}: {exc}"
+
+ if root_error:
+ return None, root, False, "", root_error
+
+ try:
+ from openjarvis.core.config import JarvisConfig, load_config
+ except Exception as exc:
+ return None, root, False, f"{type(exc).__name__}: {exc}", ""
+
+ if config_path is None or not config_path.exists():
+ return JarvisConfig(), root, False, "", root_error
+ try:
+ return load_config(config_path), root, True, "", root_error
+ except Exception as exc:
+ return JarvisConfig(), root, False, f"{type(exc).__name__}: {exc}", root_error
+
+
def _render_results(results: List[ScanResult]) -> None:
"""Render scan results as a Rich table."""
from rich.console import Console
@@ -494,17 +534,123 @@ def _render_results(results: List[ScanResult]) -> None:
console.print()
+def _render_data_boundary_report(
+ report: DataBoundaryReport,
+ *,
+ show_paths: bool,
+) -> None:
+ """Render application data-boundary findings as a Rich table."""
+ from rich.console import Console
+ from rich.table import Table
+
+ console = Console()
+ console.print()
+ console.print("[bold]OpenJarvis Data-Boundary Scan[/bold]")
+ console.print(f"Verdict: [bold]{report.verdict}[/bold]")
+ console.print()
+
+ table = Table(show_header=True, header_style="bold", show_lines=True)
+ table.add_column("", width=3, justify="center")
+ table.add_column("Finding")
+ table.add_column("Recommendation")
+
+ for finding in report.findings:
+ icon = _RICH_ICONS.get(finding.status, "?")
+ style = {"fail": "red", "warn": "yellow", "info": "blue"}.get(
+ finding.status,
+ "white",
+ )
+ details = [f"[{style}]{finding.title}[/{style}]"]
+ details.append(f"[dim]{finding.potential_data_path}[/dim]")
+ if finding.location:
+ location = finding.absolute_location if show_paths else finding.location
+ details.append(f"[dim]Location: {location}[/dim]")
+ table.add_row(icon, "\n".join(details), finding.recommendation)
+
+ console.print(table)
+ summary = report.summary()
+ console.print()
+ console.print(
+ f" [red]{summary['fail']} fail[/red], "
+ f"[yellow]{summary['warn']} warning(s)[/yellow], "
+ f"[blue]{summary['info']} info[/blue]"
+ )
+ if not show_paths:
+ console.print(
+ " [dim]Absolute paths and connector basenames are redacted by default. "
+ "Use --show-paths for local debugging.[/dim]"
+ )
+ console.print()
+
+
+def _emit_data_boundary_json(
+ report: DataBoundaryReport,
+ *,
+ show_paths: bool,
+) -> None:
+ click.echo(json.dumps(report.to_dict(show_paths=show_paths), indent=2))
+
+
@click.command()
@click.option("--quick", is_flag=True, default=False, help="Run only critical checks.")
@click.option("--json", "as_json", is_flag=True, default=False, help="Output as JSON.")
-def scan(quick: bool, as_json: bool) -> None:
+ "--data-boundaries",
+ is_flag=True,
+ default=False,
+ help="Run application data-boundary checks instead of host checks.",
+)
+ "--strict",
+ is_flag=True,
+ default=False,
+ help="Exit non-zero if data-boundary fail or warn findings are present.",
+)
+ "--show-paths",
+ is_flag=True,
+ default=False,
+ help="Show absolute paths in data-boundary output.",
+)
+def scan(
+ quick: bool,
+ as_json: bool,
+ data_boundaries: bool,
+ strict: bool,
+ show_paths: bool,
+) -> None:
"""Audit your environment for privacy and security risks."""
+ if data_boundaries:
+ if quick:
+ raise click.UsageError("--quick cannot be combined with --data-boundaries.")
+ config, root, config_loaded, config_error, root_error = (
+ _load_data_boundary_config()
+ )
+ report = build_data_boundary_report(
+ config,
+ root,
+ config_loaded=config_loaded,
+ config_error=config_error,
+ root_error=root_error,
+ )
+ if as_json:
+ _emit_data_boundary_json(report, show_paths=show_paths)
+ else:
+ _render_data_boundary_report(report, show_paths=show_paths)
+ summary = report.summary()
+ if strict and (summary["fail"] or summary["warn"]):
+ raise click.exceptions.Exit(1)
+ return
+
+ if strict or show_paths:
+ raise click.UsageError(
+ "--strict and --show-paths are only supported with --data-boundaries."
+ )
+
scanner = PrivacyScanner()
results: List[ScanResult] = scanner.run_quick() if quick else scanner.run_all()
if as_json:
- import json as json_mod
-
output = [
{
"name": r.name,
@@ -514,7 +660,7 @@ def scan(quick: bool, as_json: bool) -> None:
}
for r in results
]
- click.echo(json_mod.dumps(output, indent=2))
+ click.echo(json.dumps(output, indent=2))
return
if not results:
diff --git a/src/openjarvis/security/__init__.py b/src/openjarvis/security/__init__.py
index b6d40da6..b89a4425 100644
--- a/src/openjarvis/security/__init__.py
+++ b/src/openjarvis/security/__init__.py
@@ -4,27 +4,10 @@ from __future__ import annotations
import logging
from dataclasses import dataclass
+from importlib import import_module
from typing import Any, Optional
from openjarvis.core.events import EventBus
-from openjarvis.security._stubs import BaseScanner
-from openjarvis.security.audit import AuditLogger
-from openjarvis.security.file_policy import (
- DEFAULT_SENSITIVE_PATTERNS,
- filter_sensitive_paths,
- is_sensitive_file,
-)
-from openjarvis.security.guardrails import GuardrailsEngine, SecurityBlockError
-from openjarvis.security.scanner import PIIScanner, SecretScanner
-from openjarvis.security.ssrf import check_ssrf, is_private_ip
-from openjarvis.security.types import (
- RedactionMode,
- ScanFinding,
- ScanResult,
- SecurityEvent,
- SecurityEventType,
- ThreatLevel,
-)
logger = logging.getLogger(__name__)
@@ -50,6 +33,12 @@ def setup_security(
if not config.security.enabled:
return SecurityContext(engine=engine)
+ from openjarvis.security._stubs import BaseScanner
+ from openjarvis.security.audit import AuditLogger
+ from openjarvis.security.guardrails import GuardrailsEngine
+ from openjarvis.security.scanner import PIIScanner, SecretScanner
+ from openjarvis.security.types import RedactionMode
+
# Scanners + engine wrapping
try:
scanners: list[BaseScanner] = []
@@ -121,3 +110,46 @@ __all__ = [
"is_sensitive_file",
"setup_security",
]
+
+_LAZY_EXPORTS = {
+ "AuditLogger": ("openjarvis.security.audit", "AuditLogger"),
+ "BaseScanner": ("openjarvis.security._stubs", "BaseScanner"),
+ "DEFAULT_SENSITIVE_PATTERNS": (
+ "openjarvis.security.file_policy",
+ "DEFAULT_SENSITIVE_PATTERNS",
+ ),
+ "GuardrailsEngine": ("openjarvis.security.guardrails", "GuardrailsEngine"),
+ "PIIScanner": ("openjarvis.security.scanner", "PIIScanner"),
+ "RedactionMode": ("openjarvis.security.types", "RedactionMode"),
+ "ScanFinding": ("openjarvis.security.types", "ScanFinding"),
+ "ScanResult": ("openjarvis.security.types", "ScanResult"),
+ "SecretScanner": ("openjarvis.security.scanner", "SecretScanner"),
+ "SecurityBlockError": (
+ "openjarvis.security.guardrails",
+ "SecurityBlockError",
+ ),
+ "SecurityEvent": ("openjarvis.security.types", "SecurityEvent"),
+ "SecurityEventType": ("openjarvis.security.types", "SecurityEventType"),
+ "ThreatLevel": ("openjarvis.security.types", "ThreatLevel"),
+ "check_ssrf": ("openjarvis.security.ssrf", "check_ssrf"),
+ "filter_sensitive_paths": (
+ "openjarvis.security.file_policy",
+ "filter_sensitive_paths",
+ ),
+ "is_private_ip": ("openjarvis.security.ssrf", "is_private_ip"),
+ "is_sensitive_file": ("openjarvis.security.file_policy", "is_sensitive_file"),
+}
+
+
+def __getattr__(name: str) -> Any:
+ target = _LAZY_EXPORTS.get(name)
+ if target is None:
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
+ module_name, attribute = target
+ value = getattr(import_module(module_name), attribute)
+ globals()[name] = value
+ return value
+
+
+def __dir__() -> list[str]:
+ return sorted(set(globals()) | set(_LAZY_EXPORTS))
diff --git a/src/openjarvis/security/data_boundary_audit.py b/src/openjarvis/security/data_boundary_audit.py
new file mode 100644
index 00000000..f96aefe5
--- /dev/null
+++ b/src/openjarvis/security/data_boundary_audit.py
@@ -0,0 +1,1729 @@
+"""Application data-boundary diagnostics for OpenJarvis.
+
+The report builder intentionally limits itself to configuration values,
+environment-key presence, and file existence. It never reads private user
+content from connector credential files, memory files, trace databases, logs, or
+other local runtime stores.
+"""
+
+from __future__ import annotations
+
+import hashlib
+import os
+from dataclasses import dataclass
+from pathlib import Path
+from typing import Any, Iterable, Literal
+
+from openjarvis.core.credentials import TOOL_CREDENTIALS
+
+Status = Literal["fail", "warn", "info"]
+
+CLOUD_PROVIDER_KEYS = {
+ "anthropic",
+ "claude",
+ "cloud",
+ "codex",
+ "deepseek",
+ "gemini",
+ "google",
+ "litellm",
+ "minimax",
+ "openai",
+ "openrouter",
+}
+
+LOCAL_ENGINE_KEYS = {
+ "apple_fm",
+ "exo",
+ "gemma_cpp",
+ "lemonade",
+ "llamacpp",
+ "lmstudio",
+ "mlx",
+ "nexa",
+ "ollama",
+ "sglang",
+ "uzu",
+ "vllm",
+}
+
+API_KEY_ENV_VARS = {
+ "ANTHROPIC_API_KEY": ("Anthropic cloud inference", {"anthropic", "claude"}),
+ "CARTESIA_API_KEY": (
+ "Cartesia cloud text-to-speech",
+ {"cartesia", "text_to_speech"},
+ ),
+ "DEEPSEEK_API_KEY": ("DeepSeek cloud inference", {"deepseek"}),
+ "GEMINI_API_KEY": ("Google/Gemini cloud inference", {"google", "gemini"}),
+ "GOOGLE_API_KEY": ("Google/Gemini cloud inference", {"google", "gemini"}),
+ "MINIMAX_API_KEY": ("MiniMax cloud inference", {"minimax"}),
+ "OPENAI_API_KEY": ("OpenAI cloud inference", {"openai", "gpt"}),
+ "OPENROUTER_API_KEY": ("OpenRouter cloud inference", {"openrouter"}),
+ "TAVILY_API_KEY": ("Tavily web search", {"tavily", "web_search"}),
+}
+
+CHANNEL_SECRET_FIELDS: tuple[tuple[str, str, str], ...] = (
+ ("channel.telegram.bot_token", "Telegram bot token", "Telegram"),
+ ("channel.discord.bot_token", "Discord bot token", "Discord"),
+ ("channel.slack.bot_token", "Slack bot token", "Slack"),
+ ("channel.slack.app_token", "Slack app token", "Slack"),
+ ("channel.webhook.secret", "Webhook secret", "generic webhook"),
+ ("channel.email.password", "Email password", "email"),
+ ("channel.whatsapp.access_token", "WhatsApp access token", "WhatsApp"),
+ ("channel.irc.password", "IRC password", "IRC"),
+ ("channel.teams.app_password", "Teams app password", "Teams"),
+ ("channel.matrix.access_token", "Matrix access token", "Matrix"),
+ ("channel.mattermost.token", "Mattermost token", "Mattermost"),
+ ("channel.feishu.app_secret", "Feishu app secret", "Feishu"),
+ ("channel.bluebubbles.password", "BlueBubbles password", "BlueBubbles"),
+)
+
+CHANNEL_REFERENCE_FIELDS: tuple[tuple[str, str, str], ...] = (
+ ("channel.webhook.url", "Webhook URL", "generic webhook"),
+ ("channel.email.smtp_host", "Email SMTP host", "email"),
+ ("channel.email.imap_host", "Email IMAP host", "email"),
+ ("channel.email.username", "Email username", "email"),
+ ("channel.whatsapp.phone_number_id", "WhatsApp phone number ID", "WhatsApp"),
+ ("channel.signal.api_url", "Signal API URL", "Signal"),
+ ("channel.signal.phone_number", "Signal phone number", "Signal"),
+ ("channel.google_chat.webhook_url", "Google Chat webhook URL", "Google Chat"),
+ ("channel.irc.server", "IRC server", "IRC"),
+ ("channel.irc.nick", "IRC nick", "IRC"),
+ ("channel.teams.app_id", "Teams app ID", "Teams"),
+ ("channel.teams.service_url", "Teams service URL", "Teams"),
+ ("channel.matrix.homeserver", "Matrix homeserver", "Matrix"),
+ ("channel.mattermost.url", "Mattermost URL", "Mattermost"),
+ ("channel.feishu.app_id", "Feishu app ID", "Feishu"),
+ ("channel.bluebubbles.url", "BlueBubbles URL", "BlueBubbles"),
+)
+
+CHANNEL_SECRET_ENV_VARS = {
+ "BLUEBUBBLES_PASSWORD": "BlueBubbles channel",
+ "DISCORD_BOT_TOKEN": "Discord channel",
+ "FEISHU_APP_SECRET": "Feishu channel",
+ "MATTERMOST_TOKEN": "Mattermost channel",
+ "MATRIX_ACCESS_TOKEN": "Matrix channel",
+ "SLACK_APP_TOKEN": "Slack channel",
+ "SLACK_BOT_TOKEN": "Slack channel",
+ "TEAMS_APP_PASSWORD": "Teams channel",
+ "TELEGRAM_BOT_TOKEN": "Telegram channel",
+ "WHATSAPP_ACCESS_TOKEN": "WhatsApp channel",
+}
+
+CHANNEL_REFERENCE_ENV_VARS = {
+ "BLUEBUBBLES_URL": "BlueBubbles channel",
+ "FEISHU_APP_ID": "Feishu channel",
+ "GOOGLE_CHAT_WEBHOOK_URL": "Google Chat channel",
+ "MATTERMOST_URL": "Mattermost channel",
+ "MATRIX_HOMESERVER": "Matrix channel",
+ "SIGNAL_PHONE_NUMBER": "Signal channel",
+ "TEAMS_APP_ID": "Teams channel",
+ "WHATSAPP_PHONE_NUMBER_ID": "WhatsApp channel",
+}
+
+# Runtime tool/channel credential env keys from credentials.toml schema.
+RUNTIME_CREDENTIAL_ENV_KEYS = {
+ key for keys in TOOL_CREDENTIALS.values() for key in keys
+}
+
+# Specialized findings carry provider/channel semantics; remaining keys get a
+# presence-only generic finding. Values are never read or printed.
+_SPECIALIZED_CREDENTIAL_ENV_VARS = (
+ set(API_KEY_ENV_VARS)
+ | set(CHANNEL_SECRET_ENV_VARS)
+ | set(CHANNEL_REFERENCE_ENV_VARS)
+)
+GENERIC_CREDENTIAL_ENV_VARS = frozenset(
+ RUNTIME_CREDENTIAL_ENV_KEYS - _SPECIALIZED_CREDENTIAL_ENV_VARS
+)
+
+LOCAL_STORE_CANDIDATES: tuple[tuple[str, str, str, Status], ...] = (
+ ("config-file", "Configuration file", "config.toml", "info"),
+ ("credentials-toml", "Credentials file", "credentials.toml", "warn"),
+ ("knowledge-db", "Knowledge and Deep Research database", "knowledge.db", "warn"),
+ ("memory-db", "Memory index database", "memory.db", "warn"),
+ ("memory-facts", "Persistent memory facts", "memory_facts.jsonl", "warn"),
+ ("traces-db", "Trace database", "traces.db", "warn"),
+ ("telemetry-db", "Telemetry database", "telemetry.db", "info"),
+ ("audit-db", "Security audit database", "audit.db", "info"),
+ ("sessions-db", "Session database", "sessions.db", "warn"),
+ ("agents-db", "Agent manager database", "agents.db", "warn"),
+ ("optimize-db", "Optimization database", "optimize.db", "warn"),
+ ("scheduler-db", "Scheduler database", "scheduler.db", "warn"),
+ ("skill-index", "Skill index directory", "skill-index", "info"),
+ ("vault-key", "Vault encryption key", ".vault_key", "warn"),
+ ("embeddings-store", "Embeddings store", "embeddings", "warn"),
+ ("soul-file", "SOUL memory file", "SOUL.md", "warn"),
+ ("memory-file", "MEMORY memory file", "MEMORY.md", "warn"),
+ ("user-file", "USER memory file", "USER.md", "warn"),
+)
+
+_CONFIG_STORE_PATHS: tuple[tuple[str, str, str, Status], ...] = (
+ ("memory-db", "Memory index database", "tools.storage.db_path", "warn"),
+ ("memory-facts", "Persistent memory facts", "tools.storage.facts_path", "warn"),
+ ("traces-db", "Trace database", "traces.db_path", "warn"),
+ ("telemetry-db", "Telemetry database", "telemetry.db_path", "info"),
+ ("audit-db", "Security audit database", "security.audit_log_path", "info"),
+ ("sessions-db", "Session database", "sessions.db_path", "warn"),
+ ("agents-db", "Agent manager database", "agents.db_path", "warn"),
+ ("optimize-db", "Optimization database", "optimize.db_path", "warn"),
+ ("vault-key", "Vault encryption key", "security.vault_key_path", "warn"),
+ ("scheduler-db", "Scheduler database", "scheduler.db_path", "warn"),
+ ("skill-index", "Skill index directory", "skills.index_dir", "info"),
+)
+
+PERSONAL_DIGEST_SOURCES = {
+ "apple_health",
+ "dropbox",
+ "gcalendar",
+ "gcontacts",
+ "gdrive",
+ "github",
+ "gmail",
+ "google_tasks",
+ "imessage",
+ "notion",
+ "obsidian",
+ "oura",
+ "outlook",
+ "slack",
+ "spotify",
+ "strava",
+ "whatsapp",
+}
+
+WEB_SEARCH_TOOLS = {"web_search", "search", "tavily_search"}
+BROWSER_TOOLS = {
+ "browser",
+ "browser_axtree",
+ "browser_click",
+ "browser_extract",
+ "browser_navigate",
+ "browser_open",
+ "browser_screenshot",
+ "browser_search",
+ "browser_type",
+ "web_browser",
+}
+GENERIC_NETWORK_TOOLS = {"http_request"}
+CHANNEL_OUTBOUND_TOOLS = {"channel_send"}
+CLOUD_MEDIA_TOOLS = {"audio_transcribe", "image_generate", "text_to_speech"}
+CLOUD_TTS_BACKENDS = {"cartesia", "openai", "openai_tts"}
+# Local knowledge chunks scanned by an inference engine (Deep Research path).
+KNOWLEDGE_ENGINE_TOOLS = {"scan_chunks"}
+# External egress surfaces (web, browser, HTTP, channels, media, knowledge LM).
+EXTERNAL_TOOL_SURFACES = (
+ WEB_SEARCH_TOOLS
+ | BROWSER_TOOLS
+ | GENERIC_NETWORK_TOOLS
+ | CHANNEL_OUTBOUND_TOOLS
+ | CLOUD_MEDIA_TOOLS
+ | KNOWLEDGE_ENGINE_TOOLS
+)
+# Narrower cloud inference / media API key surfaces (not browser-only egress).
+CLOUD_API_SURFACES = CLOUD_MEDIA_TOOLS | WEB_SEARCH_TOOLS
+OUTBOUND_TOOL_SURFACES = EXTERNAL_TOOL_SURFACES
+LOCAL_ACCESS_TOOLS = {
+ "apply_patch",
+ "channel_list",
+ "channel_status",
+ "code_interpreter",
+ "code_interpreter_docker",
+ "db_query",
+ "docker_shell_exec",
+ "file_read",
+ "file_write",
+ "git_commit",
+ "git_diff",
+ "git_log",
+ "git_status",
+ "kg_add_entity",
+ "kg_add_relation",
+ "kg_neighbors",
+ "kg_query",
+ "knowledge_sql",
+ "memory_index",
+ "memory_manage",
+ "memory_retrieve",
+ "memory_search",
+ "memory_store",
+ "pdf_extract",
+ "repl",
+ "retrieval",
+ "shell_exec",
+ "skill_manage",
+ "user_profile_manage",
+}
+
+
+@dataclass(frozen=True, slots=True)
+class DataBoundaryFinding:
+ """One application data-boundary finding."""
+
+ id: str
+ status: Status
+ title: str
+ potential_data_path: str
+ evidence: str
+ recommendation: str
+ location: str = ""
+ absolute_location: str = ""
+
+ def to_dict(self, *, show_paths: bool = False) -> dict[str, str]:
+ """Return a stable JSON-serializable representation.
+
+ Absolute paths and connector basenames are redacted by default. When
+ ``show_paths`` is true, the location field exposes the absolute path for
+ local debugging.
+ """
+ payload = {
+ "id": self.id,
+ "status": self.status,
+ "title": self.title,
+ "potential_data_path": self.potential_data_path,
+ "evidence": self.evidence,
+ "recommendation": self.recommendation,
+ }
+ if self.absolute_location:
+ payload["location"] = (
+ self.absolute_location if show_paths else self.location
+ )
+ elif self.location:
+ payload["location"] = self.location
+ return payload
+
+
+@dataclass(frozen=True, slots=True)
+class DataBoundaryReport:
+ """Structured result returned by the data-boundary audit."""
+
+ verdict: str
+ root: str
+ config_loaded: bool
+ findings: tuple[DataBoundaryFinding, ...]
+
+ def summary(self) -> dict[str, int]:
+ """Count findings by status."""
+ counts = {"fail": 0, "warn": 0, "info": 0}
+ for finding in self.findings:
+ counts[finding.status] += 1
+ return counts
+
+ def to_dict(self, *, show_paths: bool = False) -> dict[str, Any]:
+ """Return a stable JSON-serializable representation."""
+ return {
+ "schema_version": 1,
+ "verdict": self.verdict,
+ "root": self.root if show_paths else _redact_root(self.root),
+ "config_loaded": self.config_loaded,
+ "summary": self.summary(),
+ "findings": [
+ finding.to_dict(show_paths=show_paths) for finding in self.findings
+ ],
+ }
+
+
+class _FindingBuilder:
+ """Small helper that preserves insertion order and deduplicates by id."""
+
+ def __init__(self) -> None:
+ self._findings: list[DataBoundaryFinding] = []
+ self._seen: set[str] = set()
+
+ def add(
+ self,
+ *,
+ finding_id: str,
+ status: Status,
+ title: str,
+ potential_data_path: str,
+ evidence: str,
+ recommendation: str,
+ location: str = "",
+ absolute_location: str = "",
+ ) -> None:
+ if finding_id in self._seen:
+ return
+ self._seen.add(finding_id)
+ self._findings.append(
+ DataBoundaryFinding(
+ id=finding_id,
+ status=status,
+ title=title,
+ potential_data_path=potential_data_path,
+ evidence=evidence,
+ recommendation=recommendation,
+ location=location,
+ absolute_location=absolute_location,
+ )
+ )
+
+ def build(self) -> tuple[DataBoundaryFinding, ...]:
+ return tuple(self._findings)
+
+
+def build_data_boundary_report(
+ config: Any,
+ root: Path | None,
+ *,
+ config_loaded: bool = True,
+ config_error: str = "",
+ root_error: str = "",
+) -> DataBoundaryReport:
+ """Build a data-boundary report from config and runtime paths.
+
+ The function is side-effect-free. It uses defensive ``getattr`` access so
+ the command remains robust across configuration additions.
+ """
+
+ builder = _FindingBuilder()
+ root_path: Path | None = None
+ root_label = "<unresolved-openjarvis-home>"
+ if root is not None:
+ try:
+ root_path = root.expanduser().resolve()
+ root_label = str(root_path)
+ except Exception as exc: # pragma: no cover - defensive path handling
+ root_error = f"{type(exc).__name__}: {exc}"
+
+ if root_error:
+ error_type = str(root_error).partition(":")[0].strip() or "Error"
+ if not error_type.replace("_", "").isalnum():
+ error_type = "Error"
+ builder.add(
+ finding_id="config-root-error",
+ status="fail",
+ title="OpenJarvis home directory could not be resolved",
+ potential_data_path="runtime state root -> local store checks",
+ evidence=(
+ f"{error_type} while resolving OpenJarvis home; "
+ "path details were redacted"
+ ),
+ recommendation=(
+ "Fix OPENJARVIS_HOME or XDG_DATA_HOME before relying on "
+ "local-store data-boundary checks."
+ ),
+ )
+
+ if config_error:
+ builder.add(
+ finding_id="config-load-error",
+ status="fail",
+ title="OpenJarvis config could not be loaded",
+ potential_data_path="config.toml -> data-boundary report",
+ evidence=_truncate(config_error),
+ recommendation=(
+ "Fix the configuration file before relying on config-derived "
+ "data-boundary checks. Local store and environment checks still run."
+ ),
+ )
+ elif config_loaded:
+ _audit_outbound_settings(config, builder)
+ _audit_telemetry_settings(config, builder)
+ _audit_memory_cloud_composition(config, builder)
+ _audit_memory_service(config, builder)
+ _audit_deep_research_settings(config, builder)
+ _audit_trace_and_learning_settings(config, builder)
+ _audit_tool_surfaces(config, builder)
+ _audit_server_exposure(config, builder)
+ _audit_channel_settings(config, builder)
+ _audit_skills_and_digest(config, builder)
+ _audit_speech_settings(config, builder)
+ elif not root_error:
+ builder.add(
+ finding_id="config-file-missing",
+ status="info",
+ title="OpenJarvis config file was not found",
+ potential_data_path="configuration defaults -> data-boundary report",
+ evidence="config_loaded = false",
+ recommendation=(
+ "Run `jarvis init` before relying on config-derived checks. "
+ "Local store and environment checks still run."
+ ),
+ )
+
+ active_tools = (
+ _configured_tools(config) if config_loaded and not config_error else set()
+ )
+ active_config = config if config_loaded and not config_error else None
+ if active_config is not None:
+ _audit_security_settings(
+ active_config,
+ builder,
+ has_external_surface=_has_external_surface(active_config, active_tools),
+ )
+
+ if root_path is not None:
+ _audit_local_stores(root_path, builder, config=active_config)
+ _audit_connector_credentials(root_path, builder)
+ if active_config is not None:
+ _audit_local_channel_credential_dirs(active_config, root_path, builder)
+ _audit_knowledge_cloud_composition(active_config, root_path, builder)
+ _audit_environment_credentials(
+ active_config,
+ builder,
+ active_tools=active_tools,
+ )
+ _audit_channel_environment_credentials(active_config, builder)
+ _audit_generic_runtime_credentials(builder)
+ if _has_cloud_api_surface(active_config, active_tools):
+ _audit_frontend_storage_scope(builder)
+
+ findings = builder.build()
+ return DataBoundaryReport(
+ verdict=_derive_verdict(findings),
+ root=root_label,
+ config_loaded=config_loaded and not bool(config_error),
+ findings=findings,
+ )
+
+
+def _audit_outbound_settings(config: Any, builder: _FindingBuilder) -> None:
+ if bool(_get(config, "analytics.enabled", False)):
+ builder.add(
+ finding_id="analytics-enabled",
+ status="info",
+ title="Outbound usage analytics are enabled",
+ potential_data_path="runtime usage events -> analytics endpoint",
+ evidence="analytics.enabled = true",
+ recommendation=(
+ "Set analytics.enabled = false for no outbound usage analytics. "
+ "This finding does not assert that prompt content is sent."
+ ),
+ )
+
+ provider = _get(config, "intelligence.provider", "")
+ if _is_cloud_value(provider):
+ builder.add(
+ finding_id="cloud-provider-configured",
+ status="warn",
+ title="Cloud model provider configured",
+ potential_data_path=(
+ "prompts, memory context, and tool outputs -> cloud provider"
+ ),
+ evidence=f"intelligence.provider = {_quote(provider)}",
+ recommendation=(
+ "Review what context is sent before enabling cloud inference, "
+ "or use a local provider for local-only operation."
+ ),
+ )
+
+ default_model = _get(config, "intelligence.default_model", "")
+ effective_engine = _first_nonempty(
+ _get(config, "intelligence.preferred_engine", ""),
+ _get(config, "engine.default", ""),
+ provider,
+ )
+ if _target_is_cloud(effective_engine, default_model):
+ builder.add(
+ finding_id="cloud-default-model-configured",
+ status="warn",
+ title="Cloud default model configured",
+ potential_data_path="model requests -> default cloud model",
+ evidence=f"intelligence.default_model = {_quote(default_model)}",
+ recommendation=("Use a local default model for local-only operation."),
+ )
+
+ preferred_engine = _get(config, "intelligence.preferred_engine", "")
+ if _is_cloud_value(preferred_engine):
+ builder.add(
+ finding_id="cloud-preferred-engine-configured",
+ status="warn",
+ title="Cloud preferred engine configured",
+ potential_data_path="model requests -> preferred cloud engine",
+ evidence=f"intelligence.preferred_engine = {_quote(preferred_engine)}",
+ recommendation="Use a local preferred engine for local-only operation.",
+ )
+
+ default_engine = _get(config, "engine.default", "")
+ if _is_cloud_value(default_engine):
+ builder.add(
+ finding_id="cloud-default-engine-configured",
+ status="warn",
+ title="Cloud default engine configured",
+ potential_data_path="model requests -> default cloud engine",
+ evidence=f"engine.default = {_quote(default_engine)}",
+ recommendation="Use a local default engine for local-only operation.",
+ )
+
+ optimize_provider = _get(config, "optimize.optimizer_provider", "")
+ if _is_cloud_value(optimize_provider):
+ builder.add(
+ finding_id="cloud-optimizer-provider-configured",
+ status="info",
+ title="Cloud optimizer provider is configured",
+ potential_data_path="optimization context -> optimizer provider",
+ evidence=f"optimize.optimizer_provider = {_quote(optimize_provider)}",
+ recommendation=(
+ "Before running optimization, review whether examples, traces, "
+ "or prompts may be sent to this provider."
+ ),
+ )
+
+ judge_model = _get(config, "optimize.judge_model", "")
+ if _target_is_cloud(optimize_provider, judge_model):
+ builder.add(
+ finding_id="cloud-judge-model-configured",
+ status="info",
+ title="Cloud judge model appears configured",
+ potential_data_path="optimization examples/results -> judge model",
+ evidence=f"optimize.judge_model = {_quote(judge_model)}",
+ recommendation="Use a local judge model for local-only optimization.",
+ )
+
+
+def _audit_telemetry_settings(config: Any, builder: _FindingBuilder) -> None:
+ if bool(_get(config, "telemetry.enabled", False)):
+ builder.add(
+ finding_id="telemetry-enabled",
+ status="warn",
+ title="Telemetry capture is enabled",
+ potential_data_path=(
+ "runtime metrics and inference events -> telemetry database"
+ ),
+ evidence="telemetry.enabled = true",
+ recommendation=(
+ "Disable telemetry when local-only metrics collection is not "
+ "needed. Treat telemetry.db as sensitive when enabled."
+ ),
+ )
+
+
+def _audit_memory_service(config: Any, builder: _FindingBuilder) -> None:
+ if not bool(_get(config, "tools.storage.enabled", False)):
+ return
+ has_cloud = bool(_primary_cloud_signals(config))
+ evidence = "tools.storage.enabled = true"
+ if has_cloud:
+ evidence += "; cloud inference surface detected"
+ builder.add(
+ finding_id="memory-service-enabled",
+ status="warn",
+ title="Automatic memory service is enabled",
+ potential_data_path=(
+ "conversation content -> extracted facts -> local memory store"
+ ),
+ evidence=evidence,
+ recommendation=(
+ "Review what conversations are persisted before enabling the "
+ "background memory service on sensitive workloads."
+ ),
+ )
+
+
+def _audit_deep_research_settings(config: Any, builder: _FindingBuilder) -> None:
+ engine = _get(config, "deep_research.engine", "")
+ model = _get(config, "deep_research.model", "")
+ cloud_engine = _is_cloud_value(engine)
+ effective_engine, effective_model = _effective_deep_research_target(config)
+ cloud_model = bool(model) and _target_is_cloud(effective_engine, effective_model)
+ if not cloud_engine and not cloud_model:
+ return
+ evidence_parts = []
+ if cloud_engine:
+ evidence_parts.append(f"deep_research.engine = {_quote(engine)}")
+ if cloud_model:
+ evidence_parts.append(f"deep_research.model = {_quote(model)}")
+ builder.add(
+ finding_id="deep-research-cloud-configured",
+ status="warn",
+ title="Cloud deep-research engine or model configured",
+ potential_data_path="research planner context -> cloud engine/model",
+ evidence="; ".join(evidence_parts),
+ recommendation=(
+ "Use local deep-research engine and model settings for local-only "
+ "operation."
+ ),
+ )
+
+
+def _effective_deep_research_target(config: Any) -> tuple[str, str]:
+ """Return static-config effective Deep Research engine and model.
+
+ Resolution uses configuration only (no request overrides or live chat
+ session engines):
+
+ * engine: first nonempty of ``deep_research.engine``, ``engine.default``
+ * model: first nonempty of ``deep_research.model``, ``server.model``,
+ ``intelligence.default_model``
+ """
+ engine = _first_nonempty(
+ _get(config, "deep_research.engine", ""),
+ _get(config, "engine.default", ""),
+ )
+ model = _first_nonempty(
+ _get(config, "deep_research.model", ""),
+ _get(config, "server.model", ""),
+ _get(config, "intelligence.default_model", ""),
+ )
+ return engine, model
+
+
+def _first_nonempty(*values: Any) -> str:
+ for value in values:
+ text = str(value or "").strip()
+ if text:
+ return text
+ return ""
+
+
+def _scan_chunks_surface_active(config: Any, tools: set[str] | None = None) -> bool:
+ """Whether scan_chunks is configured or auto-installed via Deep Research."""
+ active = tools if tools is not None else _configured_tools(config)
+ if active & KNOWLEDGE_ENGINE_TOOLS:
+ return True
+ agent = str(_get(config, "agent.default_agent", "") or "").strip().lower()
+ return agent in {"deep_research", "research"}
+
+
+def _knowledge_store_exists(root: Path) -> bool:
+ """True when knowledge.db exists under the OpenJarvis home (metadata only)."""
+ return (root / "knowledge.db").exists()
+
+
+def _audit_knowledge_cloud_composition(
+ config: Any,
+ root: Path,
+ builder: _FindingBuilder,
+) -> None:
+ """Flag local knowledge chunks routed toward cloud Deep Research inference."""
+ tools = _configured_tools(config)
+ scan_active = _scan_chunks_surface_active(config, tools)
+ knowledge_exists = _knowledge_store_exists(root)
+ engine, model = _effective_deep_research_target(config)
+ cloud_target = _target_is_cloud(engine, model)
+
+ if knowledge_exists and cloud_target:
+ # Deep Research auto-installs ScanChunksTool when knowledge.db exists.
+ evidence_parts = [
+ "knowledge.db exists",
+ (
+ "effective deep_research engine = "
+ f"{_quote(engine) if engine else '<empty>'}"
+ ),
+ (
+ "effective deep_research model = "
+ f"{_quote(model) if model else '<empty>'}"
+ ),
+ ]
+ if tools & KNOWLEDGE_ENGINE_TOOLS:
+ evidence_parts.append(
+ f"configured tool(s) = {_format_tools(tools & KNOWLEDGE_ENGINE_TOOLS)}"
+ )
+ else:
+ evidence_parts.append(
+ "deep research auto-installs scan_chunks when knowledge.db exists"
+ )
+ builder.add(
+ finding_id="knowledge-chunks-to-cloud-risk",
+ status="fail",
+ title="Local knowledge chunks may be sent to cloud inference",
+ potential_data_path=(
+ "local knowledge.db chunks -> scan_chunks / Deep Research -> "
+ "cloud inference"
+ ),
+ evidence="; ".join(evidence_parts),
+ recommendation=(
+ "Use a local Deep Research engine/model when knowledge.db contains "
+ "sensitive documents, or remove cloud defaults before scanning chunks."
+ ),
+ )
+ elif scan_active:
+ if tools & KNOWLEDGE_ENGINE_TOOLS:
+ evidence = (
+ f"configured tool(s) = {_format_tools(tools & KNOWLEDGE_ENGINE_TOOLS)}"
+ )
+ else:
+ agent_name = _get(config, "agent.default_agent", "")
+ evidence = f"agent.default_agent = {_quote(agent_name)}"
+ # Local effective target is informational; unset/unknown stays warn.
+ status: Status = "info" if engine and not cloud_target else "warn"
+ builder.add(
+ finding_id="knowledge-engine-tool-configured",
+ status=status,
+ title="Knowledge chunk scanning routes local chunks to an inference engine",
+ potential_data_path=(
+ "local knowledge-store chunks -> configured inference engine"
+ ),
+ evidence=evidence,
+ recommendation=(
+ "Review knowledge.db contents and the effective Deep Research "
+ "engine/model before scanning sensitive documents."
+ ),
+ )
+
+
+def _audit_security_settings(
+ config: Any,
+ builder: _FindingBuilder,
+ *,
+ has_external_surface: bool,
+) -> None:
+ profile = str(_get(config, "security.profile", "") or "").strip()
+ if not profile:
+ builder.add(
+ finding_id="security-profile-unset",
+ status="info",
+ title="Security profile is not set",
+ potential_data_path="security defaults -> guardrails and server posture",
+ evidence="security.profile is empty",
+ recommendation=(
+ "Set security.profile to personal, shared, or server to apply "
+ "a documented guardrails preset."
+ ),
+ )
+
+ if not has_external_surface:
+ return
+
+ if bool(_get(config, "security.local_engine_bypass", False)):
+ builder.add(
+ finding_id="security-local-engine-bypass-enabled",
+ status="warn",
+ title="Local engine guardrail bypass is enabled with external surfaces",
+ potential_data_path=(
+ "external or cloud-bound prompts/outputs -> guardrails bypass "
+ "for local engines"
+ ),
+ evidence=(
+ "security.local_engine_bypass = true with external or "
+ "cloud-capable settings"
+ ),
+ recommendation=(
+ "Disable local_engine_bypass unless the external surface is "
+ "intentional and reviewed."
+ ),
+ )
+
+ if bool(_get(config, "security.local_tool_bypass", False)):
+ builder.add(
+ finding_id="security-local-tool-bypass-enabled",
+ status="warn",
+ title="Local tool guardrail bypass is enabled with external surfaces",
+ potential_data_path=(
+ "external or cloud-bound tool arguments/results -> guardrails bypass"
+ ),
+ evidence=(
+ "security.local_tool_bypass = true with external or "
+ "cloud-capable settings"
+ ),
+ recommendation=(
+ "Disable local_tool_bypass unless the external surface is "
+ "intentional and reviewed."
+ ),
+ )
+
+
+def _audit_memory_cloud_composition(
+ config: Any,
+ builder: _FindingBuilder,
+) -> None:
+ context_from_memory = bool(_get(config, "agent.context_from_memory", False))
+ active_cloud = _primary_cloud_signals(config)
+
+ if context_from_memory and active_cloud:
+ builder.add(
+ finding_id="memory-context-to-cloud-risk",
+ status="fail",
+ title="Local memory may be injected into cloud-bound prompts",
+ potential_data_path=(
+ "indexed local memory -> prompt context -> cloud inference provider"
+ ),
+ evidence=(
+ "agent.context_from_memory = true; cloud setting(s) = "
+ + ", ".join(active_cloud)
+ ),
+ recommendation=(
+ "Disable agent.context_from_memory before using cloud inference, "
+ "or use local engines when indexed memory contains sensitive data."
+ ),
+ )
+ elif context_from_memory:
+ builder.add(
+ finding_id="memory-context-injection-enabled",
+ status="info",
+ title="Memory context injection is enabled",
+ potential_data_path="indexed local memory -> future prompt context",
+ evidence="agent.context_from_memory = true",
+ recommendation=(
+ "Keep indexed memory scoped to data that may safely appear in future "
+ "prompts, especially if cloud engines are enabled later."
+ ),
+ )
+
+
+def _audit_trace_and_learning_settings(
+ config: Any,
+ builder: _FindingBuilder,
+) -> None:
+ if bool(_get(config, "traces.enabled", False)):
+ builder.add(
+ finding_id="traces-enabled",
+ status="warn",
+ title="Trace capture is enabled",
+ potential_data_path=(
+ "prompts, outputs, tool calls, and tool results -> traces database"
+ ),
+ evidence="traces.enabled = true",
+ recommendation=(
+ "Disable traces when debugging or trace-driven learning is not "
+ "needed. Treat traces.db as sensitive when enabled."
+ ),
+ )
+
+ if bool(_get(config, "learning.enabled", False)):
+ builder.add(
+ finding_id="learning-enabled",
+ status="warn",
+ title="Learning from local runtime data is enabled",
+ potential_data_path=(
+ "local traces/telemetry/feedback -> routing, agent, skill, or "
+ "model updates"
+ ),
+ evidence="learning.enabled = true",
+ recommendation=(
+ "Review active learning sub-policies before using sensitive traces."
+ ),
+ )
+
+ if bool(_get(config, "learning.training_enabled", False)):
+ builder.add(
+ finding_id="training-enabled",
+ status="warn",
+ title="Training pipeline is enabled",
+ potential_data_path="trace-derived examples -> model adapters",
+ evidence="learning.training_enabled = true",
+ recommendation=(
+ "Disable training unless trace reuse for model updates is intentional."
+ ),
+ )
+
+ if bool(_get(config, "learning.auto_update", False)):
+ builder.add(
+ finding_id="learning-auto-update-enabled",
+ status="warn",
+ title="Automatic learning updates are enabled",
+ potential_data_path="runtime feedback/traces -> automatic updates",
+ evidence="learning.auto_update = true",
+ recommendation=(
+ "Use manual updates when explicit review is needed before "
+ "trace-derived changes."
+ ),
+ )
+
+ spec_search_enabled = bool(_get(config, "learning.spec_search.enabled", False))
+ teacher_engine = _get(config, "learning.spec_search.teacher_engine", "")
+ teacher_model = _get(config, "learning.spec_search.teacher_model", "")
+ if spec_search_enabled and _is_cloud_value(teacher_engine):
+ builder.add(
+ finding_id="spec-search-cloud-teacher-enabled",
+ status="fail",
+ title="LLM-guided spec search uses a cloud teacher engine",
+ potential_data_path=(
+ "diagnostics/spec-search context -> cloud teacher model"
+ ),
+ evidence=(
+ "learning.spec_search.enabled = true; "
+ f"teacher_engine = {_quote(teacher_engine)}; "
+ f"teacher_model = {_quote(teacher_model)}"
+ ),
+ recommendation=(
+ "Use a local teacher engine/model or keep spec search disabled for "
+ "local-only operation."
+ ),
+ )
+
+
+def _audit_tool_surfaces(config: Any, builder: _FindingBuilder) -> None:
+ tools = _configured_tools(config)
+
+ if tools & WEB_SEARCH_TOOLS:
+ builder.add(
+ finding_id="web-search-tool-configured",
+ status="warn",
+ title="Web search tool is configured",
+ potential_data_path="user or agent search query -> external search service",
+ evidence=f"configured tool(s) = {_format_tools(tools & WEB_SEARCH_TOOLS)}",
+ recommendation=(
+ "Review search queries before using web search with sensitive prompts."
+ ),
+ )
+
+ if tools & BROWSER_TOOLS:
+ builder.add(
+ finding_id="browser-tool-configured",
+ status="warn",
+ title="Browser automation tool is configured",
+ potential_data_path="agent browser actions -> external web pages",
+ evidence=f"configured tool(s) = {_format_tools(tools & BROWSER_TOOLS)}",
+ recommendation=(
+ "Use browser automation only when web interactions are intentional."
+ ),
+ )
+
+ if tools & GENERIC_NETWORK_TOOLS:
+ builder.add(
+ finding_id="generic-network-tool-configured",
+ status="warn",
+ title="Generic HTTP/network tool is configured",
+ potential_data_path=("HTTP arguments, headers, and body -> external URL"),
+ evidence=(
+ f"configured tool(s) = {_format_tools(tools & GENERIC_NETWORK_TOOLS)}"
+ ),
+ recommendation=(
+ "Review request destinations and payloads before using HTTP tools with "
+ "sensitive data."
+ ),
+ )
+
+ if tools & CHANNEL_OUTBOUND_TOOLS:
+ builder.add(
+ finding_id="channel-outbound-tool-configured",
+ status="warn",
+ title="Channel outbound messaging tool is configured",
+ potential_data_path="message content -> external messaging channel",
+ evidence=(
+ f"configured tool(s) = {_format_tools(tools & CHANNEL_OUTBOUND_TOOLS)}"
+ ),
+ recommendation=(
+ "Review channel targets and message content before enabling outbound "
+ "messaging tools."
+ ),
+ )
+
+ cloud_media = tools & CLOUD_MEDIA_TOOLS
+ if cloud_media:
+ path_parts: list[str] = []
+ if "image_generate" in cloud_media:
+ path_parts.append("image prompt -> external media provider")
+ if "audio_transcribe" in cloud_media:
+ path_parts.append("local audio file -> external media provider")
+ if "text_to_speech" in cloud_media:
+ path_parts.append("text content -> external text-to-speech provider")
+ builder.add(
+ finding_id="cloud-media-tool-configured",
+ status="warn",
+ title="Cloud media generation or transcription tool is configured",
+ potential_data_path="; ".join(path_parts),
+ evidence=f"configured tool(s) = {_format_tools(cloud_media)}",
+ recommendation=(
+ "Review prompts and local media files before sending them to external "
+ "media providers."
+ ),
+ )
+
+ # scan_chunks / Deep Research knowledge routing is handled in
+ # _audit_knowledge_cloud_composition (needs knowledge.db existence).
+
+ local_access = tools & LOCAL_ACCESS_TOOLS
+ if local_access:
+ builder.add(
+ finding_id="local-access-tools-configured",
+ status="info",
+ title="Local file, shell, or code tools are configured",
+ potential_data_path="local files/process output -> agent context",
+ evidence=f"configured tool(s) = {_format_tools(local_access)}",
+ recommendation=(
+ "Review tool permissions and prompts before giving the agent access "
+ "to sensitive local files or command output."
+ ),
+ )
+
+ mcp_enabled = bool(_get(config, "tools.mcp.enabled", False))
+ mcp_servers = str(_get(config, "tools.mcp.servers", "") or "").strip()
+ if mcp_enabled and mcp_servers:
+ builder.add(
+ finding_id="mcp-servers-configured",
+ status="warn",
+ title="External MCP servers are configured",
+ potential_data_path="agent tool calls/context -> configured MCP servers",
+ evidence="tools.mcp.enabled = true; tools.mcp.servers is non-empty",
+ recommendation=(
+ "Review MCP server trust, transport, and tool schemas before sending "
+ "sensitive prompts or tool arguments."
+ ),
+ )
+
+
+def _iter_local_store_targets(
+ root: Path,
+ config: Any | None,
+) -> Iterable[tuple[str, str, Path, str, Status]]:
+ """Yield store targets as (finding_id, title, path, location_label, status)."""
+ targets: dict[str, tuple[str, Path, str, Status]] = {}
+
+ for finding_id, title, relative_path, status in LOCAL_STORE_CANDIDATES:
+ targets[finding_id] = (title, root / relative_path, relative_path, status)
+
+ if config is not None:
+ for finding_id, title, dotted_path, status in _CONFIG_STORE_PATHS:
+ raw = str(_get(config, dotted_path, "") or "").strip()
+ if not raw:
+ if finding_id == "scheduler-db":
+ path = root / "scheduler.db"
+ location = "scheduler.db"
+ else:
+ continue
+ else:
+ path = Path(raw).expanduser()
+ if not path.is_absolute():
+ path = root / path
+ try:
+ resolved_path = path.resolve()
+ except OSError:
+ resolved_path = path
+ location = _location_label(resolved_path, root)
+
+ existing = targets.get(finding_id)
+ if existing is not None and existing[1].exists() and not path.exists():
+ continue
+ targets[finding_id] = (title, path, location, status)
+
+ seen_resolved: set[str] = set()
+ for finding_id, (title, path, location, status) in targets.items():
+ try:
+ resolved_key = str(path.resolve())
+ except OSError:
+ resolved_key = str(path)
+ if resolved_key in seen_resolved:
+ continue
+ seen_resolved.add(resolved_key)
+ yield finding_id, title, path, location, status
+
+
+def _audit_local_stores(
+ root: Path,
+ builder: _FindingBuilder,
+ *,
+ config: Any | None = None,
+) -> None:
+ if not root.exists():
+ return
+ for finding_id, title, path, location, status in _iter_local_store_targets(
+ root,
+ config,
+ ):
+ if not path.exists():
+ continue
+ builder.add(
+ finding_id=f"local-store-{finding_id}",
+ status=status,
+ title=f"{title} exists locally",
+ potential_data_path=f"local runtime state -> {location}",
+ evidence=f"path exists: {location}",
+ recommendation=(
+ "Review retention, backups, and filesystem permissions for this "
+ "local store."
+ ),
+ location=location,
+ absolute_location=str(path),
+ )
+ permission_note = _permission_note(path)
+ if permission_note:
+ builder.add(
+ finding_id=f"local-store-permissions-{finding_id}",
+ status="warn",
+ title=f"{title} permissions need review",
+ potential_data_path=f"local runtime state -> {location}",
+ evidence=permission_note,
+ recommendation=(
+ "Restrict this file or directory to the current user before "
+ "storing sensitive data."
+ ),
+ location=location,
+ absolute_location=str(path),
+ )
+
+
+def _audit_connector_credentials(root: Path, builder: _FindingBuilder) -> None:
+ connectors_dir = root / "connectors"
+ if not connectors_dir.exists():
+ return
+ for path in sorted(connectors_dir.glob("*.json")):
+ digest = hashlib.sha256(path.name.encode("utf-8")).hexdigest()[:8]
+ builder.add(
+ finding_id=f"connector-token-{digest}",
+ status="info",
+ title="Connector credential file is present",
+ potential_data_path="connector OAuth/API credentials -> local file",
+ evidence="credential file exists under connectors/*.json",
+ recommendation=(
+ "This audit did not read the file contents. Use --show-paths for "
+ "local debugging, and review account scopes and token rotation."
+ ),
+ location="connectors/<redacted>.json",
+ absolute_location=str(path),
+ )
+
+
+def _audit_environment_credentials(
+ config: Any | None,
+ builder: _FindingBuilder,
+ *,
+ active_tools: set[str],
+) -> None:
+ active_values: set[str] = set(active_tools)
+ if config is not None:
+ active_values.update(
+ {
+ str(_get(config, "intelligence.provider", "")).lower(),
+ str(_get(config, "intelligence.preferred_engine", "")).lower(),
+ str(_get(config, "engine.default", "")).lower(),
+ str(_get(config, "intelligence.default_model", "")).lower(),
+ str(_get(config, "speech.backend", "")).lower(),
+ }
+ )
+ if bool(_get(config, "digest.enabled", False)):
+ active_values.add(str(_get(config, "digest.tts_backend", "")).lower())
+
+ for env_name, (purpose, aliases) in sorted(API_KEY_ENV_VARS.items()):
+ if not os.environ.get(env_name):
+ continue
+ active = any(alias in value for alias in aliases for value in active_values)
+ status: Status = "warn" if active else "info"
+ builder.add(
+ finding_id=f"env-credential-{env_name.lower()}",
+ status=status,
+ title=f"Cloud/API credential available in environment: {env_name}",
+ potential_data_path=f"process environment -> {purpose}",
+ evidence=f"{env_name} is set; value was not read or printed",
+ recommendation=(
+ "Unset this variable for local-only operation. The audit reports "
+ "only presence and never prints credential values."
+ ),
+ )
+
+
+def _audit_server_exposure(config: Any, builder: _FindingBuilder) -> None:
+ host = str(_get(config, "server.host", "") or "").strip()
+ if not _is_loopback_host(host):
+ binds_all = host in {"0.0.0.0", "::"}
+ builder.add(
+ finding_id=(
+ "server-binds-all-interfaces"
+ if binds_all
+ else "server-binds-non-loopback-interface"
+ ),
+ status="warn",
+ title=(
+ "Server is configured to bind all network interfaces"
+ if binds_all
+ else "Server is configured to bind a non-loopback interface"
+ ),
+ potential_data_path="OpenJarvis HTTP server -> local network interfaces",
+ evidence=f"server.host = {_quote(host)}",
+ recommendation=(
+ "Use server.host = '127.0.0.1' unless LAN exposure is intentional."
+ ),
+ )
+
+ a2a_enabled = bool(_get(config, "a2a.enabled", False))
+ a2a_token = str(_get(config, "a2a.auth_token", "") or "")
+ if a2a_enabled and not a2a_token:
+ builder.add(
+ finding_id="a2a-enabled-without-auth-token",
+ status="fail",
+ title="A2A server is enabled without an auth token",
+ potential_data_path="inbound A2A requests -> OpenJarvis agent runtime",
+ evidence="a2a.enabled = true; a2a.auth_token is empty",
+ recommendation=(
+ "Set a2a.auth_token or disable A2A unless the network is trusted."
+ ),
+ )
+
+
+def _audit_channel_settings(config: Any, builder: _FindingBuilder) -> None:
+ channel_enabled = bool(_get(config, "channel.enabled", False))
+ default_channel = str(_get(config, "channel.default_channel", "") or "")
+ configured_secrets = _non_empty_paths(config, CHANNEL_SECRET_FIELDS)
+ configured_refs = _non_empty_paths(config, CHANNEL_REFERENCE_FIELDS)
+
+ if channel_enabled:
+ evidence = "channel.enabled = true"
+ if default_channel:
+ evidence += "; channel.default_channel is set; value redacted"
+ has_channel_surface = bool(
+ default_channel or configured_secrets or configured_refs
+ )
+ status: Status = "warn" if has_channel_surface else "info"
+ builder.add(
+ finding_id="channels-enabled",
+ status=status,
+ title="Messaging channels are enabled",
+ potential_data_path=(
+ "user messages and assistant replies -> configured channel services"
+ ),
+ evidence=evidence,
+ recommendation=(
+ "Review active channel credentials and account scopes before "
+ "routing sensitive conversations through external services."
+ ),
+ )
+
+ for dotted_path, label, service in configured_secrets:
+ status = "warn" if channel_enabled else "info"
+ normalized = dotted_path.replace(".", "-").replace("_", "-")
+ builder.add(
+ finding_id=f"channel-secret-{normalized}",
+ status=status,
+ title=f"Channel secret configured: {label}",
+ potential_data_path=f"OpenJarvis channel messages -> {service}",
+ evidence=f"{dotted_path} is non-empty; value was not printed",
+ recommendation=(
+ "Use dedicated bot/service credentials and rotate them after tests. "
+ "The audit reports only presence and never prints secret values."
+ ),
+ )
+
+ for dotted_path, label, service in configured_refs:
+ status = "warn" if channel_enabled else "info"
+ normalized = dotted_path.replace(".", "-").replace("_", "-")
+ builder.add(
+ finding_id=f"channel-reference-{normalized}",
+ status=status,
+ title=f"Channel endpoint or identifier configured: {label}",
+ potential_data_path=f"OpenJarvis channel messages -> {service}",
+ evidence=f"{dotted_path} is non-empty; value was not printed",
+ recommendation=(
+ "Review configured channel endpoints and identifiers before "
+ "routing sensitive conversations through external services."
+ ),
+ )
+
+
+def _audit_channel_environment_credentials(
+ config: Any | None,
+ builder: _FindingBuilder,
+) -> None:
+ channel_enabled = bool(_get(config, "channel.enabled", False)) if config else False
+ for env_name, purpose in sorted(CHANNEL_SECRET_ENV_VARS.items()):
+ if not os.environ.get(env_name):
+ continue
+ status: Status = "warn" if channel_enabled else "info"
+ builder.add(
+ finding_id=f"channel-env-secret-{env_name.lower()}",
+ status=status,
+ title=f"Channel secret available in environment: {env_name}",
+ potential_data_path=f"process environment -> {purpose}",
+ evidence=f"{env_name} is set; value was not read or printed",
+ recommendation=(
+ "Unset channel secrets when external messaging is not in use. "
+ "The audit reports only presence and never prints secret values."
+ ),
+ )
+
+ for env_name, purpose in sorted(CHANNEL_REFERENCE_ENV_VARS.items()):
+ if not os.environ.get(env_name):
+ continue
+ status = "warn" if channel_enabled else "info"
+ builder.add(
+ finding_id=f"channel-env-reference-{env_name.lower()}",
+ status=status,
+ title=f"Channel endpoint or identifier in environment: {env_name}",
+ potential_data_path=f"process environment -> {purpose}",
+ evidence=f"{env_name} is set; value was not read or printed",
+ recommendation=(
+ "Unset channel endpoint variables when external messaging is not "
+ "in use. The audit reports only presence."
+ ),
+ )
+
+
+def _audit_local_channel_credential_dirs(
+ config: Any,
+ root: Path,
+ builder: _FindingBuilder,
+) -> None:
+ auth_dir_value = str(
+ _get(config, "channel.whatsapp_baileys.auth_dir", "") or ""
+ ).strip()
+ candidates: list[tuple[Path, str]] = []
+ if auth_dir_value:
+ candidates.append((Path(auth_dir_value).expanduser(), "<redacted>"))
+ candidates.append(
+ (root / "whatsapp_baileys_bridge" / "auth", "whatsapp_baileys_bridge/auth")
+ )
+
+ seen_resolved: set[str] = set()
+ for path, location in candidates:
+ try:
+ resolved = path.resolve()
+ resolved_key = str(resolved)
+ except OSError:
+ resolved = path
+ resolved_key = str(path)
+ if resolved_key in seen_resolved or not path.exists():
+ continue
+ seen_resolved.add(resolved_key)
+ path_digest = hashlib.sha256(resolved_key.encode("utf-8")).hexdigest()[:8]
+ builder.add(
+ finding_id=f"channel-local-credential-dir-whatsapp-baileys-{path_digest}",
+ status="info",
+ title="WhatsApp Baileys credential directory is present",
+ potential_data_path="WhatsApp session credentials -> local directory",
+ evidence="credential directory exists; contents were not inspected",
+ recommendation=(
+ "Review permissions and retention for local messaging session "
+ "credentials."
+ ),
+ location=location,
+ absolute_location=resolved_key,
+ )
+
+
+def _audit_frontend_storage_scope(builder: _FindingBuilder) -> None:
+ builder.add(
+ finding_id="frontend-credential-storage-not-inspected",
+ status="info",
+ title="Frontend credential storage is outside this CLI scan",
+ potential_data_path="desktop/web frontend storage -> cloud API keys",
+ evidence="CLI scan cannot inspect browser localStorage or Tauri storage",
+ recommendation=(
+ "Review frontend credential-storage work separately. This finding is "
+ "a scope note for cloud/API-key deployments, not a detected leak."
+ ),
+ )
+
+
+def _audit_generic_runtime_credentials(builder: _FindingBuilder) -> None:
+ """Report presence-only findings for remaining TOOL_CREDENTIALS env keys."""
+ for env_name in sorted(GENERIC_CREDENTIAL_ENV_VARS):
+ if not os.environ.get(env_name):
+ continue
+ builder.add(
+ finding_id=f"env-credential-generic-{env_name.lower()}",
+ status="info",
+ title=f"Runtime credential available in environment: {env_name}",
+ potential_data_path=f"process environment -> {env_name}",
+ evidence=f"{env_name} is set; value was not read or printed",
+ recommendation=(
+ "Unset unused runtime credentials. The audit reports only presence "
+ "and never prints credential values."
+ ),
+ )
+
+
+def _audit_skills_and_digest(config: Any, builder: _FindingBuilder) -> None:
+ if bool(_get(config, "skills.enabled", False)):
+ builder.add(
+ finding_id="skills-enabled",
+ status="info",
+ title="Skills are enabled",
+ potential_data_path="agent-selected skills -> local files and tools",
+ evidence="skills.enabled = true",
+ recommendation=(
+ "Review installed skills, especially skills with file, shell, "
+ "browser, or network access."
+ ),
+ )
+
+ if bool(_get(config, "skills.auto_sync", False)):
+ builder.add(
+ finding_id="skills-auto-sync-enabled",
+ status="warn",
+ title="Skill auto-sync is enabled",
+ potential_data_path="configured skill source -> local skill directory",
+ evidence="skills.auto_sync = true",
+ recommendation="Review external skill sources before enabling auto-sync.",
+ )
+
+ if bool(_get(config, "digest.enabled", False)):
+ sources = sorted(set(_iter_digest_sources(config)) & PERSONAL_DIGEST_SOURCES)
+ builder.add(
+ finding_id="digest-enabled",
+ status="warn",
+ title="Morning digest is enabled",
+ potential_data_path="personal connectors -> digest generation context",
+ evidence=(
+ "digest.enabled = true; sources = "
+ + (", ".join(sources) or "configured sections")
+ ),
+ recommendation=(
+ "Review digest sources and connector scopes before enabling "
+ "personal-data digests."
+ ),
+ )
+
+
+def _audit_speech_settings(config: Any, builder: _FindingBuilder) -> None:
+ speech_backend = str(_get(config, "speech.backend", "") or "").lower()
+ if speech_backend in {"openai", "deepgram"}:
+ builder.add(
+ finding_id="cloud-speech-backend-configured",
+ status="warn",
+ title="Cloud speech backend configured",
+ potential_data_path="speech audio or transcripts -> cloud speech provider",
+ evidence=f"speech.backend = {_quote(speech_backend)}",
+ recommendation=(
+ "Use a local speech backend for local-only audio processing."
+ ),
+ )
+
+ digest_enabled = bool(_get(config, "digest.enabled", False))
+ tts_backend = str(_get(config, "digest.tts_backend", "") or "").lower()
+ if digest_enabled and tts_backend in CLOUD_TTS_BACKENDS:
+ builder.add(
+ finding_id="cloud-tts-backend-configured",
+ status="warn",
+ title="Cloud text-to-speech backend configured for digests",
+ potential_data_path=(
+ "personal digest narrative -> cloud text-to-speech provider"
+ ),
+ evidence=f"digest.tts_backend = {_quote(tts_backend)}",
+ recommendation=(
+ "Use a local text-to-speech backend or disable digest audio when "
+ "the generated narrative contains sensitive personal data."
+ ),
+ )
+
+
+def _has_cloud_api_surface(config: Any | None, active_tools: set[str]) -> bool:
+ """True when cloud inference/API-key surfaces are configured (not browser-only)."""
+ if any(os.environ.get(name) for name in API_KEY_ENV_VARS):
+ return True
+ if active_tools & CLOUD_API_SURFACES:
+ return True
+ if config is None:
+ return False
+ if _primary_cloud_signals(config):
+ return True
+ deep_engine, deep_model = _effective_deep_research_target(config)
+ if _target_is_cloud(deep_engine, deep_model):
+ return True
+ optimizer_provider = _get(config, "optimize.optimizer_provider", "")
+ if _target_is_cloud(optimizer_provider, _get(config, "optimize.judge_model", "")):
+ return True
+ if str(_get(config, "speech.backend", "") or "").lower() in {
+ "openai",
+ "deepgram",
+ }:
+ return True
+ if (
+ bool(_get(config, "digest.enabled", False))
+ and str(_get(config, "digest.tts_backend", "") or "").lower()
+ in CLOUD_TTS_BACKENDS
+ ):
+ return True
+ if bool(_get(config, "learning.spec_search.enabled", False)):
+ return _target_is_cloud(
+ _get(config, "learning.spec_search.teacher_engine", ""),
+ _get(config, "learning.spec_search.teacher_model", ""),
+ )
+ return False
+
+
+def _has_external_surface(config: Any | None, active_tools: set[str]) -> bool:
+ """True when external egress or cloud/API surfaces are present."""
+ if active_tools & EXTERNAL_TOOL_SURFACES:
+ return True
+ if (
+ _scan_chunks_surface_active(config, active_tools)
+ if config is not None
+ else False
+ ):
+ return True
+ return _has_cloud_api_surface(config, active_tools)
+
+
+def _has_cloud_or_api_surface(config: Any | None, active_tools: set[str]) -> bool:
+ """Backward-compatible alias for external-or-cloud surface detection."""
+ return _has_external_surface(config, active_tools)
+
+
+def _derive_verdict(findings: Iterable[DataBoundaryFinding]) -> str:
+ finding_ids = {finding.id for finding in findings}
+ statuses = {finding.status for finding in findings}
+
+ if "memory-context-to-cloud-risk" in finding_ids:
+ return "local memory may be sent to cloud inference"
+ if "knowledge-chunks-to-cloud-risk" in finding_ids:
+ return "local knowledge may be sent to cloud inference"
+ if "config-root-error" in finding_ids:
+ return "OpenJarvis home must be fixed before full data-boundary review"
+ if "config-load-error" in finding_ids:
+ return "configuration must be fixed before full data-boundary review"
+ if "fail" in statuses:
+ return "attention required for application data boundaries"
+ if any(
+ fid in finding_ids
+ for fid in {
+ "cloud-provider-configured",
+ "cloud-preferred-engine-configured",
+ "cloud-default-engine-configured",
+ "cloud-default-model-configured",
+ "cloud-speech-backend-configured",
+ "cloud-tts-backend-configured",
+ "deep-research-cloud-configured",
+ }
+ ):
+ return "cloud-capable data boundaries configured"
+ if "warn" in statuses:
+ return "local sensitive stores or optional data flows detected"
+ return "no fail or warn findings detected"
+
+
+def _configured_tools(config: Any) -> set[str]:
+ values: list[Any] = [
+ _get(config, "tools.enabled", ""),
+ _get(config, "agent.tools", ""),
+ ]
+ tools: set[str] = set()
+ for value in values:
+ if isinstance(value, str):
+ raw_items = value.split(",")
+ elif isinstance(value, Iterable):
+ raw_items = list(value)
+ else:
+ raw_items = []
+ for item in raw_items:
+ normalized = str(item).strip().lower().replace("-", "_")
+ if normalized:
+ tools.add(normalized)
+ return tools
+
+
+def _get(obj: Any, dotted_path: str, default: Any = None) -> Any:
+ current = obj
+ for part in dotted_path.split("."):
+ if current is None:
+ return default
+ current = getattr(current, part, default)
+ return current
+
+
+def _is_cloud_value(value: Any) -> bool:
+ if value is None:
+ return False
+ text = str(value).strip().lower()
+ if not text or text in LOCAL_ENGINE_KEYS:
+ return False
+ return any(key in text for key in CLOUD_PROVIDER_KEYS)
+
+
+def _is_local_engine_value(value: Any) -> bool:
+ if value is None:
+ return False
+ text = str(value).strip().lower().replace("-", "_")
+ return text in LOCAL_ENGINE_KEYS
+
+
+def _target_is_cloud(engine: Any, model: Any) -> bool:
+ """Classify a model target without treating local vendor model IDs as cloud."""
+ if _is_cloud_value(engine):
+ return True
+ if _is_local_engine_value(engine):
+ return False
+ return _looks_like_cloud_model(model)
+
+
+def _primary_cloud_signals(config: Any) -> list[str]:
+ """Return explicit cloud signals for the primary inference target."""
+ provider = _get(config, "intelligence.provider", "")
+ preferred_engine = _get(config, "intelligence.preferred_engine", "")
+ default_engine = _get(config, "engine.default", "")
+ default_model = _get(config, "intelligence.default_model", "")
+ signals = [
+ str(value)
+ for value in (provider, preferred_engine, default_engine)
+ if _is_cloud_value(value)
+ ]
+ effective_engine = _first_nonempty(preferred_engine, default_engine, provider)
+ if not signals and _target_is_cloud(effective_engine, default_model):
+ signals.append(str(default_model))
+ return signals
+
+
+def _looks_like_cloud_model(value: Any) -> bool:
+ if value is None:
+ return False
+ text = str(value).strip().lower()
+ if not text:
+ return False
+ return any(key in text for key in CLOUD_PROVIDER_KEYS) or text.startswith("gpt-")
+
+
+def _is_loopback_host(host: str) -> bool:
+ if host in {"", "localhost"}:
+ return True
+ try:
+ import ipaddress
+
+ return ipaddress.ip_address(host).is_loopback
+ except ValueError:
+ return False
+
+
+def _iter_digest_sources(config: Any) -> Iterable[str]:
+ digest = _get(config, "digest", None)
+ if digest is None:
+ return []
+ sections = _get(digest, "sections", []) or []
+ optional_sections = _get(digest, "optional_sections", []) or []
+ names = list(sections) + list(optional_sections)
+ sources: list[str] = []
+ for name in names:
+ section = getattr(digest, str(name), None)
+ if section is None:
+ continue
+ section_sources = getattr(section, "sources", []) or []
+ sources.extend(str(source) for source in section_sources)
+ return sources
+
+
+def _non_empty_paths(
+ config: Any,
+ fields: tuple[tuple[str, str, str], ...],
+) -> list[tuple[str, str, str]]:
+ results: list[tuple[str, str, str]] = []
+ for dotted_path, label, service in fields:
+ value = _get(config, dotted_path, "")
+ if str(value or "").strip():
+ results.append((dotted_path, label, service))
+ return results
+
+
+def _location_label(path: Path, root: Path) -> str:
+ try:
+ return str(path.resolve().relative_to(root.resolve()))
+ except ValueError:
+ return "<redacted>"
+
+
+def _permission_note(path: Path) -> str:
+ try:
+ if path.is_symlink():
+ return "path is a symlink"
+ if os.name == "nt":
+ return ""
+ mode = path.stat().st_mode & 0o777
+ except OSError:
+ return "could not read filesystem metadata"
+ if mode & 0o077:
+ return f"permissions are {mode:03o}; group/other access is present"
+ return ""
+
+
+def _format_tools(tools: Iterable[str]) -> str:
+ return ", ".join(sorted(tools))
+
+
+def _quote(value: Any) -> str:
+ return repr(str(value))
+
+
+def _redact_root(root: str) -> str:
+ if root.startswith("<"):
+ return root
+ path = Path(root)
+ if path.name == ".openjarvis":
+ return "~/.openjarvis"
+ if path.name == "openjarvis":
+ return "<xdg-data-home>/openjarvis"
+ return "<openjarvis-home>"
+
+
+def _truncate(text: str, limit: int = 240) -> str:
+ clean = " ".join(str(text).split())
+ if len(clean) <= limit:
+ return clean
+ return clean[: limit - 1] + "…"
diff --git a/tests/cli/test_scan_data_boundaries.py b/tests/cli/test_scan_data_boundaries.py
new file mode 100644
index 00000000..beed1f88
--- /dev/null
+++ b/tests/cli/test_scan_data_boundaries.py
@@ -0,0 +1,396 @@
+from __future__ import annotations
+
+import json
+import os
+import subprocess
+import sys
+from pathlib import Path
+
+from click.testing import CliRunner
+
+from openjarvis.cli.scan_cmd import PrivacyScanner, ScanResult, scan
+from openjarvis.core.config import JarvisConfig
+
+
+def _low_noise_config():
+ """Baseline config with no warn/fail findings under an empty scan root.
+
+ JarvisConfig defaults include absolute store paths under the real
+ OPENJARVIS_HOME; clear those so tests only see artifacts under tmp_path.
+ """
+ config = JarvisConfig()
+ config.analytics.enabled = False
+ config.traces.enabled = False
+ config.telemetry.enabled = False
+ config.agent.context_from_memory = False
+ config.agent.tools = ""
+ config.skills.enabled = False
+ config.digest.enabled = False
+ config.channel.enabled = False
+ config.learning.enabled = False
+ config.learning.training_enabled = False
+ config.learning.auto_update = False
+ config.learning.spec_search.enabled = False
+ config.tools.enabled = ""
+ config.tools.mcp.enabled = False
+ config.tools.storage.enabled = False
+ config.optimize.optimizer_provider = ""
+ config.optimize.judge_model = ""
+ config.server.host = "127.0.0.1"
+ config.security.profile = "personal"
+ # Avoid scanning the developer's real ~/.openjarvis store files.
+ config.traces.db_path = ""
+ config.telemetry.db_path = ""
+ config.security.audit_log_path = ""
+ config.security.vault_key_path = ""
+ config.tools.storage.db_path = ""
+ config.tools.storage.facts_path = ""
+ config.sessions.db_path = ""
+ config.agent_manager.db_path = ""
+ config.optimize.db_path = ""
+ config.scheduler.db_path = ""
+ config.skills.index_dir = ""
+ config.memory_files.soul_path = ""
+ config.memory_files.memory_path = ""
+ config.memory_files.user_path = ""
+ return config
+
+
+def _patch_config(monkeypatch, tmp_path, config, config_loaded=True, error=""):
+ monkeypatch.setattr(
+ "openjarvis.cli.scan_cmd._load_data_boundary_config",
+ lambda: (config, tmp_path, config_loaded, error, ""),
+ )
+ monkeypatch.setattr("openjarvis.cli.scan_cmd.get_config_dir", lambda: tmp_path)
+
+
+def test_scan_data_boundaries_json_redacts_paths(monkeypatch, tmp_path):
+ config = _low_noise_config()
+ (tmp_path / "traces.db").write_text("", encoding="utf-8")
+ _patch_config(monkeypatch, tmp_path, config)
+
+ result = CliRunner().invoke(scan, ["--data-boundaries", "--json"])
+
+ assert result.exit_code == 0
+ payload = json.loads(result.output)
+ assert payload["schema_version"] == 1
+ assert payload["root"] != str(tmp_path.resolve())
+ assert str(tmp_path.resolve()) not in result.output
+ assert "findings" in payload
+
+
+def test_scan_data_boundaries_show_paths_json(monkeypatch, tmp_path):
+ config = _low_noise_config()
+ trace_db = tmp_path / "traces.db"
+ trace_db.write_text("", encoding="utf-8")
+ _patch_config(monkeypatch, tmp_path, config)
+
+ result = CliRunner().invoke(
+ scan,
+ ["--data-boundaries", "--json", "--show-paths"],
+ )
+
+ assert result.exit_code == 0
+ payload = json.loads(result.output)
+ assert payload["root"] == str(tmp_path.resolve())
+ assert "traces.db" in result.output
+
+
+def test_scan_data_boundaries_handles_config_load_error(monkeypatch, tmp_path):
+ config = _low_noise_config()
+ _patch_config(
+ monkeypatch,
+ tmp_path,
+ config,
+ config_loaded=False,
+ error="TOMLDecodeError: invalid config",
+ )
+
+ result = CliRunner().invoke(scan, ["--data-boundaries", "--json"])
+
+ assert result.exit_code == 0
+ payload = json.loads(result.output)
+ assert payload["summary"]["fail"] == 1
+ assert payload["findings"][0]["id"] == "config-load-error"
+
+
+def test_scan_data_boundaries_strict_exits_nonzero_on_fail(
+ monkeypatch,
+ tmp_path,
+):
+ config = _low_noise_config()
+ config.intelligence.provider = "openai"
+ config.agent.context_from_memory = True
+ _patch_config(monkeypatch, tmp_path, config)
+
+ result = CliRunner().invoke(scan, ["--data-boundaries", "--strict"])
+
+ assert result.exit_code == 1
+ assert "local memory may be sent to cloud inference" in result.output
+
+
+def test_scan_data_boundaries_fail_exits_zero_without_strict(
+ monkeypatch,
+ tmp_path,
+):
+ config = _low_noise_config()
+ config.intelligence.provider = "openai"
+ config.agent.context_from_memory = True
+ _patch_config(monkeypatch, tmp_path, config)
+
+ result = CliRunner().invoke(scan, ["--data-boundaries"])
+
+ assert result.exit_code == 0
+ assert "local memory may be sent to cloud inference" in result.output
+
+
+def test_scan_data_boundaries_strict_exits_on_warning(
+ monkeypatch,
+ tmp_path,
+):
+ config = _low_noise_config()
+ config.tools.enabled = "web_search"
+ _patch_config(monkeypatch, tmp_path, config)
+
+ result = CliRunner().invoke(scan, ["--data-boundaries", "--strict"])
+
+ assert result.exit_code == 1
+ assert "Web search tool is configured" in result.output
+
+
+def test_scan_data_boundaries_strict_passes_with_info_only(
+ monkeypatch,
+ tmp_path,
+):
+ config = _low_noise_config()
+ config.agent.context_from_memory = True
+ _patch_config(monkeypatch, tmp_path, config)
+
+ result = CliRunner().invoke(scan, ["--data-boundaries", "--strict"])
+
+ assert result.exit_code == 0
+ assert "OpenJarvis Data-Boundary Scan" in result.output
+
+
+def test_scan_data_boundaries_init_defaults_strict_exits_on_warn(
+ monkeypatch,
+ tmp_path,
+):
+ config = _low_noise_config()
+ config.server.host = "0.0.0.0"
+ config.telemetry.enabled = True
+ _patch_config(monkeypatch, tmp_path, config)
+
+ result = CliRunner().invoke(scan, ["--data-boundaries", "--strict"])
+
+ assert result.exit_code == 1
+ assert "bind all" in result.output
+
+
+def test_scan_data_boundaries_rejects_quick(monkeypatch, tmp_path):
+ config = _low_noise_config()
+ _patch_config(monkeypatch, tmp_path, config)
+
+ result = CliRunner().invoke(scan, ["--quick", "--data-boundaries"])
+
+ assert result.exit_code != 0
+ assert "cannot be combined" in result.output
+
+
+def test_scan_rejects_strict_without_data_boundaries():
+ result = CliRunner().invoke(scan, ["--strict"])
+
+ assert result.exit_code != 0
+ assert "only supported with --data-boundaries" in result.output
+
+
+def test_existing_scan_json_still_works(monkeypatch):
+ monkeypatch.setattr(
+ PrivacyScanner,
+ "run_all",
+ lambda self: [
+ ScanResult(
+ name="Network Exposure",
+ status="ok",
+ message="No exposed ports.",
+ platform="all",
+ )
+ ],
+ )
+
+ result = CliRunner().invoke(scan, ["--json"])
+
+ assert result.exit_code == 0
+ payload = json.loads(result.output)
+ assert payload[0]["name"] == "Network Exposure"
+ assert payload[0]["status"] == "ok"
+
+
+def test_existing_scan_quick_json_still_works(monkeypatch):
+ monkeypatch.setattr(
+ PrivacyScanner,
+ "run_quick",
+ lambda self: [
+ ScanResult(
+ name="Cloud Sync Agents",
+ status="ok",
+ message="No cloud-sync agents detected.",
+ platform="all",
+ )
+ ],
+ )
+
+ result = CliRunner().invoke(scan, ["--quick", "--json"])
+
+ assert result.exit_code == 0
+ payload = json.loads(result.output)
+ assert payload[0]["name"] == "Cloud Sync Agents"
+
+
+def test_top_level_cli_registers_data_boundary_scan(monkeypatch, tmp_path):
+ from openjarvis.cli import cli
+
+ config = _low_noise_config()
+ _patch_config(monkeypatch, tmp_path, config)
+
+ result = CliRunner().invoke(cli, ["scan", "--data-boundaries", "--json"])
+
+ assert result.exit_code == 0
+ payload = json.loads(result.output)
+ assert payload["schema_version"] == 1
+ assert "summary" in payload
+
+
+def test_top_level_scan_data_boundaries_does_not_check_for_updates(
+ monkeypatch,
+ tmp_path,
+):
+ import sys
+
+ from openjarvis.cli import cli
+ from openjarvis.core.config import JarvisConfig
+
+ called = {"value": False}
+
+ def fake_check_for_updates(_subcommand):
+ called["value"] = True
+
+ monkeypatch.setattr(
+ "openjarvis.cli._version_check.check_for_updates",
+ fake_check_for_updates,
+ )
+ monkeypatch.setattr(
+ "openjarvis.cli.scan_cmd._load_data_boundary_config",
+ lambda: (JarvisConfig(), tmp_path, False, "", ""),
+ )
+ monkeypatch.setattr(
+ sys,
+ "argv",
+ ["jarvis", "scan", "--data-boundaries", "--json"],
+ )
+
+ result = CliRunner().invoke(cli, ["scan", "--data-boundaries", "--json"])
+
+ assert result.exit_code == 0
+ assert called["value"] is False
+
+
+def test_update_check_skip_helper_is_precise():
+ from click import Command, Context
+
+ from openjarvis.cli import _should_skip_update_check
+
+ ctx = Context(Command("jarvis"))
+ ctx.invoked_subcommand = "scan"
+ assert _should_skip_update_check(ctx, ["scan", "--data-boundaries"])
+
+ ctx.invoked_subcommand = "ask"
+ assert not _should_skip_update_check(ctx, ["ask", "scan", "--data-boundaries"])
+
+
+def test_existing_scan_quick_text_still_works(monkeypatch):
+ monkeypatch.setattr(
+ PrivacyScanner,
+ "run_quick",
+ lambda self: [
+ ScanResult(
+ name="Cloud Sync Agents",
+ status="ok",
+ message="No cloud-sync agents detected.",
+ platform="all",
+ )
+ ],
+ )
+
+ result = CliRunner().invoke(scan, ["--quick"])
+
+ assert result.exit_code == 0
+ assert "OpenJarvis Security Scan" in result.output
+
+
+def test_data_boundary_loader_honors_openjarvis_config(
+ monkeypatch,
+ tmp_path,
+):
+ from openjarvis.cli import scan_cmd
+ from openjarvis.core.config import load_config
+
+ config_path = tmp_path / "custom.toml"
+ config_path.write_text(
+ "[telemetry]\nenabled = false\n",
+ encoding="utf-8",
+ )
+ monkeypatch.setenv("OPENJARVIS_CONFIG", str(config_path))
+ monkeypatch.setenv("OPENJARVIS_HOME", str(tmp_path / "home"))
+ load_config.cache_clear()
+
+ _config, _root, loaded, error, root_error = scan_cmd._load_data_boundary_config()
+
+ assert loaded is True
+ assert error == ""
+ assert root_error == ""
+
+
+def test_data_boundary_loader_reports_root_error(monkeypatch):
+ from openjarvis.cli import scan_cmd
+
+ monkeypatch.setattr(
+ "openjarvis.cli.scan_cmd.get_config_dir",
+ lambda: (_ for _ in ()).throw(RuntimeError("bad home")),
+ )
+
+ _config, root, loaded, error, root_error = scan_cmd._load_data_boundary_config()
+
+ assert root is None
+ assert loaded is False
+ assert error == ""
+ assert "bad home" in root_error
+
+
+def test_data_boundary_cli_reports_real_root_error_without_import_crash():
+ repo_root = Path(__file__).resolve().parents[2]
+ invalid_home = repo_root / ".invalid-openjarvis-home"
+ env = os.environ.copy()
+ env["OPENJARVIS_HOME"] = str(invalid_home)
+ env["PYTHONPATH"] = str(repo_root / "src")
+
+ result = subprocess.run(
+ [
+ sys.executable,
+ "-c",
+ "from openjarvis.cli import main; main()",
+ "scan",
+ "--data-boundaries",
+ "--json",
+ ],
+ capture_output=True,
+ text=True,
+ env=env,
+ check=False,
+ )
+
+ assert result.returncode == 0, result.stderr
+ payload = json.loads(result.stdout)
+ assert payload["findings"][0]["id"] == "config-root-error"
+ assert str(invalid_home) not in result.stdout
+ assert str(repo_root) not in result.stdout
diff --git a/tests/security/test_data_boundary_audit.py b/tests/security/test_data_boundary_audit.py
new file mode 100644
index 00000000..5d61c3bc
--- /dev/null
+++ b/tests/security/test_data_boundary_audit.py
@@ -0,0 +1,1303 @@
+from __future__ import annotations
+
+import os
+
+import pytest
+
+from openjarvis.core.config import JarvisConfig, load_config
+from openjarvis.security.data_boundary_audit import (
+ API_KEY_ENV_VARS,
+ BROWSER_TOOLS,
+ CHANNEL_OUTBOUND_TOOLS,
+ CHANNEL_REFERENCE_ENV_VARS,
+ CHANNEL_SECRET_ENV_VARS,
+ CLOUD_MEDIA_TOOLS,
+ EXTERNAL_TOOL_SURFACES,
+ GENERIC_CREDENTIAL_ENV_VARS,
+ GENERIC_NETWORK_TOOLS,
+ KNOWLEDGE_ENGINE_TOOLS,
+ LOCAL_ACCESS_TOOLS,
+ OUTBOUND_TOOL_SURFACES,
+ RUNTIME_CREDENTIAL_ENV_KEYS,
+ WEB_SEARCH_TOOLS,
+ build_data_boundary_report,
+)
+from tests.tools.test_tool_registration import EXPECTED_TOOLS as EXPECTED_BUILTIN_TOOLS
+
+EXPECTED_BROWSER_TOOLS = {
+ "browser_navigate",
+ "browser_click",
+ "browser_type",
+ "browser_screenshot",
+ "browser_extract",
+}
+
+EXPECTED_GENERIC_NETWORK_TOOLS = {"http_request"}
+EXPECTED_CHANNEL_OUTBOUND_TOOLS = {"channel_send"}
+EXPECTED_CLOUD_MEDIA_TOOLS = {
+ "audio_transcribe",
+ "image_generate",
+ "text_to_speech",
+}
+EXPECTED_KNOWLEDGE_ENGINE_TOOLS = {"scan_chunks"}
+
+EXPECTED_LOCAL_ACCESS_TOOLS = {
+ "file_write",
+ "apply_patch",
+ "docker_shell_exec",
+ "db_query",
+ "knowledge_sql",
+ "memory_manage",
+ "repl",
+ "code_interpreter_docker",
+ "git_status",
+ "git_diff",
+ "git_commit",
+ "git_log",
+ "retrieval",
+ "memory_store",
+ "memory_retrieve",
+ "memory_search",
+ "memory_index",
+ "user_profile_manage",
+ "skill_manage",
+ "channel_list",
+ "channel_status",
+ "pdf_extract",
+ "kg_add_entity",
+ "kg_add_relation",
+ "kg_query",
+ "kg_neighbors",
+}
+
+# Built-in tools with no independent data-boundary surface beyond existing
+# provider/engine/channel configuration findings.
+EXPLICITLY_EXEMPT_TOOLS = {
+ # Pure local arithmetic; no file, network, or credential egress.
+ "calculator",
+ # Local scratchpad/reasoning only; content stays in-process.
+ "think",
+ # Routes through the configured intelligence stack already audited via
+ # provider/engine/model findings; classifying here would double-count.
+ "llm",
+}
+
+CLASSIFIED_TOOLS = (
+ WEB_SEARCH_TOOLS
+ | BROWSER_TOOLS
+ | GENERIC_NETWORK_TOOLS
+ | CHANNEL_OUTBOUND_TOOLS
+ | CLOUD_MEDIA_TOOLS
+ | KNOWLEDGE_ENGINE_TOOLS
+ | LOCAL_ACCESS_TOOLS
+)
+
+
+def _ids(report):
+ return {finding.id for finding in report.findings}
+
+
+def _low_noise_config():
+ """Baseline config with no warn/fail findings under an empty scan root.
+
+ JarvisConfig defaults include absolute store paths under the real
+ OPENJARVIS_HOME; clear those so tests only see artifacts under tmp_path.
+ """
+ config = JarvisConfig()
+ config.analytics.enabled = False
+ config.traces.enabled = False
+ config.telemetry.enabled = False
+ config.agent.context_from_memory = False
+ config.agent.tools = ""
+ config.agent.default_agent = "simple"
+ config.skills.enabled = False
+ config.digest.enabled = False
+ config.channel.enabled = False
+ config.learning.enabled = False
+ config.learning.training_enabled = False
+ config.learning.auto_update = False
+ config.learning.spec_search.enabled = False
+ config.learning.spec_search.teacher_engine = ""
+ config.tools.enabled = ""
+ config.tools.mcp.enabled = False
+ config.tools.storage.enabled = False
+ config.optimize.optimizer_provider = ""
+ config.optimize.judge_model = ""
+ config.server.host = "127.0.0.1"
+ config.server.model = ""
+ config.security.profile = "personal"
+ config.intelligence.provider = ""
+ config.intelligence.preferred_engine = ""
+ config.intelligence.default_model = ""
+ config.engine.default = "ollama"
+ config.deep_research.engine = ""
+ config.deep_research.model = ""
+ # Avoid scanning the developer's real ~/.openjarvis store files.
+ config.traces.db_path = ""
+ config.telemetry.db_path = ""
+ config.security.audit_log_path = ""
+ config.security.vault_key_path = ""
+ config.tools.storage.db_path = ""
+ config.tools.storage.facts_path = ""
+ config.sessions.db_path = ""
+ config.agent_manager.db_path = ""
+ config.optimize.db_path = ""
+ config.scheduler.db_path = ""
+ config.skills.index_dir = ""
+ config.memory_files.soul_path = ""
+ config.memory_files.memory_path = ""
+ config.memory_files.user_path = ""
+ return config
+
+
+def test_missing_config_does_not_report_dataclass_defaults(tmp_path, monkeypatch):
+ monkeypatch.delenv("OPENAI_API_KEY", raising=False)
+ config = JarvisConfig()
+
+ report = build_data_boundary_report(config, tmp_path, config_loaded=False)
+
+ assert report.config_loaded is False
+ assert "config-file-missing" in _ids(report)
+ assert "analytics-enabled" not in _ids(report)
+ assert "traces-enabled" not in _ids(report)
+
+
+def test_config_error_returns_fail_finding_without_crashing(tmp_path):
+ config = JarvisConfig()
+
+ report = build_data_boundary_report(
+ config,
+ tmp_path,
+ config_loaded=False,
+ config_error="TOMLDecodeError: invalid config",
+ )
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert report.config_loaded is False
+ assert findings["config-load-error"].status == "fail"
+ assert "configuration must be fixed" in report.verdict
+
+
+def test_memory_context_injection_is_info_without_cloud(tmp_path):
+ config = _low_noise_config()
+ config.agent.context_from_memory = True
+ config.intelligence.provider = ""
+ config.engine.default = "ollama"
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["memory-context-injection-enabled"].status == "info"
+ assert report.verdict == "no fail or warn findings detected"
+
+
+def test_memory_plus_cloud_provider_is_fail(tmp_path):
+ config = _low_noise_config()
+ config.agent.context_from_memory = True
+ config.intelligence.provider = "openai"
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["memory-context-to-cloud-risk"].status == "fail"
+ assert report.verdict == "local memory may be sent to cloud inference"
+
+
+ "model",
+ ["deepseek-r1:7b", "google/gemma-3-4b-it", "openai/gpt-oss-20b"],
+)
+def test_local_engine_vendor_model_names_are_not_cloud(tmp_path, model):
+ config = _low_noise_config()
+ config.engine.default = "ollama"
+ config.intelligence.default_model = model
+ config.agent.context_from_memory = True
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert "cloud-default-model-configured" not in findings
+ assert "memory-context-to-cloud-risk" not in findings
+ assert "frontend-credential-storage-not-inspected" not in findings
+ assert findings["memory-context-injection-enabled"].status == "info"
+
+
+def test_analytics_is_info_and_does_not_assert_prompt_capture(tmp_path):
+ config = _low_noise_config()
+ config.analytics.enabled = True
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ finding = findings["analytics-enabled"]
+ assert finding.status == "info"
+ assert "does not assert" in finding.recommendation
+
+
+def test_traces_enabled_flags_capture_setting(tmp_path):
+ config = _low_noise_config()
+ config.traces.enabled = True
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["traces-enabled"].status == "warn"
+ assert "traces database" in findings["traces-enabled"].potential_data_path
+
+
+def test_telemetry_enabled_flags_capture_setting(tmp_path):
+ config = _low_noise_config()
+ config.telemetry.enabled = True
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["telemetry-enabled"].status == "warn"
+ assert "telemetry.enabled = true" in findings["telemetry-enabled"].evidence
+
+
+def test_trace_database_presence_redacts_and_shows_paths(tmp_path):
+ config = _low_noise_config()
+ (tmp_path / "traces.db").write_text("", encoding="utf-8")
+
+ report = build_data_boundary_report(config, tmp_path)
+ payload = report.to_dict()
+ payload_with_paths = report.to_dict(show_paths=True)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["local-store-traces-db"].status == "warn"
+ assert payload["schema_version"] == 1
+ assert str(tmp_path) not in str(payload)
+ assert "traces.db" in str(payload_with_paths)
+ assert findings["local-store-traces-db"].absolute_location.endswith("traces.db")
+
+
+def test_custom_traces_db_path_is_audited(tmp_path):
+ config = _low_noise_config()
+ custom_db = tmp_path / "custom" / "traces.db"
+ custom_db.parent.mkdir()
+ custom_db.write_text("", encoding="utf-8")
+ config.traces.db_path = str(custom_db)
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["local-store-traces-db"].status == "warn"
+ assert str(custom_db) in findings["local-store-traces-db"].absolute_location
+
+
+def test_connector_json_basename_redacted_by_default(tmp_path):
+ config = _low_noise_config()
+ connector_dir = tmp_path / "connectors"
+ connector_dir.mkdir()
+ token_file = connector_dir / "alice-personal-gmail.json"
+ token_file.write_text('{"refresh_token":"secret-value"}', encoding="utf-8")
+
+ report = build_data_boundary_report(config, tmp_path)
+ redacted = report.to_dict()
+ shown = report.to_dict(show_paths=True)
+
+ assert "alice-personal-gmail" not in str(redacted)
+ assert "secret-value" not in str(shown)
+ assert token_file.name in str(shown)
+
+
+def test_spec_search_cloud_teacher_is_fail_only_when_enabled(tmp_path):
+ config = _low_noise_config()
+ config.learning.spec_search.enabled = False
+ config.learning.spec_search.teacher_engine = "cloud"
+
+ disabled_report = build_data_boundary_report(config, tmp_path)
+ assert "spec-search-cloud-teacher-enabled" not in _ids(disabled_report)
+
+ config.learning.spec_search.enabled = True
+ enabled_report = build_data_boundary_report(config, tmp_path)
+ findings = {finding.id: finding for finding in enabled_report.findings}
+ assert findings["spec-search-cloud-teacher-enabled"].status == "fail"
+
+
+def test_web_search_tool_and_tavily_env_are_correlated(
+ tmp_path,
+ monkeypatch,
+):
+ config = _low_noise_config()
+ config.tools.enabled = "web_search"
+ monkeypatch.setenv("TAVILY_API_KEY", "secret-value")
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["web-search-tool-configured"].status == "warn"
+ assert findings["env-credential-tavily_api_key"].status == "warn"
+ assert "secret-value" not in str(report.to_dict(show_paths=True))
+
+
+def test_mcp_servers_are_flagged_when_non_empty(tmp_path):
+ config = _low_noise_config()
+ config.tools.mcp.enabled = True
+ config.tools.mcp.servers = '[{"name":"external"}]'
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["mcp-servers-configured"].status == "warn"
+
+
+def test_local_file_shell_and_code_tools_are_info(tmp_path):
+ config = _low_noise_config()
+ config.tools.enabled = ["file_read", "shell_exec", "code_interpreter"]
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["local-access-tools-configured"].status == "info"
+
+
+def test_google_env_warns_when_gemini_provider_active(tmp_path, monkeypatch):
+ config = _low_noise_config()
+ config.intelligence.provider = "gemini"
+ monkeypatch.setenv("GOOGLE_API_KEY", "secret-key")
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["env-credential-google_api_key"].status == "warn"
+
+
+def test_environment_credentials_report_presence_only(tmp_path, monkeypatch):
+ config = _low_noise_config()
+ monkeypatch.setenv("OPENAI_API_KEY", "secret-key")
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ finding = findings["env-credential-openai_api_key"]
+ assert finding.status == "info"
+ assert "OPENAI_API_KEY is set" in finding.evidence
+ assert "secret-key" not in str(report.to_dict(show_paths=True))
+
+
+def test_server_all_interfaces_is_warn(tmp_path):
+ config = _low_noise_config()
+ config.server.host = "0.0.0.0"
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["server-binds-all-interfaces"].status == "warn"
+
+
[email protected]("host", ["192.168.1.50", "203.0.113.5"])
+def test_server_non_loopback_interface_is_warn(tmp_path, host):
+ config = _low_noise_config()
+ config.server.host = host
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ finding = findings["server-binds-non-loopback-interface"]
+ assert finding.status == "warn"
+ assert host in finding.evidence
+
+
+def test_a2a_without_auth_token_is_fail(tmp_path):
+ config = _low_noise_config()
+ config.a2a.enabled = True
+ config.a2a.auth_token = ""
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["a2a-enabled-without-auth-token"].status == "fail"
+
+
+def test_report_json_shape_is_stable(tmp_path, monkeypatch):
+ monkeypatch.delenv("OPENAI_API_KEY", raising=False)
+ config = _low_noise_config()
+
+ report = build_data_boundary_report(config, tmp_path)
+ payload = report.to_dict()
+
+ assert set(payload) == {
+ "schema_version",
+ "verdict",
+ "root",
+ "config_loaded",
+ "summary",
+ "findings",
+ }
+ assert payload["schema_version"] == 1
+ assert set(payload["summary"]) == {"fail", "warn", "info"}
+ assert isinstance(payload["findings"], list)
+
+
+def test_channel_enabled_and_credentials_are_flagged(tmp_path):
+ config = _low_noise_config()
+ config.channel.enabled = True
+ config.channel.telegram.bot_token = "telegram-secret"
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["channels-enabled"].status == "warn"
+ channel_finding = findings["channel-secret-channel-telegram-bot-token"]
+ assert channel_finding.status == "warn"
+ assert "telegram-secret" not in str(report.to_dict(show_paths=True))
+
+
+def test_channel_reference_fields_are_flagged(tmp_path):
+ config = _low_noise_config()
+ config.channel.matrix.homeserver = "https://matrix.example.org"
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ ref = findings["channel-reference-channel-matrix-homeserver"]
+ assert ref.status == "info"
+ assert "Matrix homeserver" in ref.title
+
+
+def test_channel_env_credential_presence_only(tmp_path, monkeypatch):
+ config = _low_noise_config()
+ monkeypatch.setenv("SLACK_BOT_TOKEN", "slack-secret")
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ finding = findings["channel-env-secret-slack_bot_token"]
+ assert finding.status == "info"
+ assert "SLACK_BOT_TOKEN is set" in finding.evidence
+ assert "slack-secret" not in str(report.to_dict(show_paths=True))
+
+
+def test_cloud_speech_backend_is_warn(tmp_path):
+ config = _low_noise_config()
+ config.speech.backend = "openai"
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["cloud-speech-backend-configured"].status == "warn"
+
+
+def test_cartesia_digest_tts_and_credential_are_reported_without_leak(
+ tmp_path,
+ monkeypatch,
+):
+ config = _low_noise_config()
+ config.digest.enabled = True
+ config.digest.tts_backend = "cartesia"
+ monkeypatch.setenv("CARTESIA_API_KEY", "secret-cartesia-key")
+
+ report = build_data_boundary_report(config, tmp_path)
+ payload = report.to_dict(show_paths=True)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["cloud-tts-backend-configured"].status == "warn"
+ credential = findings["env-credential-cartesia_api_key"]
+ assert credential.status == "warn"
+ assert "CARTESIA_API_KEY is set" in credential.evidence
+ assert "secret-cartesia-key" not in str(payload)
+ assert report.verdict == "cloud-capable data boundaries configured"
+
+
+def test_skills_auto_sync_is_warn(tmp_path):
+ config = _low_noise_config()
+ config.skills.auto_sync = True
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["skills-auto-sync-enabled"].status == "warn"
+
+
+def test_digest_enabled_is_warn(tmp_path):
+ config = _low_noise_config()
+ config.digest.enabled = True
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["digest-enabled"].status == "warn"
+
+
+def test_memory_service_enabled_warns_with_cloud_engine(tmp_path):
+ config = _low_noise_config()
+ config.tools.storage.enabled = True
+ config.intelligence.provider = "openai"
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ finding = findings["memory-service-enabled"]
+ assert finding.status == "warn"
+ assert "cloud inference surface detected" in finding.evidence
+
+
+def test_default_model_cloud_detection(tmp_path):
+ config = _low_noise_config()
+ config.engine.default = "openai"
+ config.intelligence.default_model = "gpt-4o"
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["cloud-default-model-configured"].status == "warn"
+
+
+def test_deep_research_cloud_engine_and_model(tmp_path):
+ config = _low_noise_config()
+ config.deep_research.engine = "openai"
+ config.deep_research.model = "gpt-4o-mini"
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["deep-research-cloud-configured"].status == "warn"
+ assert "deep_research.engine" in findings["deep-research-cloud-configured"].evidence
+ assert "deep_research.model" in findings["deep-research-cloud-configured"].evidence
+
+
+def test_security_bypass_warns_with_cloud_surface(tmp_path):
+ config = _low_noise_config()
+ config.intelligence.provider = "openai"
+ config.security.local_engine_bypass = True
+ config.security.local_tool_bypass = True
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["security-local-engine-bypass-enabled"].status == "warn"
+ assert findings["security-local-tool-bypass-enabled"].status == "warn"
+
+
+def test_security_profile_unset_is_info(tmp_path):
+ config = _low_noise_config()
+ config.security.profile = ""
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["security-profile-unset"].status == "info"
+ assert "security.profile" in findings["security-profile-unset"].recommendation
+
+
+def test_frontend_scope_note_appears_with_cloud_api_surface(
+ tmp_path,
+ monkeypatch,
+):
+ config = _low_noise_config()
+ monkeypatch.setenv("OPENAI_API_KEY", "secret-key")
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ assert "frontend-credential-storage-not-inspected" in _ids(report)
+
+
+def test_config_root_error_returns_fail_without_local_store_scan(tmp_path):
+ config = _low_noise_config()
+
+ report = build_data_boundary_report(
+ config,
+ None,
+ root_error=(
+ "ConfigurationError: bad OPENJARVIS_HOME at /Users/alice/private/openjarvis"
+ ),
+ )
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["config-root-error"].status == "fail"
+ assert "bad OPENJARVIS_HOME" not in findings["config-root-error"].evidence
+ assert "/Users/alice/private/openjarvis" not in str(report.to_dict())
+ assert "path details were redacted" in findings["config-root-error"].evidence
+ assert report.root == "<unresolved-openjarvis-home>"
+
+
+def test_group_or_other_readable_local_store_warns(tmp_path):
+ if os.name == "nt":
+ import pytest
+
+ pytest.skip("Unix permission bits are not checked on Windows")
+
+ config = _low_noise_config()
+ trace_db = tmp_path / "traces.db"
+ trace_db.write_text("", encoding="utf-8")
+ trace_db.chmod(0o644)
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["local-store-permissions-traces-db"].status == "warn"
+
+
+def test_symlink_local_store_permission_warns(tmp_path):
+ if os.name == "nt":
+ import pytest
+
+ pytest.skip("Symlink permission semantics differ on Windows")
+
+ config = _low_noise_config()
+ real_db = tmp_path / "real-traces.db"
+ real_db.write_text("", encoding="utf-8")
+ symlink = tmp_path / "traces.db"
+ symlink.symlink_to(real_db)
+ config.traces.db_path = str(symlink)
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["local-store-permissions-traces-db"].status == "warn"
+ assert "symlink" in findings["local-store-permissions-traces-db"].evidence
+
+
+def test_whatsapp_baileys_local_auth_dir_is_reported(tmp_path):
+ config = _low_noise_config()
+ auth_dir = tmp_path / "whatsapp_baileys_bridge" / "auth"
+ auth_dir.mkdir(parents=True)
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ whatsapp_findings = [
+ finding
+ for finding in report.findings
+ if finding.id.startswith("channel-local-credential-dir-whatsapp-baileys")
+ ]
+ assert len(whatsapp_findings) == 1
+ assert whatsapp_findings[0].status == "info"
+ assert whatsapp_findings[0].location == "whatsapp_baileys_bridge/auth"
+
+
+def test_whatsapp_dual_auth_dirs_both_reported(tmp_path):
+ config = _low_noise_config()
+ default_dir = tmp_path / "whatsapp_baileys_bridge" / "auth"
+ default_dir.mkdir(parents=True)
+ custom_dir = tmp_path / "custom_whatsapp_auth"
+ custom_dir.mkdir()
+ config.channel.whatsapp_baileys.auth_dir = str(custom_dir)
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ whatsapp_findings = [
+ finding
+ for finding in report.findings
+ if finding.id.startswith("channel-local-credential-dir-whatsapp-baileys")
+ ]
+ assert len(whatsapp_findings) == 2
+ ids = {finding.id for finding in whatsapp_findings}
+ assert len(ids) == 2
+ locations = {finding.location for finding in whatsapp_findings}
+ assert "whatsapp_baileys_bridge/auth" in locations
+ assert "<redacted>" in locations
+
+
+def test_channel_enabled_without_endpoint_is_info(tmp_path):
+ config = _low_noise_config()
+ config.channel.enabled = True
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["channels-enabled"].status == "info"
+
+
+def test_default_channel_value_is_always_redacted(tmp_path):
+ config = _low_noise_config()
+ config.channel.enabled = True
+ config.channel.default_channel = "telegram-secret-channel"
+
+ report = build_data_boundary_report(config, tmp_path)
+ payload = report.to_dict(show_paths=True)
+
+ findings = {finding.id: finding for finding in report.findings}
+ finding = findings["channels-enabled"]
+ assert finding.status == "warn"
+ assert "channel.default_channel is set; value redacted" in finding.evidence
+ assert "telegram-secret-channel" not in finding.evidence
+ assert "telegram-secret-channel" not in str(payload)
+
+
+def test_required_registered_tool_names_are_classified():
+ assert EXPECTED_BROWSER_TOOLS <= BROWSER_TOOLS
+ assert EXPECTED_LOCAL_ACCESS_TOOLS <= LOCAL_ACCESS_TOOLS
+ assert EXPECTED_GENERIC_NETWORK_TOOLS <= GENERIC_NETWORK_TOOLS
+ assert EXPECTED_CHANNEL_OUTBOUND_TOOLS <= CHANNEL_OUTBOUND_TOOLS
+ assert EXPECTED_CLOUD_MEDIA_TOOLS <= CLOUD_MEDIA_TOOLS
+ assert EXPECTED_KNOWLEDGE_ENGINE_TOOLS <= KNOWLEDGE_ENGINE_TOOLS
+ assert (
+ EXPECTED_GENERIC_NETWORK_TOOLS
+ | EXPECTED_CHANNEL_OUTBOUND_TOOLS
+ | EXPECTED_CLOUD_MEDIA_TOOLS
+ | EXPECTED_BROWSER_TOOLS
+ | EXPECTED_KNOWLEDGE_ENGINE_TOOLS
+ ) <= OUTBOUND_TOOL_SURFACES
+ assert EXPECTED_KNOWLEDGE_ENGINE_TOOLS <= EXTERNAL_TOOL_SURFACES
+
+
+def test_builtin_registry_tools_are_classified_or_explicitly_exempt():
+ unclassified = EXPECTED_BUILTIN_TOOLS - CLASSIFIED_TOOLS - EXPLICITLY_EXEMPT_TOOLS
+ assert not unclassified, (
+ "Registered built-in tools lack a data-boundary classification or "
+ f"documented exemption: {sorted(unclassified)}"
+ )
+ assert EXPECTED_BUILTIN_TOOLS <= CLASSIFIED_TOOLS | EXPLICITLY_EXEMPT_TOOLS
+ # Exemptions must not silently absorb tools that are already classified.
+ assert not (EXPLICITLY_EXEMPT_TOOLS & CLASSIFIED_TOOLS)
+
+
[email protected]("tool_name", sorted(EXPECTED_BROWSER_TOOLS))
+def test_required_browser_tools_are_detected(tmp_path, tool_name):
+ config = _low_noise_config()
+ config.tools.enabled = tool_name
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["browser-tool-configured"].status == "warn"
+ assert tool_name in findings["browser-tool-configured"].evidence
+
+
[email protected]("tool_name", sorted(EXPECTED_LOCAL_ACCESS_TOOLS))
+def test_required_local_access_tools_are_detected(tmp_path, tool_name):
+ config = _low_noise_config()
+ config.tools.enabled = tool_name
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["local-access-tools-configured"].status == "info"
+ assert tool_name in findings["local-access-tools-configured"].evidence
+
+
[email protected]("tool_name", sorted(EXPECTED_GENERIC_NETWORK_TOOLS))
+def test_http_request_produces_outbound_warn(tmp_path, tool_name):
+ config = _low_noise_config()
+ config.tools.enabled = tool_name
+
+ report = build_data_boundary_report(config, tmp_path)
+ payload = report.to_dict(show_paths=True)
+
+ findings = {finding.id: finding for finding in report.findings}
+ finding = findings["generic-network-tool-configured"]
+ assert finding.status == "warn"
+ assert tool_name in finding.evidence
+ assert "HTTP arguments, headers, and body" in finding.potential_data_path
+ assert "external URL" in finding.potential_data_path
+ assert "Authorization" not in str(payload)
+ assert "https://" not in str(payload)
+
+
[email protected]("tool_name", sorted(EXPECTED_CHANNEL_OUTBOUND_TOOLS))
+def test_channel_send_produces_outbound_warn(tmp_path, tool_name):
+ config = _low_noise_config()
+ config.tools.enabled = tool_name
+
+ report = build_data_boundary_report(config, tmp_path)
+ payload = report.to_dict(show_paths=True)
+
+ findings = {finding.id: finding for finding in report.findings}
+ finding = findings["channel-outbound-tool-configured"]
+ assert finding.status == "warn"
+ assert tool_name in finding.evidence
+ assert "message content" in finding.potential_data_path
+ assert "external messaging channel" in finding.potential_data_path
+ assert "secret-message" not in str(payload)
+ assert "telegram-secret-channel" not in str(payload)
+
+
+def test_image_generate_produces_outbound_warn(tmp_path):
+ config = _low_noise_config()
+ config.tools.enabled = "image_generate"
+
+ report = build_data_boundary_report(config, tmp_path)
+ payload = report.to_dict(show_paths=True)
+
+ findings = {finding.id: finding for finding in report.findings}
+ finding = findings["cloud-media-tool-configured"]
+ assert finding.status == "warn"
+ assert "image_generate" in finding.evidence
+ assert "image prompt" in finding.potential_data_path
+ assert "external media provider" in finding.potential_data_path
+ assert "a secret prompt about Alice" not in str(payload)
+
+
+def test_audio_transcribe_produces_outbound_warn_for_local_audio(tmp_path):
+ config = _low_noise_config()
+ config.tools.enabled = "audio_transcribe"
+
+ report = build_data_boundary_report(config, tmp_path)
+ payload = report.to_dict(show_paths=True)
+
+ findings = {finding.id: finding for finding in report.findings}
+ finding = findings["cloud-media-tool-configured"]
+ assert finding.status == "warn"
+ assert "audio_transcribe" in finding.evidence
+ assert "local audio file" in finding.potential_data_path
+ assert "external media provider" in finding.potential_data_path
+ assert "private-meeting.wav" not in str(payload)
+
+
+def test_http_request_with_local_tool_bypass_warns(tmp_path):
+ config = _low_noise_config()
+ config.tools.enabled = "http_request"
+ config.security.local_tool_bypass = True
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["generic-network-tool-configured"].status == "warn"
+ assert findings["security-local-tool-bypass-enabled"].status == "warn"
+
+
+ "tool_name",
+ sorted(
+ EXPECTED_GENERIC_NETWORK_TOOLS
+ | EXPECTED_CHANNEL_OUTBOUND_TOOLS
+ | EXPECTED_CLOUD_MEDIA_TOOLS
+ | EXPECTED_BROWSER_TOOLS
+ ),
+)
+def test_outbound_tools_with_bypass_are_external_surfaces(tmp_path, tool_name):
+ config = _low_noise_config()
+ config.tools.enabled = tool_name
+ config.security.local_tool_bypass = True
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["security-local-tool-bypass-enabled"].status == "warn"
+
+
+ "tool_name",
+ sorted(EXPECTED_CLOUD_MEDIA_TOOLS | {"web_search"}),
+)
+def test_cloud_api_outbound_tools_emit_frontend_scope_note(tmp_path, tool_name):
+ config = _low_noise_config()
+ config.tools.enabled = tool_name
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ assert "frontend-credential-storage-not-inspected" in _ids(report)
+
+
+ "tool_name",
+ [
+ "code_interpreter_docker",
+ "git_status",
+ "git_diff",
+ "git_commit",
+ "git_log",
+ ],
+)
+def test_docker_and_git_tools_are_local_access_info(tmp_path, tool_name):
+ config = _low_noise_config()
+ config.tools.enabled = tool_name
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["local-access-tools-configured"].status == "info"
+ assert tool_name in findings["local-access-tools-configured"].evidence
+
+
[email protected]("tool_name", sorted(BROWSER_TOOLS))
+def test_registered_browser_tools_are_detected(tmp_path, tool_name):
+ config = _low_noise_config()
+ config.tools.enabled = tool_name
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["browser-tool-configured"].status == "warn"
+ assert tool_name in findings["browser-tool-configured"].evidence
+
+
[email protected]("tool_name", sorted(LOCAL_ACCESS_TOOLS))
+def test_registered_local_sensitive_tools_are_detected(tmp_path, tool_name):
+ config = _low_noise_config()
+ config.tools.enabled = tool_name
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["local-access-tools-configured"].status == "info"
+ assert tool_name in findings["local-access-tools-configured"].evidence
+
+
[email protected]("tool_name", sorted(GENERIC_NETWORK_TOOLS))
+def test_registered_generic_network_tools_are_detected(tmp_path, tool_name):
+ config = _low_noise_config()
+ config.tools.enabled = tool_name
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["generic-network-tool-configured"].status == "warn"
+ assert tool_name in findings["generic-network-tool-configured"].evidence
+
+
[email protected]("tool_name", sorted(CHANNEL_OUTBOUND_TOOLS))
+def test_registered_channel_outbound_tools_are_detected(tmp_path, tool_name):
+ config = _low_noise_config()
+ config.tools.enabled = tool_name
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["channel-outbound-tool-configured"].status == "warn"
+ assert tool_name in findings["channel-outbound-tool-configured"].evidence
+
+
[email protected]("tool_name", sorted(CLOUD_MEDIA_TOOLS))
+def test_registered_cloud_media_tools_are_detected(tmp_path, tool_name):
+ config = _low_noise_config()
+ config.tools.enabled = tool_name
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["cloud-media-tool-configured"].status == "warn"
+ assert tool_name in findings["cloud-media-tool-configured"].evidence
+
+
+def test_gemini_api_key_is_detected_without_value_leak(tmp_path, monkeypatch):
+ config = _low_noise_config()
+ config.intelligence.provider = "gemini"
+ monkeypatch.setenv("GEMINI_API_KEY", "secret-gemini-key")
+
+ report = build_data_boundary_report(config, tmp_path)
+ payload = report.to_dict(show_paths=True)
+
+ findings = {finding.id: finding for finding in report.findings}
+ finding = findings["env-credential-gemini_api_key"]
+ assert finding.status == "warn"
+ assert "GEMINI_API_KEY is set" in finding.evidence
+ assert "secret-gemini-key" not in str(payload)
+
+
+def test_init_template_config_snapshot(tmp_path):
+ init_like_toml = """
+[server]
+host = "0.0.0.0"
+
+[telemetry]
+enabled = true
+
+[traces]
+enabled = false
+
+[agent]
+context_from_memory = true
+
+[memory]
+enabled = false
+"""
+ config_path = tmp_path / "config.toml"
+ config_path.write_text(init_like_toml, encoding="utf-8")
+ config = load_config(config_path)
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["server-binds-all-interfaces"].status == "warn"
+ assert findings["telemetry-enabled"].status == "warn"
+ assert "traces-enabled" not in findings
+ assert findings["memory-context-injection-enabled"].status == "info"
+
+
+def test_scan_chunks_is_classified():
+ assert "scan_chunks" in KNOWLEDGE_ENGINE_TOOLS
+ assert "scan_chunks" in CLASSIFIED_TOOLS
+ assert "scan_chunks" in EXPECTED_BUILTIN_TOOLS
+
+
+def test_scan_chunks_local_engine_is_warn_or_info(tmp_path):
+ config = _low_noise_config()
+ config.tools.enabled = "scan_chunks"
+ config.engine.default = "ollama"
+ config.deep_research.engine = ""
+ config.deep_research.model = ""
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert "knowledge-chunks-to-cloud-risk" not in findings
+ finding = findings["knowledge-engine-tool-configured"]
+ assert finding.status in {"warn", "info"}
+ assert "local knowledge-store chunks" in finding.potential_data_path
+
+
+def test_knowledge_chunks_cloud_composition_is_fail(tmp_path):
+ config = _low_noise_config()
+ config.tools.enabled = "scan_chunks"
+ config.engine.default = "openai"
+ (tmp_path / "knowledge.db").write_text("", encoding="utf-8")
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ finding = findings["knowledge-chunks-to-cloud-risk"]
+ assert finding.status == "fail"
+ assert "knowledge.db chunks" in finding.potential_data_path
+ assert "cloud inference" in finding.potential_data_path
+ assert report.verdict == "local knowledge may be sent to cloud inference"
+
+
+def test_knowledge_chunks_local_composition_is_not_fail(tmp_path):
+ config = _low_noise_config()
+ config.tools.enabled = "scan_chunks"
+ config.engine.default = "ollama"
+ config.intelligence.default_model = "qwen3.5:9b"
+ (tmp_path / "knowledge.db").write_text("", encoding="utf-8")
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert "knowledge-chunks-to-cloud-risk" not in findings
+ assert findings["knowledge-engine-tool-configured"].status in {"warn", "info"}
+ assert findings["local-store-knowledge-db"].status == "warn"
+
+
+def test_knowledge_db_is_reported(tmp_path):
+ config = _low_noise_config()
+ (tmp_path / "knowledge.db").write_text("", encoding="utf-8")
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["local-store-knowledge-db"].status == "warn"
+ assert (
+ "Knowledge and Deep Research database"
+ in findings["local-store-knowledge-db"].title
+ )
+
+
+def test_knowledge_db_path_is_redacted(tmp_path):
+ config = _low_noise_config()
+ (tmp_path / "knowledge.db").write_text("", encoding="utf-8")
+
+ report = build_data_boundary_report(config, tmp_path)
+ payload = report.to_dict()
+ payload_with_paths = report.to_dict(show_paths=True)
+
+ assert str(tmp_path) not in str(payload)
+ assert "knowledge.db" in str(payload)
+ assert "knowledge.db" in str(payload_with_paths)
+
+
+def test_knowledge_db_posix_permissions_checked(tmp_path):
+ if os.name == "nt":
+ pytest.skip("Unix permission bits are not checked on Windows")
+
+ config = _low_noise_config()
+ knowledge_db = tmp_path / "knowledge.db"
+ knowledge_db.write_text("", encoding="utf-8")
+ knowledge_db.chmod(0o644)
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["local-store-permissions-knowledge-db"].status == "warn"
+
+
+def test_browser_resolver_tools_are_all_classified():
+ from openjarvis.agents.tool_resolver import BROWSER_SUB_TOOLS
+
+ assert set(BROWSER_SUB_TOOLS) <= BROWSER_TOOLS
+
+
+def test_browser_axtree_is_warn(tmp_path):
+ config = _low_noise_config()
+ config.tools.enabled = "browser_axtree"
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["browser-tool-configured"].status == "warn"
+ assert "browser_axtree" in findings["browser-tool-configured"].evidence
+
+
+def test_credentials_toml_is_reported_without_reading_contents(tmp_path):
+ config = _low_noise_config()
+ creds = tmp_path / "credentials.toml"
+ creds.write_text(
+ 'openai = { OPENAI_API_KEY = "super-secret-value" }\n', encoding="utf-8"
+ )
+
+ report = build_data_boundary_report(config, tmp_path)
+ payload = report.to_dict(show_paths=True)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["local-store-credentials-toml"].status == "warn"
+ assert "super-secret-value" not in str(payload)
+ assert "OPENAI_API_KEY" not in findings["local-store-credentials-toml"].evidence
+
+
+def test_credentials_toml_path_redacted(tmp_path):
+ config = _low_noise_config()
+ (tmp_path / "credentials.toml").write_text("", encoding="utf-8")
+
+ report = build_data_boundary_report(config, tmp_path)
+ payload = report.to_dict()
+
+ assert str(tmp_path) not in str(payload)
+ assert "credentials.toml" in str(payload)
+
+
+def test_credentials_toml_permission_warning(tmp_path):
+ if os.name == "nt":
+ pytest.skip("Unix permission bits are not checked on Windows")
+
+ config = _low_noise_config()
+ creds = tmp_path / "credentials.toml"
+ creds.write_text("", encoding="utf-8")
+ creds.chmod(0o644)
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["local-store-permissions-credentials-toml"].status == "warn"
+
+
+def test_runtime_credential_keys_are_all_covered():
+ specialized = (
+ set(API_KEY_ENV_VARS)
+ | set(CHANNEL_SECRET_ENV_VARS)
+ | set(CHANNEL_REFERENCE_ENV_VARS)
+ )
+ assert RUNTIME_CREDENTIAL_ENV_KEYS <= specialized | set(GENERIC_CREDENTIAL_ENV_VARS)
+
+
+def test_runtime_credential_values_never_appear(tmp_path, monkeypatch):
+ config = _low_noise_config()
+ secret = "runtime-credential-secret-value-xyz"
+ # Cover both specialized and generic keys.
+ monkeypatch.setenv("OPENAI_API_KEY", secret)
+ monkeypatch.setenv("ZULIP_API_KEY", secret)
+ monkeypatch.setenv("LINE_CHANNEL_SECRET", secret)
+
+ report = build_data_boundary_report(config, tmp_path)
+ payload = report.to_dict(show_paths=True)
+ blob = str(payload)
+
+ assert secret not in blob
+ findings = {finding.id: finding for finding in report.findings}
+ assert "OPENAI_API_KEY is set" in findings["env-credential-openai_api_key"].evidence
+ assert (
+ "ZULIP_API_KEY is set"
+ in findings["env-credential-generic-zulip_api_key"].evidence
+ )
+ assert (
+ "LINE_CHANNEL_SECRET is set"
+ in findings["env-credential-generic-line_channel_secret"].evidence
+ )
+
+
+def _clear_cloud_api_env(monkeypatch) -> None:
+ for name in API_KEY_ENV_VARS:
+ monkeypatch.delenv(name, raising=False)
+
+
+def test_external_surface_does_not_claim_cloud_inference_without_cloud(
+ tmp_path,
+ monkeypatch,
+):
+ _clear_cloud_api_env(monkeypatch)
+ config = _low_noise_config()
+ config.tools.enabled = "browser_navigate"
+ config.security.local_tool_bypass = True
+
+ report = build_data_boundary_report(config, tmp_path)
+ payload = report.to_dict(show_paths=True)
+ blob = str(payload).lower()
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["browser-tool-configured"].status == "warn"
+ assert findings["security-local-tool-bypass-enabled"].status == "warn"
+ assert "frontend-credential-storage-not-inspected" not in findings
+ assert "cloud inference" not in blob
+
+
+def test_browser_only_does_not_emit_cloud_api_key_claim(tmp_path, monkeypatch):
+ _clear_cloud_api_env(monkeypatch)
+ config = _low_noise_config()
+ config.tools.enabled = "browser_axtree"
+
+ report = build_data_boundary_report(config, tmp_path)
+ payload = report.to_dict(show_paths=True)
+
+ assert "frontend-credential-storage-not-inspected" not in _ids(report)
+ assert "cloud API keys" not in str(payload)
+
+
+def test_full_system_access_config_snapshot(tmp_path, monkeypatch):
+ _clear_cloud_api_env(monkeypatch)
+ profile = """
+[engine]
+default = "ollama"
+
+[intelligence]
+default_model = "qwen3.5:9b"
+
+[agent]
+default_agent = "orchestrator"
+max_turns = 10
+
+[tools]
+enabled = [
+ "shell_exec",
+ "file_read",
+ "file_write",
+ "apply_patch",
+ "code_interpreter",
+ "git_status",
+ "git_diff",
+ "think",
+ "calculator",
+]
+"""
+ config_path = tmp_path / "config.toml"
+ config_path.write_text(profile, encoding="utf-8")
+ if os.name != "nt":
+ config_path.chmod(0o600)
+ config = load_config(config_path)
+ # Mirror _low_noise_config store-path clearing so real home files are ignored.
+ config.traces.db_path = ""
+ config.telemetry.db_path = ""
+ config.security.audit_log_path = ""
+ config.security.vault_key_path = ""
+ config.tools.storage.db_path = ""
+ config.tools.storage.facts_path = ""
+ config.sessions.db_path = ""
+ config.agent_manager.db_path = ""
+ config.optimize.db_path = ""
+ config.optimize.optimizer_provider = ""
+ config.optimize.judge_model = ""
+ config.scheduler.db_path = ""
+ config.skills.index_dir = ""
+ config.analytics.enabled = False
+ config.traces.enabled = False
+ config.telemetry.enabled = False
+ config.agent.context_from_memory = False
+ config.skills.enabled = False
+ config.digest.enabled = False
+ config.channel.enabled = False
+ config.server.host = "127.0.0.1"
+ config.security.profile = "personal"
+ config.learning.spec_search.enabled = False
+ config.learning.enabled = False
+ config.learning.training_enabled = False
+ config.learning.auto_update = False
+
+ report = build_data_boundary_report(config, tmp_path)
+
+ findings = {finding.id: finding for finding in report.findings}
+ assert findings["local-access-tools-configured"].status == "info"
+ assert "shell_exec" in findings["local-access-tools-configured"].evidence
+ assert "file_read" in findings["local-access-tools-configured"].evidence
+ assert "knowledge-chunks-to-cloud-risk" not in findings
+ assert "cloud-provider-configured" not in findings
+ assert "frontend-credential-storage-not-inspected" not in findings
+ assert report.verdict == "no fail or warn findings detected"
diff --git a/tests/tools/test_tool_registration.py b/tests/tools/test_tool_registration.py
index b045fd6d..d17f0ece 100644
--- a/tests/tools/test_tool_registration.py
+++ b/tests/tools/test_tool_registration.py
@@ -64,6 +64,8 @@ EXPECTED_TOOLS = {
"image_generate",
# audio_tool.py
"audio_transcribe",
+ # text_to_speech.py
+ "text_to_speech",
# knowledge_tools.py
"kg_add_entity",
"kg_add_relation",