Security
CodeSpar security architecture including RBAC roles, permission mapping, token-based approval system, audit trail with hash chain integrity, cross-channel identity resolution, and safety guardrails.
Security
CodeSpar implements defense-in-depth security with role-based access control (RBAC), a token-based approval system, an append-only audit trail with hash chain integrity, cross-channel identity resolution, and mandatory safety guardrails for high-risk operations.
RBAC — Role-Based Access Control
Roles
CodeSpar defines six roles, ordered from most to least privileged:
| Role | Description | Typical User |
|---|---|---|
owner | Full control over project, agents, and configuration | Project creator, tech lead |
maintainer | Can execute all commands, manage autonomy and links | Senior developers |
operator | Can execute tasks and deploys, limited configuration | DevOps engineers |
reviewer | Can review PRs and view status, no execution | Junior developers, QA |
read-only | Can only view status, logs, and memory stats | Stakeholders, observers |
emergency_admin | Can execute kill without approval at any autonomy level | On-call engineers |
Permission Matrix
Each role maps to a set of permitted intents (commands):
| Permission | owner | maintainer | operator | reviewer | read-only | emergency_admin |
|---|---|---|---|---|---|---|
status | Yes | Yes | Yes | Yes | Yes | Yes |
help | Yes | Yes | Yes | Yes | Yes | Yes |
logs | Yes | Yes | Yes | Yes | Yes | Yes |
context / memory | Yes | Yes | Yes | Yes | Yes | Yes |
whoami | Yes | Yes | Yes | Yes | Yes | Yes |
register | Yes | Yes | Yes | Yes | No | Yes |
prs | Yes | Yes | Yes | Yes | Yes | Yes |
review | Yes | Yes | Yes | Yes | No | Yes |
instruct | Yes | Yes | Yes | No | No | Yes |
fix | Yes | Yes | Yes | No | No | Yes |
link | Yes | Yes | No | No | No | Yes |
unlink | Yes | Yes | No | No | No | Yes |
deploy | Yes | Yes | Yes | No | No | Yes |
rollback | Yes | Yes | No | No | No | Yes |
approve | Yes | Yes | Yes | No | No | Yes |
autonomy | Yes | Yes | Limited* | No | No | Yes |
kill | Yes | Yes | No | No | No | Yes |
* Operators can set autonomy up to L4. Only owners and maintainers can set L5.
15 Permissions
The complete list of permissions that map to command intents:
| # | Permission | Intent | Risk Level |
|---|---|---|---|
| 1 | view:status | status | low |
| 2 | view:help | help | low |
| 3 | view:logs | logs | low |
| 4 | view:memory | context, memory | low |
| 5 | view:identity | whoami | low |
| 6 | view:prs | prs | low |
| 7 | manage:identity | register | low |
| 8 | execute:review | review | low |
| 9 | execute:task | instruct | medium |
| 10 | execute:fix | fix | medium |
| 11 | manage:link | link, unlink | medium |
| 12 | execute:deploy | deploy | high |
| 13 | execute:rollback | rollback | critical |
| 14 | manage:autonomy | autonomy | medium |
| 15 | execute:kill | kill | critical |
Approval System
High-risk actions require explicit human approval before execution. The approval system is token-based with several safety mechanisms.
How It Works
- A user requests a high-risk action (e.g.,
@codespar deploy production) - CodeSpar generates a unique approval token (e.g.,
dp-a1b2c3) - A notification is sent to connected channels with the token
- An authorized user approves with
@codespar approve dp-a1b2c3 - The action executes
Approval Token Format and Prefixes
Approval tokens follow the format {prefix}-{random}, where the prefix indicates the type of action being approved:
| Prefix | Action | Example Token |
|---|---|---|
dp- | Deploy | dp-a1b2c3 |
rb- | Rollback | rb-x9y8z7 |
sg- | Suggested action (auto-proposed by L2+ agents) | sg-m4n5o6 |
tk- | Task execution (at certain autonomy levels) | tk-p7q8r9 |
kl- | Kill switch (emergency stop) | kl-j1k2l3 |
The random portion is a cryptographically secure 6-character alphanumeric string, providing sufficient uniqueness for the token's 30-minute lifespan.
Approval Token Properties
| Property | Value |
|---|---|
| Format | {prefix}-{random} (e.g., dp-a1b2c3) |
| Expiration | 30 minutes (configurable via APPROVAL_TIMEOUT) |
| Single-use | Yes — token is invalidated after use |
| Cross-channel | Yes — approve from any connected channel |
Safety Mechanisms
Self-Approval Blocking
A user cannot approve their own request. This prevents a single person from both requesting and approving a high-risk action.
Quorum
For production deployments, organizations can configure a quorum — the minimum number of approvals required:
| Configuration | Default | Description |
|---|---|---|
APPROVAL_QUORUM | 1 | Number of approvals required |
APPROVAL_TIMEOUT | 30m | Time before approval expires |
ALLOW_SELF_APPROVE | false | Whether requestor can self-approve |
Expiration
Approval tokens expire after 30 minutes (configurable). Expired tokens cannot be used:
Audit Trail
Every action in CodeSpar is recorded in an append-only audit log with cryptographic hash chain integrity.
What Gets Logged
| Event Type | Examples |
|---|---|
| User commands | All 17 commands and their results |
| Agent actions | Task execution, PR review, deploy, auto-actions |
| System events | Webhook receipt, agent spawn/terminate, errors |
| Access control | Permission denials, role changes |
| Approvals | Approval requests, grants, denials, expirations |
Hash Chain Integrity
Each audit entry includes a SHA-256 hash that chains to the previous entry, creating a tamper-evident log.
How It Works
Every audit entry contains these fields for integrity verification:
The hash for each entry is computed as:
Hash Chain Verification
The chaining works as follows:
- Entry 0 (genesis):
previousHashis"0"(the initial seed). ItshashisSHA-256("0" + timestamp + actor + action + result + metadata). - Entry 1:
previousHashis Entry 0'shash. Itshashincludes Entry 0's hash in the computation. - Entry N:
previousHashis Entry N-1'shash. The chain continues.
To verify the audit trail's integrity:
If any entry has been modified, its hash will not match the recomputed value, and all subsequent entries' previousHash fields will be invalid. This makes tampering detectable.
Example Chain
If Entry 1 is modified, its hash changes from "b7c1..." to something else. Entry 2's previousHash still says "b7c1...", which no longer matches Entry 1's actual hash — tampering detected.
Retention
| Setting | Default |
|---|---|
| Retention period | 365 days |
| Storage | File-based (.codespar/audit/) or PostgreSQL |
| Export | Available via Audit API pagination |
Cross-Channel Identity Resolution
CodeSpar maintains a cross-channel identity system that links users across WhatsApp, Slack, Discord, and Telegram. This is critical for consistent RBAC enforcement, cross-channel approvals, and unified audit trails.
How the Identity Store Works
The identity store maintains a persistent mapping between channel-specific user IDs and a unified CodeSpar identity.
Data Structure
Registration and Linking Flow
-
First contact: When a user sends any message from a channel, CodeSpar creates a temporary identity record with the channel-specific ID and a default
read-onlyrole. -
Registration: The user sends
@codespar register John Silva. CodeSpar:- Checks if an identity with display name "John Silva" already exists
- If not: creates a new identity with the display name and links the current channel
- If yes: links the current channel to the existing identity
-
Cross-channel linking: The same user sends
@codespar register John Silvafrom a different channel (e.g., WhatsApp after already registering from Slack). CodeSpar:- Finds the existing identity with display name "John Silva"
- Adds the WhatsApp channel identity to the existing record
- Both channels are now linked under one identity
-
Identity resolution: On every subsequent message, CodeSpar looks up the channel-specific user ID in the identity store. If found, the message is attributed to the resolved identity, and the identity's RBAC role is applied.
Storage
Identity records are stored in the identity store:
- File storage:
.codespar/identities/directory (one JSON file per identity) - Database:
identitiestable whenDATABASE_URLis configured
Cross-Channel Capabilities
With linked identities:
- Approve from any channel: A deploy requested in Slack can be approved from WhatsApp
- Unified audit trail: All actions across channels are attributed to the same identity
- Consistent permissions: RBAC role applies regardless of which channel is used
- Single notification: Avoid duplicate alerts when the same user is on multiple channels
Identity Lookup
See the Memory API for full details.
Safety Guardrails
Regardless of autonomy level, RBAC role, or configuration, CodeSpar enforces hard safety guardrails.
Never Auto-Executed
These actions always require explicit human approval:
| Action | Reason |
|---|---|
| Production deployments | Direct user impact, requires verification |
| Rollbacks | Destructive, may cause data inconsistency |
| Data migrations | Irreversible database changes |
| Security-sensitive changes | Credential rotation, permission changes, secret updates |
| Infrastructure modifications | Scaling, networking, resource allocation changes |
| Kill switch | Emergency stop affects all running agents |
Guardrail Enforcement
Guardrails are enforced at the engine level and cannot be overridden by configuration, RBAC roles, or autonomy settings. Even at L5 (Full Auto) with owner role:
The only exception is emergency_admin for the kill command, which can be executed without approval to enable rapid incident response.
Rate Limiting
Note: Rate limiting is not yet implemented. This is a roadmap item planned for a future release.
The planned rate limiting system will enforce:
| Limit | Planned Value | Scope |
|---|---|---|
| Commands per user per minute | 10 | Per identity |
| API requests per minute | 60 | Per API key |
| Webhook events per minute | 100 | Per repository |
| Agent spawns per hour | 20 | Per project |
Rate limiting will be configurable per organization and will apply to both chat commands and API requests.
Security Checklist
When deploying CodeSpar to production:
- Set
ANTHROPIC_API_KEYandGITHUB_TOKENas environment variables (never in code) - Use HTTPS for
WEBHOOK_BASE_URL - Configure reverse proxy or API gateway for authentication
- Set appropriate autonomy level (L1 recommended for production)
- Assign RBAC roles to all team members
- Verify audit trail is being written (check
.codespar/audit/) - Set up monitoring for agent errors and unusual activity
- Configure approval quorum for production deploys (2+ recommended)
- Disable self-approval (
ALLOW_SELF_APPROVE=false) - Review and test the kill switch procedure
Next Steps
- Graduated Autonomy — Autonomy level details and RBAC interaction
- Audit API — Query and verify the audit trail
- Multi-Channel Setup — Cross-channel identity linking
- Configuration — All environment variables