Skip to content
Hafiz Syed Shah Ali

All projects

Case study

Secure RAG Assistant

An AI assistant on this site that answers questions about my work from public sources only, designed against the OWASP Top 10 for LLM Applications.

View on GitHub (opens in a new tab)

The problem

Recruiters and clients ask the same questions: what I have built, which tools I use, where I can work. I wanted them to get a direct answer with sources, at any hour.

But an AI assistant on a public site is also an attack surface: anyone can try prompt injection, try to extract its instructions, or try to run up its cost.

Requirements

  • Public information only: it must never reveal anything that is not already on this site, my CV or my journal.
  • It can only return text: no tools, no write access.
  • Model use is prepaid or free, with a daily cost limit.
  • No stored answers or conversations. Questions are kept for a limited time in a private log (see the privacy page).
  • The site’s static pages, security headers and Content Security Policy stay unchanged.

What I built

  • Knowledge: Built from my public pages, CV, FAQ and journal. The build scans every piece for personal data and secrets and stops on a finding. The index is committed, so every change is reviewed in git.1
  • Search: Embeddings plus a typo-tolerant keyword score, so informal and misspelt questions still find the right content. When nothing relevant is found, the model is not called and a fixed reply is sent.2
  • Answering: Multi-provider fallback, called directly over HTTPS without an LLM SDK or framework. If one provider fails, another one answers.
  • Delivery: Answers reach the browser in whole sentences, with the sources under every answer.

How it works

  1. Questionfrom the chat panel
  2. Pre-checksinjection and extraction attempts
  3. Searchread-only public index
  4. Modeltext only, no tools
  5. Output filterlinks, contact data, leak check
  6. Answerwith its sources
Build time: my public pages, CV, FAQ and journal pass a personal-data and secret scan into an index that is committed to git. Each question: pre-checks, a search of the read-only index, the model, then the output filter and leak check, and the answer with its sources.

Security decisions

Mapped to the OWASP Top 10 for LLM Applications (2025), by category.3 The full table is on How this site is secured.2

  • Prompt injection (LLM01): Pre-checks on the question and the whole conversation history before any model call. Site content and history are passed to the model as data, never as instructions.
  • Sensitive information disclosure (LLM02): Public knowledge only. The output filter removes phone numbers and any email address other than the public contact address.
  • Improper output handling (LLM05): Answers are plain text, never rendered as HTML. Links are clickable only when they point to an allow-listed site.
  • Excessive agency (LLM06): The model has no tools, functions or credentials.
  • System prompt leakage (LLM07): Extraction attempts are refused before the model call. A leak check stops answers that reveal the instructions. Refusals are fixed texts on the server.
  • Unbounded consumption (LLM10): Per-visitor and global rate limits, length limits, timeouts and a daily cost limit on prepaid usage. If the rate-limit store cannot be reached, the assistant fails closed.

Results

  • Live on shahali.dev since October 2026. Try it with the Ask Professor button.
  • Answers come with their sources. Out-of-scope, personal and attack prompts get fixed replies.
  • Before each release, an evaluation suite of normal questions, attack prompts and regression cases from earlier findings runs against a local server. Attack and regression cases must all pass.2
  • Last full evaluation run, on 30 November 2026: 167 of 168 cases passed, including all 45 regression cases. The one failure was fixed, and its case passed 3 of 3 runs afterwards.5
  • A written threat model with trust boundaries and the residual risks I accepted.4
  • The code is public on GitHub, running on a fictional sample knowledge base and an example configuration. The configuration this site uses stays private.5

What I’d do next

  • Pre-checks cannot catch every new phrasing of an injection attempt. Today each new attack prompt goes into the evaluation suite; a second, model-based check could catch more.