ai-powered-conversational-intelligence

Security

This is a demo/portfolio project, not a production-hardened product. Please read this before pointing it at anything real.

2026-09-01 update: this document reflects an enterprise-oriented security audit (22 attack-surface categories, tested against the running code, not just reasoned about from the design). It found and closed two real gaps in the SQL validator — see “What’s actually enforced” below and docs/security-changelog.md’s dated entry for the full detail — plus added several defense-in-depth layers (identifier quoting, secret redaction, a SecretStr wrapper, a best-effort write-privilege check, enforced column sensitivity classification, structured security-event logging, a RAG-poisoning detection scan, and closing a process-wide result-cache cross-session risk). Everything below is written to still be accurate after that pass, not a separate “what’s new” list bolted on top.

2026 Phase 3 update (2026-09-16): real authentication (OIDC/JWT, plus a now-usable frontend login flow) and RBAC authorization landed in the sessions between the update above and this one — see “Authentication and authorization” below, which this document previously didn’t mention at all. This pass itself added: security headers (HSTS/CSP/X-Frame-Options/ etc., on by default), a SQL-validator block on system-catalog/ data-dictionary access, a startup check that refuses to boot in production if a configured database’s role isn’t actually read-only, SSRF redirect-hop re-validation for media generation, a CORS wildcard rejection, and a per-document RBAC restriction option for RAG content. Full audit trail: SECURITY_FINAL_REPORT.md, SECURITY_BASELINE.md, SECURITY_CHANGELOG.md, SECURITY_PRODUCTION_CHECKLIST.md (repo root). That report’s own conclusion: this platform is not production-ready as shipped — 24 known CVEs across 7 backend dependencies remain unresolved (the largest needs a langgraph major-version migration), the frontend OIDC flow has not been exercised against a live identity provider, and several other items in that report’s own checklist are still open. Treat this document as describing what’s implemented, not a claim that everything here has been independently verified end-to-end — where a control is unverified, it’s said so explicitly.

2026 dependency/CI-hardening + final-gate update: a later engagement (docs/security/, not the repo-root files above) flipped CI’s SAST/ dependency-scan/secret-scan gates from report-only to actually blocking, added a MalwareScanner abstraction (opt-in, fail-closed once configured — security/malware_scanner.py), and ran a first production-readiness gate against the current codebase end-to-end. Its verdict: NOT READY — see docs/security/PRODUCTION_SECURITY_READINESS_REPORT.md for the current, authoritative answer. Not because a new vulnerability was found (the tested architecture — SQL validation, RBAC, IDOR, SSRF — holds up), but because DAST has never been run against this app, the OIDC flow (see above) still hasn’t been exercised against a live IdP, and the new malware scanner has never been tested against a real scanner daemon. This supersedes the “not production-ready as shipped” conclusion cited above where the two differ — read the newer document, not just this paragraph.

What’s actually enforced

What is explicitly not guaranteed

Database content is untrusted input too

It’s tempting to think of “the user’s typed question” as the only adversarial input this app has to worry about. It isn’t. Two other things flow into an LLM prompt with roughly the same trust level as a typed question, and are treated the same way:

None of this is sanitized because it’s expected to contain literal SQL injection in the traditional sense (it’s never concatenated into executable SQL — only into prompt text, and the SQL validator still gates whatever the LLM produces regardless). The risk here is prompt injection via stored data, not SQL injection via stored data, and it gets the same layered treatment as user input: normalize at the source, frame it as untrusted data in the system prompt, and don’t rely on either of those alone — the SELECT-only allowlist and read-only connection are what actually bound the consequences if a poisoned value ever does influence what the model generates.

Authentication and authorization

Off by default (Settings.auth_mode == "none", unchanged behavior for local/single-user use), but real when turned on — this section previously didn’t exist in this document even after both landed, which was itself a documentation gap; the detail below has existed in docs/AUTHENTICATION.md/ docs/AUTHORIZATION.md for longer than it’s been summarized here.

Multi-source RAG and web search (optional, off by default)

Everything in this section only exists when ENABLE_MULTI_SOURCE_ROUTER=true and the specific source’s own flag/config is set — see docs/MULTI_SOURCE_GUIDE.md. With the router off (the default), none of this code path runs at all.

Media generation (image/video, optional, off by default)

Same ENABLE_MULTI_SOURCE_ROUTER=true gate as above, plus its own ENABLE_MEDIA_GENERATION/IMA_API_KEY. Distinct from every other source here in one way that matters: a successful generation spends real, metered third-party (IMA Studio) credit, not just compute — it gets controls the others don’t need.

Media search (image/video, optional, off by default)

Same ENABLE_MULTI_SOURCE_ROUTER=true gate as above, plus its own ENABLE_MEDIA_SEARCH/MEDIA_LIBRARY_PATH. Unlike media generation, no per-call third-party cost — the controls here are about untrusted content and file-system safety instead.

Content moderation gate (mandatory whenever media search or document/policy RAG is on)

Both content-ingestion pipelines — media search’s images/video (media/ingest.py) and document/policy RAG’s PDFs (rag/ingestion.py) — now run every chunk of every file through a pre-ingestion moderation gate (moderation/) before anything is ever embedded or stored. This is mandatory, not a feature flag: there is deliberately no ENABLE_CONTENT_MODERATION toggle that could disable it while leaving either ingestion pipeline on. Missing provider/store configuration fails ingestion closed with a clear error (ModerationNotConfiguredError), mirroring RagStoreNotConfiguredError’s existing pattern, rather than silently skipping the check.

Chat attachments — security controls

Images, PDFs, DOCX, XLSX, PPTX, TXT, MD, CSV, and JSON files attached directly to a chat question (attachments/, POST /attachments/upload, POST /ask’s attachment_ids) go through the same class of untrusted-input handling as every other content source in this codebase, plus a few controls specific to what a file upload can carry that plain text cannot.

See CLAUDE.md’s “Chat attachments, image actions, and their security hardening” section for the full design and docs/API.md’s “Attachments” section for the request/response contracts.

AI-guided (generative) image editing — security controls

POST /attachments/{id}/ai-edit (attachments/ai_edit.py, media_gen/image_edit_provider.py) is the one attachment action that calls a third-party generative provider (IMA Studio), so it carries additional controls beyond the deterministic actions above:

See docs/image-editing-architecture.md for the full design and CLAUDE.md’s “AI-guided (generative) image editing” section.

Ollama model selection — security controls

POST /ask’s optional model field (letting a caller pick which locally installed Ollama model answers a question, agent/model_registry.py) never becomes an unrestricted way to reach an arbitrary local resource:

Google sign-in — security controls

“Continue with Google” (2026-09-28, optional — GOOGLE_OAUTH_CLIENT_ID, requires LOCAL_AUTH_ENABLED=true) is a second way to reach this app’s own self-hosted accounts, never a separate trust boundary. Full design in docs/AUTHENTICATION.md’s “Google sign-in” section; the security-relevant controls specifically:

Secure conversation sharing — security controls

“Share conversation” (optional, Settings.enable_conversation_sharing, default on — public “anyone with the link” mode separately gated behind Settings.share_public_links_enabled, default off) turns a conversation into a controlled, read-only snapshot other people may view — never a live query channel, never an authentication session, and never a way to reach this app’s SQL/RAG/web/model/image pipelines. Full design in docs/SHARING_SECURITY.md; the security-relevant controls specifically:

Per-conversation source selection — security controls

AskRequest.sources lets a caller restrict one question to named sources (agent/orchestrator/nodes.py::_apply_source_selection).

It is a filter, never a grant. The selection is intersected with what standing configuration makes available and with what the caller’s roles permit; the pre-existing role check in router_node then runs on whatever survives. Naming a source you are not entitled to cannot reach it.

Mutation-tested: replacing the intersection with a union fails 19 tests (tests/test_source_selection.py).

Outbound HTTP (security/outbound_url.py) — security controls

The SSRF controls used by the REST connector, and the canonical home for any new outbound caller.

This is a resolve-then-connect check, not a pinned-IP call — the same disclosed scope media_gen/download.py and bi_integration/outbound_safety.py already accept. The allowlist is what makes the rebinding window small: a rebind must be served by a host an operator explicitly named.

Three copies of the blocklist now exist (this module plus the two above), for reasons documented in each. Duplication of a security control is only acceptable if divergence cannot go unnoticed, so tests/test_outbound_url.py::TestBlocklistsAreIdentical asserts all three match, plus a second check that the list still covers the ranges that matter. Consolidating the two older copies is its own task and is not done.

Mutation-tested: dropping per-hop redirect re-validation fails 3 tests; dropping the allowlist fails 9; checking only the first resolved address fails 1.

REST/OpenAPI connector (rest/, optional, off by default) — security controls

MCP client (mcp_client/, optional, off by default) — security controls

A client of remote MCP servers. Not to be confused with agent/tools/, which is MCP-shaped so this app’s own capabilities could be exposed to a client — opposite direction, no shared code.

Trust is administrator-controlled only.

Everything a server sends is data, never instructions.

Subprocess handling. This is the first production code in this repository to spawn a subprocess (agent api config db voice media media_gen security contain no subprocess import outside scripts/ and tests/).

Mutation-tested: a permissive allowlist fails 7 tests, a prefix-matching allowlist 2, an inherited environment 2, shell=True 1, and storing instructions on the client 1.

Not verified against a live MCP server — none exists in this environment. Protocol shapes are spec-verified and the framing is exhaustively unit-tested, but end-to-end behaviour against a real implementation is unverified.

Streaming (POST /ask/stream) — security controls

Resource exhaustion / abuse protections

Two independent, deliberately simple protections guard against both accidental abuse (a user re-asking the same broad question repeatedly) and deliberate attempts to degrade the app’s availability — catching the common cases before execution, alongside the row cap and query timeout that already catch anything at execution time (see “What’s actually enforced” above; none of this replaces those).

The REST API (api/) shares this posture, not a separate one

api/main.py’s POST /ask calls the same agent.graph.run_agent the UI calls — every control described above (validator, rate limits, row cap, timeout, sensitive-column blocking) applies identically, there is no parallel, weaker code path. The API’s own auth/authz layer is the “Authentication and authorization” section above — a static shared token remains the simplest option (see docs/API.md’s “Auth” section) but OIDC

2026-09-13 addition: POST /execute, POST /schema/refresh, and the mutating /documents routes previously had no rate limit at all (only /ask did). All four now go through a shared per-client-IP limiter (api/rate_limit.py::enforce_api_action_rate_limit, API_ACTION_RATE_LIMIT_PER_MINUTE) — the same limitation as the existing per-IP question limiter applies (evadable by changing IP; a soft control appropriate for this app’s single-user/local-trust posture, not a substitute for the authenticating reverse proxy above). POST /documents also gained a hard upload-size cap (MAX_DOCUMENT_UPLOAD_MB, default 25) and a magic-byte check rejecting non-PDF content before parsing — previously the entire upload was read into memory unbounded, and “not a PDF” was only ever discovered by pypdf failing partway through.

Bottom line

Do not point this at a production database, or a database containing real sensitive/personal data, without an independent security review and your own risk assessment first. For local exploration, portfolio demos, or a sandboxed/synthetic dataset, the read-only validator plus a genuinely-read-only DB account is a reasonable posture. For anything more sensitive, treat this as a starting point, not a finished answer.

See also: docs/GOVERNANCE.md (ownership, change control), docs/COMPLIANCE.md (OWASP/NIST AI RMF/ ISO 42001/EU AI Act self-assessment), docs/RESPONSIBLE_AI.md (design choices through a responsible-AI lens), and docs/RISK_REGISTER.md (every open risk named in this document, tracked with severity and a review date) — together these five documents describe this project’s full risk posture, each linking back to the others.

Reporting a vulnerability

This is a personal project without a dedicated security contact — please open a GitHub issue (or a private security advisory, if enabled on this repo) describing the issue. For something that would let generated SQL bypass the read-only allowlist, or a question/sampled value that gets past agent/input_guard.py and actually changes the model’s behavior (not just past the regex pre-filter — that’s expected to be beatable; past the system prompt’s untrusted-data framing too), please include the exact input that triggered it.