Securing LLM applications
Prompt injection, data leaks, unsafe output and cost attacks. Attack your own app, then harden it.
How to use the lab files
The zip keeps the files of each lesson apart, and the lessons work in one flat folder. After you unzip it, sh kr-lab.sh LESSON FOLDER builds that folder as it stands after a lesson, for example sh kr-lab.sh 00-set-up-your-lab ~/krlab/securing-llm-apps.
You will build
You need
A computer with Linux, macOS, or Windows with WSL. No GPU, no cloud account and no paid tool.
Next course
- 00Set up your lab for Securing LLM applicationsCreate the lab folder of the courseSet-up15 min
- 01Build a support bot and break it with prompt injectionBuild a small support chatbot and a test harness on your own machineBuild40 min
- 02Hide an instruction in a review and measure how often the bot obeysAdd a review summary feature to your bot that reads text from outside40 min
- 03Keep secrets out of the prompt and check them in codeMeasure how often a secret in a system prompt can be extracted40 min
- 04Stop customer data from leaking with minimal context and an output filterShow how a model reveals other customers' records that sit in its context60 min
- 05Escape, sign and compare model answers before anyone trusts themFix a staff page that runs markup from a model answer, and list the images that leak data50 min
- 06Run database queries that the model cannot changeShow how a question in plain words changes a query that a model writes35 min
- 07Limit what the bot can do with least privilege and approvalGive the bot a refund tool and measure how often an injected instruction moves money45 min
- 08Control cost and abuse with limits you can measureMeasure the tokens and the time that one request costs50 min
- 09Add guardrails to the bot and measure what they missBuild an input filter and an output check around the model60 min
- 10Rebuild the bot with five secure design patterns and measure the sumPut the whole weak app in one file as a baseline for tests60 min
- 11Turn your tests into a suite with a report and a pass thresholdStore test cases in a JSON file with a category, a prompt and a check60 min
- 12Test that the rules hold against jailbreaksTell a jailbreak from a prompt injection and name four families of jailbreak55 min
- 13Build the hardened bot and write its security reportCombine the defences of the course in one hardened botBuild60 min
- 14Close the last gap in the bot and count what it costsAdd one code check against the attack that still gets through60 min
- 15Review a chatbot before it goes live and fix what you findFind the planted weaknesses in a chatbot by reading its code and by testing itTest90 min
Work roles
Work roles this course supports
The course helps you to prepare for these roles of the NICE Workforce Framework for Cybersecurity (NIST SP 800-181 Rev. 1). No single course covers a whole role, and KaliRange is not a certification body.
- Secure Software Development
DD-WRL-003a main skill of the roleYou fix prompt injection, data leaks and unsafe output in the code of an LLM app. - Software Security Assessment
DD-WRL-005a main skill of the roleYou attack your own LLM app, measure attack rates and write a security review.