Skip to content

Security model

This page describes how Spongram authenticates callers, keeps one brain's memory separate from another's, and limits what leaves the deployment. It covers the server, the Cloud control plane that can be enabled on it and, where it differs, the desktop edition.

Trust boundaries

  • MCP clients and browsers reach only the spongram service, over its single HTTP port.
  • spongram is the only component that talks to graphiti-mcp, PostgreSQL and Neo4j.
  • graphiti-mcp sends its model calls back to spongram, which forwards them to the one configured inference endpoint.
  • Memory content (episodes, extracted text, model output) is treated as untrusted data everywhere it is rendered.

Brain keys

A brain key authenticates an MCP client or a /v1 API call for exactly one brain.

Property Value
Format spt_brain_ followed by 32 hexadecimal characters (42 characters in total), from a cryptographically secure generator
Storage spongram_api_keys.key_hash holds the SHA-256 digest of the full key; key_prefix holds the first 18 characters, indexed for lookup. The clear value is never stored.
Disclosure Returned once, by the call that creates the brain or regenerates the key
Validity Refused when is_active is false, revoked_at is set, expires_at is past, or the brain's status is not active
Regeneration Creates a new key, attaches it to the brain and revokes the previous one in the same transaction; the authentication cache is cleared so the old key stops working at once

SHA-256 is used instead of a slow password hash because the key is a 128-bit random value, not a human-chosen secret, and it is looked up on every request. The distinct prefix also makes a brain key recognisable in logs and secret scanners.

Without the Cloud control plane a resolved key is cached in memory for SPONGRAM_AUTH_CACHE_TTL seconds (default 300). The cache is cleared when a key is regenerated or a brain is changed or deleted. The Cloud control plane does not cache positive results: key, user, grant and organisation are read on each request.

Because the server cannot recover a key, downloading a client bundle requires the caller to present the clear key again in the X-Spongram-Brain-Key header; the server checks it against the stored hash before embedding it in the bundle.

Warning

A bundle (.mcpb or .plugin) contains the brain key in clear text. Handle bundle files like the key itself. If a key or a bundle leaks, regenerate the key: every bundle built with the old key stops working.

Admin token

On a server without the Cloud control plane, SPONGRAM_ADMIN_TOKEN protects every route under /admin/api/spongram and the /metrics endpoint. It is sent as Authorization: Bearer <admin-token> and compared in constant time. There is one token and no per-operator account: anyone who holds it can read, export, purge or delete every brain, so treat it as a root credential and serve the admin UI over HTTPS only.

The admin UI keeps the token in the browser's local storage. It also keeps a brain key there after creating or regenerating it, so that bundles and explorers can be opened without retyping the key. Use the admin UI from a trusted browser profile. When it embeds an explorer in an iframe, it passes the token in the URL fragment (#admin=), which the browser does not send to the server; the page then sends it as an Authorization header on its data calls.

With the Cloud control plane the admin token does not open the admin API. It is the installation credential: it is required to create the first administrator account and to open a 30-minute recovery session.

Cloud control plane accounts and permissions

With SPONGRAM_CLOUD_CONTROL_ENABLED=true, access is governed by accounts, organisations and per-brain grants.

Permissions are enforced per brain, according to its access_mode: only a brain in enforce checks the permissions of keys and sessions. A brain that existed before the control plane was enabled stays in legacy mode, where its original key keeps working without permission checks, until an installation administrator migrates it.

Identities

Object Meaning
User A person who signs in with a username and password, or through OpenID Connect when SPONGRAM_CLOUD_OIDC_ISSUER and SPONGRAM_CLOUD_OIDC_CLIENT_ID are set. A user can be an installation administrator.
Organisation The tenant that owns brains. It can be suspended.
Principal A member of an organisation: a human (a user) or a service (an application). Its organisation role is member, admin or owner.
Grant The list of permissions one principal holds on one brain.
Brain key Issued to a principal for a brain, with its own list of permissions, an optional expiry and optional rotation of an earlier key.

An organisation admin or owner, or an installation administrator, can manage the organisation's members, brains and grants. The effective rights of a key are the intersection of the key's permissions and the principal's current grant on that brain. Removing a grant revokes that principal's keys on the brain in the same transaction, and suspending the user, the principal or the organisation makes its keys invalid.

Permissions

Permission Allows
memory.read Search and read tools, the explorers, /v1/info, bundle download
memory.write add_memory, record_skill, reflect_on_failure, memory distillation
memory.correct Tag backfills and entity normalisation
memory.delete delete_episode, delete_entity_edge, forgetting an entity or a fact, retiring a queue row, purging one code-map repository
memory.import Brain import, persona card and skill import, code-map ingest
memory.export Brain export, wiki archive, full graph download, persona card export
brain.configure Activating or deactivating a persona, project aliases, editing personas and skills, brain settings, installing a marketplace persona
access.manage Managing grants and keys of a brain, changing its status
operations.read Activity and ingestion-queue views
operations.retry Replaying ingestion-queue rows
usage.read Usage statistics
audit.read Audit views
keys.create Issuing a key for oneself on a brain. Issuing a key for someone else needs access.manage. A key never carries a permission its issuer does not hold.

An MCP tool that is not mapped to a permission is refused, and tools/list only shows the tools the key could call.

The console offers presets rather than raw lists:

Preset Where Permissions
Reader Account creation memory.read, operations.read, keys.create
Contributor Account creation Reader plus memory.write
Brain administrator Account creation Every permission
Read only Key creation memory.read, operations.read
Agent Key creation memory.read, memory.write, memory.correct, memory.delete, memory.import, memory.export, brain.configure, operations.read

Erasing a whole brain

Deleting a brain, purging it, and the MCP tool clear_graph require memory.delete, brain.configure and access.manage together. Forgetting a single episode needs memory.delete alone. The Agent key preset holds no access.manage, so an agent can forget an episode but cannot erase the brain.

Sessions

Control Behaviour
Passwords Hashed with Argon2. An account created or reset by an administrator must change its temporary password before doing anything else.
Throttling Sign-in attempts are counted per account and per client address.
Session cookie spongram_cloud_session, HttpOnly, SameSite=Lax, Secure unless SPONGRAM_CLOUD_COOKIE_SECURE=false. Only a hash of the session token is stored.
Lifetime SPONGRAM_CLOUD_SESSION_HOURS (default 8, 1 to 24); 30 minutes for a recovery session.
CSRF Every request other than GET, HEAD or OPTIONS must carry an Origin header equal to SPONGRAM_PUBLIC_URL and a valid X-CSRF-Token.
Database The control plane tables for sources, operations, graph withdrawals and inference calls use PostgreSQL row-level security keyed on the organisation.
Licence The control plane licence is a token signed with RS256 and verified against the public keys in SPONGRAM_CLOUD_LICENSE_PUBLIC_KEYS.

Set SPONGRAM_PUBLIC_URL to the exact public origin, otherwise every write from the console fails the origin check.

Tenant isolation

One brain is one group_id. Every node and relationship Graphiti writes carries it, and every query Spongram runs is scoped by it. Isolation rests on four rules.

The group_id is injected server-side. spongram resolves the brain from the key and writes its group_id into every MCP tool call before forwarding it. Clients never need to send one.

A mismatching group_id is rejected. If a tool call carries a group_id, or a group_ids list, that differs from the authenticated brain, the request fails with 403 (group_id mismatch — anti-tampering) and is counted in the authentication-failure metric. POST /v1/codemap/ingest applies the same check.

Tools addressed by uuid are checked before forwarding. delete_episode, delete_entity_edge and get_entity_edge take a uuid, and Graphiti resolves a uuid without looking at the group_id. On a server spongram therefore first verifies in the graph that the uuid belongs to the caller's brain:

  • a uuid outside the brain gets the same not found tool error as a uuid that does not exist, so the answer cannot be used to probe other brains;
  • if the graph cannot be read, the call is refused with a retry message instead of being forwarded (fail closed).

The admin API never trusts a client-supplied brain. Admin routes take a numeric instance id and look up the group_id in PostgreSQL. Purge refuses any group_id that is not a Spongram namespace (sb_ prefix, or local on desktop).

The upstream tools that were added to Graphiti after the surface Spongram exposes are not offered to clients: they are absent from tools/list and answer Unknown tool without reaching Graphiti. add_memory only passes the arguments name, episode_body, source, source_description and uuid.

The desktop edition holds a single brain (group_id local) and applies no key and no tampering check: it listens on the loopback address for the local user only.

Graphiti is not reachable directly

graphiti-mcp has no authentication of its own and would serve any group_id to any caller. Its port 8000 is therefore internal to the container network and is never published. Do not add a ports: mapping or a reverse-proxy route for it, and do not give clients its address: all memory traffic must pass through spongram, where authentication, group_id injection, the ingestion queue and the checks above are applied.

PostgreSQL is internal for the same reason. Neo4j ports are published on the host for administration and debugging only; client bundles never reference them, and the explorers read the graph through spongram.

Inference traffic and telemetry

Memory operations need a chat model and an embedding model. graphiti-mcp is configured with OPENAI_API_URL and OPENAI_BASE_URL pointing at spongram's internal proxy (/_internal/v1/graphiti), authenticated with SPONGRAM_INTERNAL_AUTH_TOKEN; the proxy refuses every call while that variable is unset. The Sleeper, Dream and distillation calls use the same proxy. The proxy forwards every call to the single endpoint stored in the inference settings.

Consequences for the operator:

  • Episode text and extracted facts are sent to that endpoint and to no other model provider. With an endpoint you host, no memory content leaves your infrastructure.
  • If you select a hosted provider in the inference settings, memory content is sent to that provider. This is a deployment choice, not a default behaviour.
  • Both variables must point at the proxy. If OPENAI_BASE_URL is missing, the OpenAI client library inside graphiti-mcp falls back to its public default endpoint.
  • Graphiti's usage telemetry is disabled: GRAPHITI_TELEMETRY_ENABLED=false is set in the Graphiti image, whose build fails if telemetry is still enabled, and by spongram itself for the embedded engine of the desktop edition.
  • Langfuse tracing is off unless SPONGRAM_LANGFUSE_ENABLED and its keys are set.
  • Request analytics are opt-in as well: the analytics middleware is added only when ORIFLUX_API_KEY is set, and the admin UI receives an analytics key only when ORIFLUX_WEB_KEY is set.

See inference providers.

Untrusted content in the browser

Wiki pages embed raw episode content and model-generated text. A memory can therefore contain HTML or a javascript: link written by anyone whose text reached the brain. The wiki renders Markdown through a dedicated safe renderer:

  • raw HTML in the source is escaped and shown as text;
  • links and images are kept only when their URL is http, https, mailto or relative;
  • the generated markup then passes an allow-list filter inside an inert template element before it is inserted in the page.

Every other value the explorers display is HTML-escaped. This matters most in the admin mirrors and in the control plane console, where the page runs with the operator's credentials: one script injection there would give access to every brain the operator can reach.

Keys in the browser

The explorer pages (/v1/graph, /v1/wiki, /v1/codemap, /v1/personas) are static shells. The brain key is supplied in the URL fragment (#key=) or typed into the page, kept in the tab's session storage, and sent as an Authorization header on each data request. It is never placed in a query string, where it would end up in access logs and proxy caches.

The live stream /v1/graph/stream follows the same rule: it must be consumed with fetch() and a stream reader. The browser EventSource API cannot set an Authorization header, so using it would force the key into the URL.

Imported content

Entry point Restrictions
Persona skill import from a URL https:// only; 32 KiB at most; 3 redirects at most, each to an https:// address; 10-second timeout. The text is stored, never executed.
Character Card import JSON request body only, 128 KiB at most. No URL is fetched and no image is parsed.
Brain import 100 MB and 50 000 episodes at most; the embedding dimension must match the brain. Episodes go through the normal ingestion queue. Never activates a persona.
Persona marketplace sources Local directories only; nothing is downloaded at run time. Every file is resolved and must stay inside its source directory, so a symbolic link pointing outside is refused. Size caps: 128 KiB per card, 32 KiB per skill, 150 KiB per avatar. An invalid article is skipped and logged.
Marketplace avatars Served by a route that returns only the .webp of a catalogued article; the source directory is not exposed as static files.

Installing or importing a persona never activates it. Activation is only done by the agent through activate_persona; no HTTP route activates a persona.

Secrets

Secret Purpose Notes
SPONGRAM_ADMIN_TOKEN Admin API; installation credential when the Cloud control plane is enabled Required. The control plane only accepts it as installation credential when it is at least 20 characters long.
SPONGRAM_INTERNAL_AUTH_TOKEN Calls from graphiti-mcp and the workers to the internal inference proxy Required by the Compose file.
SPONGRAM_ENCRYPTION_KEY Fernet key that encrypts the inference provider's API key in spongram_runtime_config If unset, a key derived from the admin token is used, so rotating the admin token makes the stored API key unreadable. Set a dedicated Fernet key.
SPONGRAM_INFERENCE_API_KEY API key of the inference endpoint Can also be set in the inference settings, where it is stored encrypted and never returned by the API.
SPONGRAM_NEO4J_PASSWORD, database DSN Storage credentials

Generate a Fernet key with:

python3 -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())"

Keep secrets in the environment or in your orchestrator's secret store. The repository's .env file is ignored by Git and .env.example carries placeholders only. See configuration.

Rate limiting

Each brain has a token bucket of SPONGRAM_RATE_LIMIT_PER_MIN requests per minute (default 100; 0 disables it). The MCP handshake methods are not charged. An exhausted bucket returns 429 with Retry-After. The limiter lives in the memory of the process.

Network exposure

Ports published by the Docker Compose file and the Docker Swarm stack file shipped in the repository:

Service Port Docker Compose Docker Swarm stack Reachable by
spongram 8091 Published (SPONGRAM_HOST_PORT, default 8091) Published Clients, through your TLS reverse proxy
graphiti-mcp 8000 Internal only Internal only spongram
postgres 5432 Internal only Internal only spongram
neo4j HTTP 7474 Published on host port 7475 (NEO4J_HTTP_PORT) Published on 7475 Operators, for administration
neo4j Bolt 7687 Published on host port 7688 (NEO4J_BOLT_PORT) Published on 7688 Operators, for administration

Recommendations:

  • Terminate TLS in front of spongram; keys and tokens travel in headers.
  • Do not expose the Neo4j ports beyond the administration network. Anyone who can reach Bolt with the Neo4j password can read every brain.
  • Do not route /_internal/ paths through a public reverse proxy.
  • /readyz, /healthz, /docs, /openapi.json and /documentation/ answer without credentials; restrict them at the reverse proxy if your policy requires it.

See the HTTP API for the authentication of each route, and the deployment pages for Docker Compose and Docker Swarm.