Skip to content

Security: pmutua/sms-parser-api

Security

SECURITY.md

Secure Flow to Use Embeddings with Online LLM (Azure OpenAI) Step 1: Data Preparation & Chunking (Offline / Backend) Event data (e.g., logs, documents) is processed and split into manageable text chunks.

Each chunk is sanitized to remove sensitive info.

Chunks are saved as RAGSnippet instances in your database.

Step 2: Embedding Generation & Storage (Backend) For each snippet missing an embedding:

Call Azure OpenAI Embedding API securely from your backend.

Convert the returned embedding vector to a storable format (e.g., bytes).

Save the embedding in your own database attached to the snippet.

No embeddings or raw text snippets are stored on Azure; you control data storage.

Step 3: Query Processing (Backend) User sends a query to your API endpoint.

Your backend generates an embedding vector for the query using Azure OpenAI Embedding API.

Your backend fetches top-k RAG snippets from your database by comparing cosine similarity between stored snippet embeddings and the query embedding.

This retrieval happens locally and securely in your environment.

Step 4: Contextualized LLM Query (Backend) Your backend constructs a prompt combining the user query + retrieved snippet texts.

Calls Azure OpenAI Chat Completion API with the prompt and streams the response back to the user.

Only the prompt and query are sent to Azure; no full dataset is sent.

Your backend controls and logs all calls for audit and compliance.

Step 5: Response Streaming to Client Your API streams the LLM response back to the client.

The client renders the answer progressively for a better UX.

No sensitive data leaks from your backend since all data is sanitized and embeddings stored locally.

Security Highlights Aspect Your Setup / Best Practice Data Ownership You retain all raw text and embeddings; Azure stores none. Sensitive Data Handling Sanitization before saving chunks. API Keys Protection Keys stored securely in environment variables, never exposed client-side. Embedding Calls Performed only server-side; no direct client calls to Azure. Access Control Your API endpoint enforces authentication & rate limiting. Prompt Construction Only top-k relevant snippets included to minimize data sent. Streaming Responses Secure streaming ensures no data buffering on intermediate proxies.

Visual Flow (Simplified) plaintext Copy Edit Event Data --> Sanitize & Chunk --> Save chunks (RAGSnippet) in DB | Embed missing chunks using Azure Embedding API | User Query --> Embed query using Azure Embedding API | Retrieve top-k snippets from DB by similarity search | Build prompt = context snippets + user query | Send prompt to Azure Chat Completion API (stream=True) | Stream response back to client via your API endpoint If you want, I can also help you draft the threat model or checklist for auditing this setup! Would you like that?

You said: yes

ChatGPT said: Great! Here’s a Threat Model and Security Audit Checklist tailored for your RAG + Azure OpenAI embedding & LLM system. This will help you identify risks, verify controls, and improve security.

Threat Model for RAG + Azure OpenAI Integration Threat Category Description Impact Mitigation / Controls Data Leakage Sensitive raw text or embeddings accidentally exposed. High - Sanitize text before saving (mask_sensitive_info).

  • Store embeddings & text only in your DB.
  • Limit data sent to Azure (only queries or prompts). API Key Exposure Leakage of Azure API keys (e.g., via client code, logs). Critical - Store API keys in environment variables or secure vault.
  • Never expose keys client-side.
  • Rotate keys periodically. Unauthorized Access Attackers access your API or database without permission. Critical - Require authentication (e.g., OAuth, API keys) for all endpoints.
  • Use RBAC & audit logs.
  • Rate-limit & monitor suspicious activity. Man-in-the-Middle (MitM) Intercepted API calls or responses tampered with. Medium - Use HTTPS/TLS for all communications.
  • Validate certificates. Data Corruption Malicious or accidental modification of embeddings or chunks. Medium - Use database constraints and validation.
  • Back up data regularly. Overexposure of Context Sending too much context to LLM may leak sensitive info. Medium - Limit top-k snippets by relevance.
  • Sanitize snippets thoroughly. Replay Attacks Old queries or snippets replayed to extract info. Low - Use timestamps & request IDs.
  • Limit query repetition if needed. Denial of Service (DoS) Overloading your embedding or chat endpoints. Medium - Rate limit API requests.
  • Use caching where possible. Logging Sensitive Data Sensitive info saved in logs accidentally. Medium - Sanitize logs.
  • Use secure log management. Third-party Risks Azure service vulnerabilities or outages affect your data. Low to Medium - Review Azure SLAs & security docs.
  • Prepare fallback/retry logic.

Security Audit Checklist for Your RAG & Azure OpenAI Setup Audit Item Status / Notes Action Items Text Sanitization Are all sensitive fields masked before saving? Verify and improve mask_sensitive_info function. Embedding Storage Are embeddings stored only in your DB? Confirm no raw embeddings stored on Azure. API Key Management Are keys stored in env vars and never exposed client-side? Enforce environment variable usage and secrets management. Authentication Are all API endpoints secured? Implement authentication, e.g., token-based auth. Authorization & RBAC Is access controlled per role? Define roles and permissions; limit admin access. Network Security Is HTTPS enforced? Use HTTPS everywhere, including internal APIs. Rate Limiting & Throttling Is rate limiting configured to prevent abuse? Add rate limiting middleware. Prompt Construction Are only necessary context snippets sent? Limit top-k, sanitize snippets. Logging Are logs free of sensitive info? Sanitize and review logs regularly. Backup & Recovery Is data regularly backed up? Schedule backups and test restores. Monitoring & Alerts Are suspicious activities monitored? Set up logging alerts & anomaly detection. Incident Response Plan Is there a documented plan for breaches? Develop and test an incident response process. Azure Security Compliance Review Azure’s compliance certifications and best practices. Follow Azure security guidelines. User Data Privacy Is user data handled according to privacy regulations? Review and comply with GDPR, CCPA, etc., if applicable. Dependency & Code Review Are third-party libs checked for vulnerabilities? Use tools like Dependabot or Snyk. Streaming Response Security Is streaming implemented securely to prevent data leaks? Review streaming implementation and headers.

Summary You keep full control of all sensitive data and embeddings on your backend.

Azure only processes queries and snippets you send, no permanent storage of your raw data.

Security is critical at the boundary: sanitize data, protect API keys, authenticate all users.

Monitor, audit, and prepare for incidents continuously.

Regularly review and update your threat model as your app and environment evolve.

If you want, I can help you create example checklists or templates for audits or help implement some monitoring/logging features next! Would you like that?

There aren’t any published security advisories