How sg2technologies/safeprompt_agent works
SafePrompt is an on-device data-loss-prevention agent paired with a browser extension. The main workflow is: the extension intercepts chat prompts and uploads, sends them to the local agent, which scans text and files, applies configured policy, then masks or blocks as appropriate and records decisions locally. The agent also offers a local console and proxy-based browser coverage. Groups include detection, policy, storage, and provider/proxy subsystems. Some internal detector and extension wiring is unsampled, so those links are dashed and unverified.
Main entry points: lib.rs Scan coordinator · main.rs Agent service · server.rs CONNECT scanner · main-world-interceptor.js Page interceptor
Components 26
Browser extension
- Page interceptor
browser-extension/src/main-world-interceptor.js - Content bridge
browser-extension/src/bridge-content-script.js - Extension worker
browser-extension/src/background.js
Agent runtime
- Agent service
apps/service/src/main.rs - Local console API
crates/local_api/src/lib.rs - Binary integrity
crates/integrity/src/lib.rs - Signer verification
crates/integrity/src/authenticode.rs
Detection and policy
- Scan coordinator
crates/inspector/src/lib.rs - PII detection
crates/pii/src/lib.rs - Custom rules
crates/rules/src/lib.rs - Prompt threats
crates/prompt/src/lib.rs - File extraction
crates/file_inspector/src/lib.rs - On-device OCR
crates/ocr/src/lib.rs - Policy decisions
crates/policy/src/lib.rs - Mask or block
crates/response/src/lib.rs
Proxy and providers
- Local reverse proxy
crates/proxy/src/lib.rs - Provider adapters
crates/providers_api/src/openai_compatible.rs - CONNECT scanner
crates/connect_proxy/src/server.rs - Domain gate
crates/connect_proxy/src/sni_gate.rs - HTTP message framing
crates/connect_proxy/src/http1.rs - Interception CA
crates/connect_proxy/src/ca.rs
Local state
- Encrypted audit store
crates/storage/src/lib.rs - Finding encryption
crates/storage/src/encryption.rs - CA key persistence
crates/connect_proxy/src/ca/persistence.rs
Other components
- User
- AI chat site
Connections 26
- User → Page interceptor: enters prompt
- Page interceptor → Content bridge: passes traffic
- Content bridge → Extension worker: dispatches
- Extension worker → Local console API: requests scan
- Local console API → Agent service: reaches local agent
- Agent service → Local reverse proxy: runs
apps/service/src/main.rs - Agent service → CONNECT scanner: runs
apps/service/src/main.rs - Agent service → Local console API: runs
apps/service/src/main.rs - Agent service → Scan coordinator: configures scanning
- Scan coordinator → PII detection: checks PII
- Scan coordinator → Custom rules: checks custom rules
- Scan coordinator → Prompt threats: checks prompt attacks
- Scan coordinator → File extraction: inspects files
- File extraction → On-device OCR: uses OCR
- Scan coordinator → Policy decisions: applies policy
- Policy decisions → Mask or block: selects action
- Scan coordinator → Encrypted audit store: records decisions
- Encrypted audit store → Finding encryption: encrypts findings
crates/storage/src/lib.rs - Agent service → Binary integrity: verifies manifest
apps/service/src/main.rs - Binary integrity → Signer verification: checks signer
crates/integrity/src/lib.rs - CONNECT scanner → Domain gate: checks host
crates/connect_proxy/src/server.rs - CONNECT scanner → HTTP message framing: reads and writes
crates/connect_proxy/src/server.rs - CONNECT scanner → Interception CA: issues certificates
crates/connect_proxy/src/server.rs - Interception CA → CA key persistence: loads or saves key
crates/connect_proxy/src/ca.rs - Local reverse proxy → Provider adapters: translates requests
- AI chat site → Page interceptor: receives submission