Production infrastructure for AI agents
Website · Documentation · Guides · Core · Template · Discord
systemprompt-security
Security infrastructure for systemprompt.io AI governance: JWT, OAuth2 token extraction, scope enforcement, ChaCha20-Poly1305 secret encryption, and the four-layer tool-call governance pipeline. Handles JWT token generation and validation, multi-method token extraction, and bot/scanner detection.
Layer: Infra — infrastructure primitives (database, security, events, etc.) consumed by domain crates. Part of the systemprompt-core workspace.
Overview
This crate provides security primitives for the systemprompt.io platform. It handles JWT token generation and validation, multi-method token extraction, and bot/scanner detection.
Architecture
src/
├── lib.rs # Module exports and public API
├── auth/
│ ├── mod.rs # Auth module re-exports
│ └── validation.rs # AuthValidationService, AuthMode, token validation
├── extraction/
│ ├── mod.rs # Extraction module re-exports
│ ├── token.rs # TokenExtractor with fallback chain
│ ├── header.rs # HeaderExtractor/HeaderInjector for context propagation
│ └── cookie.rs # CookieExtractor for cookie-based auth
├── jwt/
│ └── mod.rs # JwtService for admin token generation
├── services/
│ ├── mod.rs # Services module re-exports
│ └── scanner.rs # ScannerDetector for bot detection
└── session/
├── mod.rs # Session module re-exports
├── generator.rs # SessionGenerator for session token creation
└── claims.rs # ValidatedSessionClaims data structure
auth
Authentication validation service with configurable enforcement modes.
| Export | Type | Purpose |
|---|---|---|
AuthValidationService |
Struct | Validates JWT tokens and creates RequestContext |
AuthMode |
Enum | Required, Optional, Disabled enforcement levels |
extraction
Token extraction from multiple sources with fallback chain support.
| Export | Type | Purpose |
|---|---|---|
TokenExtractor |
Struct | Extracts tokens from headers/cookies with configurable fallback |
ExtractionMethod |
Enum | AuthorizationHeader, McpProxyHeader, Cookie |
TokenExtractionError |
Enum | Specific error types for extraction failures |
HeaderExtractor |
Struct | Extracts trace_id, context_id, agent_name from headers |
HeaderInjector |
Struct | Injects RequestContext fields into outgoing headers |
HeaderInjectionError |
Struct | Error type for header injection failures |
CookieExtractor |
Struct | Dedicated cookie-based token extraction |
CookieExtractionError |
Enum | Cookie-specific error types |
jwt
JWT token generation for administrative access.
| Export | Type | Purpose |
|---|---|---|
JwtService |
Struct | Generates admin JWT tokens with HS256 |
AdminTokenParams |
Struct | Configuration for admin token creation |
services
Security services for request classification.
| Export | Type | Purpose |
|---|---|---|
ScannerDetector |
Struct | Detects bot/scanner requests by path, user-agent, velocity |
session
Session token generation and claim validation.
| Export | Type | Purpose |
|---|---|---|
SessionGenerator |
Struct | Generates session-scoped JWT tokens |
SessionParams |
Struct | Configuration for session token creation |
ValidatedSessionClaims |
Struct | Extracted claims after JWT validation |
Usage
[]
= "0.2.1"
Token Extraction
use ;
let extractor = standard;
let token = extractor.extract?;
let browser_extractor = browser_only
.with_cookie_name;
Authentication Validation
use ;
let service = new;
let context = service.validate_request?;
Admin Token Generation
use ;
let params = AdminTokenParams ;
let token = generate_admin_token?;
Session Token Generation
use ;
use ;
let generator = new;
let params = SessionParams ;
let token = generator.generate?;
Dependencies
| Crate | Purpose |
|---|---|
systemprompt-models |
Shared models (JwtClaims, UserType, Permission) |
systemprompt-identifiers |
Typed identifiers (UserId, SessionId, TraceId) |
jsonwebtoken |
JWT encoding/decoding with HS256 |
axum |
HTTP types (HeaderMap, HeaderValue) |
chrono |
Timestamp handling |
tracing |
Debug logging for extraction errors |
License
BSL-1.1 (Business Source License). Source-available for evaluation, testing, and non-production use. Production use requires a commercial license. Each version converts to Apache 2.0 four years after publication. See LICENSE.
systemprompt.io · Documentation · Guides · Live Demo · Template · crates.io · docs.rs · Discord
Infra layer · Own how your organization uses AI.