AI Security
End‑to‑End Encryption for Secure AI Summarization of Customer Documents
TL;DR: Encrypt documents before they leave your premises, store keys in a dedicated secret manager, use Cloudflare Workers AI’s POST /v1/ai/run endpoint with Content‑Encryption headers, and delete the plaintext copy immediately after the AI returns a summary. Verify the model’s data‑retention policy and audit each step.
Why encryption matters for AI summarization
AI summarization services typically receive raw text, process it in memory, and then discard it. However, the moment a document is uploaded it becomes vulnerable to interception, accidental logging, or unintended retention by the provider. For small companies handling contracts, medical records, or proprietary designs, a breach can mean regulatory fines and loss of trust.
Step‑by‑step encryption workflow
- Generate a per‑document data‑encryption key (DEK). Use a secret‑management service (e.g., AWS KMS, GCP Secret Manager, or HashiCorp Vault). Store the DEK only in memory; never write it to disk.
- Encrypt the document locally. Use an authenticated encryption algorithm such as AES‑256‑GCM. The ciphertext, along with the IV and authentication tag, is what you will send to the AI service.
- Wrap the DEK with a master key. The master key lives in your secret manager and is never exposed to the AI runtime.
- Upload the ciphertext to Cloudflare Workers AI. Include the following HTTP headers:
The Workers AI endpointContent-Type: application/octet-stream Content-Encryption: aes256gcm Encryption-Key: <base64‑wrapped‑DEK>POST /v1/ai/runaccepts binary payloads, so you can pass the encrypted bytes directly. - Ask the model to summarize the encrypted payload. Cloudflare Workers AI currently does not decrypt data, so you must decrypt locally after the response. The typical pattern is:
This keeps the plaintext never on the provider’s network.ciphertext = readFile('doc.enc') summary = callWorkerAI(ciphertext) plaintext = decrypt(ciphertext, DEK) // use plaintext to verify the summary, then discard - Securely delete the plaintext. Overwrite the in‑memory buffer and, if a temporary file was created, use OS‑level secure delete (e.g.,
srmon Linux).
Hardening the surrounding workflow
- Network isolation. Run the encryption step in a VPC or private subnet with no outbound internet access except the Cloudflare edge IPs.
- Audit logs. Record the document ID, hash of the plaintext, timestamp, and the user who triggered the summarization. Store logs in an immutable store (e.g., Cloudflare Logpush to an S3 bucket with Object Lock).
- Provider data‑retention checks. Review Cloudflare’s data‑privacy statement. As of the latest docs, Workers AI does not retain request bodies, but you should capture the provider’s guarantee in a compliance artifact.
- Rate limiting. Apply a per‑user quota to prevent accidental mass uploads that could expose large data sets.
Integrating with existing no‑code automation tools
If you use Zapier or Make to orchestrate the summarization, insert a custom code step that performs the encryption and key‑wrap before calling the Cloudflare HTTP request action. Ensure the secret manager’s API token is stored in the platform’s “private variable” store with read‑only permissions.
Testing the pipeline
Run a set of synthetic documents that contain known markers (e.g., CONFIDENTIAL) and verify that the summary does not expose the marker text verbatim. Use OWASP GenAI’s “Data Leakage” test matrix as a reference.
When to fall back to a self‑hosted model
If regulatory constraints forbid any off‑premise processing, consider deploying an open‑source LLM (e.g., Llama 2) on a private server and run the same encryption‑then‑decrypt pattern locally. The same workflow applies; only the endpoint changes.
Summary checklist
- Generate per‑document DEK and wrap with a master key.
- Encrypt locally with AES‑256‑GCM.
- Send ciphertext to Cloudflare Workers AI using
Content‑Encryptionheaders. - Decrypt response locally, verify, then securely erase plaintext.
- Log hash, user, and timestamp in an immutable store.
- Review provider retention policy and enforce rate limits.
Following this checklist gives small teams the confidence to leverage powerful summarization models without exposing raw customer data.
FAQ
- Can I skip the decryption step and let the provider summarize encrypted data? Not today. Current LLMs cannot operate on ciphertext. Decryption must happen on your side after the model returns a summary.
- What if the provider logs request headers? Include only non‑secret identifiers in headers. The
Encryption-Keyheader should contain the wrapped DEK, which is meaningless without the master key. - Is AES‑256‑GCM mandatory? Any AEAD cipher is acceptable, but AES‑256‑GCM is widely supported and meets NIST recommendations (NIST AI RMF).
- How often should I rotate the master key? Follow your organization’s key‑rotation policy, typically every 90 days for production workloads.
Need a practical AI security review?
AISecAll reviews prompts, tool permissions, document flows, and agent behavior so small teams can use AI without guessing where the risk sits.