Key takeaways
- Adding an AI chatbot, document assistant, or RAG search bar to a web application introduces four new failure modes that standard web frameworks do not guard against automatically: cross-tenant RAG leakage, prompt injection, XSS via model output, and token-exhaustion 'denial of wallet' attacks.
- Never rely on system-prompt instructions ('do not share other customers' data') for authorization—enforce tenant and role filters strictly inside your database and vector queries before retrieval.
- Since August 2, 2026, EU AI Act Article 50 makes clear user-facing AI disclosure mandatory for chatbots and AI-generated content across Cyprus and the EU.
- Engineering secure AI features requires strict server-side API proxies, output schema validation, token-aware rate limiting, and clean streaming performance.
On this page (6 sections)
- Five Non-Negotiable Architecture Rules for AI Web Features
- 1. Enforce Authorization in the Vector Query — Never in the Prompt
- 2. Treat Every Model Output as Untrusted User Input
- 3. Defend Against "Denial of Wallet" Token Exhaustion
- 4. Build EU AI Act Article 50 Transparency Into the UI
- 5. Protect Core Web Vitals & Streaming Reliability
Across global SaaS products, fintech client portals, and modern corporate websites, embedded AI features—conversational assistants, semantic document search (RAG), and automated onboarding helpers—have quickly become standard user expectations.
Yet shipping an LLM endpoint inside a production web application is fundamentally different from shipping a normal REST route. Standard web security checklists rarely cover cross-tenant vector retrieval leaks, prompt-driven XSS, wallet-draining token floods, or EU AI Act transparency rules. Here is the practical engineering baseline we apply when building and reviewing AI-powered web platforms in Cyprus and internationally.
Production AI Web Engineering Guardrails
Pre-Filter
Vector Isolation
Enforce tenant_id & RBAC before LLM context
Untrusted
Model Output Rule
Validate tool schemas & block Markdown/HTML XSS
Token Cap
Denial-of-Wallet
Rate-limit by token cost + bot protection
Art. 50
UI Transparency
Clear AI disclosure active across EU since Aug 2026
Five Non-Negotiable Architecture Rules for AI Web Features#
1. Enforce Authorization in the Vector Query — Never in the Prompt#
The most dangerous bug in multi-tenant RAG portals is indexing all customer documents into one shared vector collection and asking the LLM to "only answer questions about the logged-in user." That fails instantly against prompt injection.
- Correct pattern: Extract the authenticated
tenant_idandrolestrictly from the verified server-side session, pass them as mandatory metadata filters directly into your vector search query (WHERE tenant_id = $1 AND access_level <= $2), and only inject already-authorised chunks into the prompt. - Bonus benefit: This aligns directly with OWASP Top 10 (2025/2026) A01 Broken Access Control.
2. Treat Every Model Output as Untrusted User Input#
An LLM prompted by external web pages, uploaded PDFs, or adversarial chat messages can be coerced into outputting malicious Markdown links (javascript: URIs), tracking-pixel image tags ( that silently exfiltrate conversation secrets when the browser loads the image!), or malformed JSON tool calls.
- Disable raw HTML rendering in chat Markdown parsers and enforce a strict
Content-Security-Policy(img-src 'self') so exfiltration pixels cannot fire outbound requests from the user's browser. - Validate every tool/function call with a strict server-side schema validator (such as Zod) and verify permissions again inside the backend handler before executing any database read or mutation.
3. Defend Against "Denial of Wallet" Token Exhaustion#
Unlike traditional static pages that cost fractions of a cent to serve, an unprotected /api/chat endpoint backed by frontier LLM APIs can burn thousands of euros overnight under scripted bot traffic.
| Defence Layer | Implementation Detail |
|---|---|
| Bot & Abuse Gate | Protect anonymous/public AI endpoints with invisible verification (such as Cloudflare Turnstile) before minting a short-lived chat session |
| Input & Output Ceilings | Enforce hard character caps on user prompts, trim conversation history windows, and set explicit max_tokens per response |
| Token-Aware Rate Limiting | Throttle by both requests-per-minute AND rolling daily token budget per IP/account—failing closed cleanly when exceeded |
| Edge & Semantic Caching | Cache frequent FAQ/documentation queries so identical questions never hit the LLM API repeatedly |
| Isolated Server Proxy | Route all LLM calls through a private backend service (never exposing provider API keys to the browser bundle) |
4. Build EU AI Act Article 50 Transparency Into the UI#
Since August 2, 2026, EU AI Act Article 50 transparency rules apply across Cyprus and all EU member states. Good UX and compliance reinforce each other:
- Label AI chat widgets and AI-generated summaries unambiguously ("AI Assistant — responses are generated automatically").
- Cite source documents clearly in RAG answers so users can verify facts directly instead of trusting hallucinations blindly.
- Offer an obvious, one-click handover to a human contact form or support channel.
5. Protect Core Web Vitals & Streaming Reliability#
Never let heavy AI widgets degrade page-load speed or Google SEO rankings:
- Lazy-load interactive chat widgets only on user intent so initial HTML stays lightweight and fast.
- Stream responses cleanly with strict upstream timeouts and friendly fallback messages so a slow upstream LLM provider never locks up your web server workers.
AI Web Feature Launch Security Checklist
- Confirm LLM provider API keys exist only on a private backend service—never inside client-bundled JavaScript.
- Verify multi-tenant vector/RAG queries filter by server-verified tenant_id and user role before retrieval.
- Sanitise rendered chat Markdown strictly and enforce CSP blocking untrusted external images and inline scripts.
- Apply input length caps, max_tokens ceilings, bot protection, and rolling token budgets to stop Denial-of-Wallet abuse.
- Add clear EU AI Act Article 50 user disclosures and a direct fallback path to human contact.
- Run targeted prompt-injection and authorization tests before production launch.
Frequently asked questions
Can a system prompt stop a chatbot from leaking another customer's data?
What is a 'Denial of Wallet' attack on an AI web application?
What does EU AI Act Article 50 require for a business website chatbot in Cyprus?
Written by
Kleanthis Savva
Director & Principal Consultant — Syntify Ltd, Limassol
Director at Syntify Ltd in Limassol, Cyprus, advising organisations across Cyprus and internationally on cybersecurity, independent security audits, NIS2 & DORA readiness, resilient cloud/hybrid infrastructure, and IT strategy.