Identity and access lab: OpenID Connect, OAuth 2.0 and JWTs

This lab gives each student a real OpenID Connect provider, Dex, and a small web app that signs people in with it. The app runs twice: a weak copy with the classic mistakes and a safe copy with each one fixed. Students attack the weak copy, watch the safe one refuse, and find each attack in the app’s log.

Everything is made up: a college, four accounts and three apps. Every attack is against the student’s own copy, which has no route to the internet and none to any other student. Nothing is downloaded and no AI service is called.

What students learn

How a web app knows who is using it. They read both copies’ session cookies, plant a session id that the weak copy keeps after sign-in, and reuse a cookie after logging out. They follow the OAuth 2.0 code flow with PKCE step by step, see the provider refuse an unknown redirect, a reused code and a wrong verifier, and try login CSRF.

They check an ID token by hand, six checks in all, and forge two tokens for a teacher: one with alg none and one signed with the public key. The weak copy hands over every mark; the safe copy refuses both. They sign and check a SAML assertion, try signature wrapping, and run an access review that finds eight problems.

Run it in your browser

The lab starts three services. idp is Dex 2.46, at http://idp:5556/dex, with three apps registered. app is the Noticeboard, weak on port 8000 and safe on port 8001. tools is Python with short scripts in steps/. The terminal beside the lab reaches them with docker exec, docker logs and curl.

  1. Open the Container page. Open Build on the bar and choose Run a container. Anybody may open it, and the Git lab and the SQL lab start with no account. Every other lab needs a free account: create one, sign in, then press Start.
  2. Find the lab. The Sample labs card lists every sample. Find Identity and access: OpenID Connect, OAuth 2.0 and JWTs.
  3. Press Start. Start runs it as it is, in one press. Edit the file first opens the compose file so you can change it before you start. It is ready in under a minute.
  4. Open it. On the lab's page, press Open terminal and type docker exec tools python3 steps/flow.py amira to follow one sign-in through Dex, step by step.

What to ask students to hand in

A short report on their own copy: for three of the weak app’s mistakes, the output that shows the attack, the output that shows the safe copy refusing it, and the log line that would spot it; then the access review’s findings with a decision for each. Nothing is marked automatically: the decisions show whether it was understood.

A basic lesson on this lab

Identity Provider Basics is a small lesson worked in this lab. In it a student reads the provider’s discovery document, follows one sign-in, checks an ID token and compares the two copies’ session cookies. It attacks nothing.

Free personal accounts have it in the Basics module, which is on Home, and every college can copy it from the Library's Basics folder. It is deliberately small: it shows a teacher what a lesson worked in a lab is, and the lab does the rest. The module Identity and access goes further in six lessons.

The code on GitHub

The compose file has no Dockerfile: it runs two stock public images pinned by digest, Dex (Apache 2.0) and Python 3.12 on Alpine (the PSF licence), neither distributed by us. The app and the scripts run as an unprivileged account, and the file writes Dex’s settings, the app and the scripts from fixed text when it starts. The passwords and client secrets belong to made-up accounts and are written down on purpose.

Set it as work

Say in the task what to hand in.

  1. Make the lab. In your module add a task and choose the Container lab card, then In a GitHub repository. Give https://github.com/mitsurutech/lab-idp-lab with the branch main. The compose file is the default, compose.yaml. Fork the repository first if you want to change it, for example to add accounts or apps of your own.
  2. Publish and try it. Publish pins the commit you were shown, so a later change in the repository does not alter a lab you have already set. Start your own copy first.
  3. Hand it out. Assign it like any task, with a due date if you want one, and say in the task what to do and what to hand in.
  4. Mark what is handed in. Open a student’s copy and the work they handed in, mark it, and send it back with a reason if it needs more.

Try this lab, and what it costs

A free personal account can work through the basic lessons in this lab, with enough free credit each month to follow most lessons and no card. For a class, a school or college has its first 365 days free for up to 50 students, then pays per student a year, with every lab included and staff free.

Questions people ask

Is it safe to teach attacks like these?
Every attack is against the weak app in the student’s own copy, which cannot reach the internet. Each lesson that attacks opens with the rule: only your own lab, a real system only with written permission, and the Computer Misuse Act 1990. Each attack ends with the fix and the log line that spots it.
Why do the scripts sign in, and not the browser?
The provider’s address, http://idp:5556/dex, only works inside the lab’s own network. So a small browser written in Python plays the person, keeps the cookies and prints every redirect, which also shows students each step a real browser hides.
Why does single sign-on ask for the password each time?
Dex keeps no sign-in session of its own. Most identity providers do, so the second app opens without a password. The lab still shows the same person behind both apps.
Is the SAML part a real SAML library?
No. It is a script written for the lab, with Python’s own canonical XML and a 1024-bit key from a fixed seed, so every step can be read. Real SAML uses a maintained library such as xmlsec, and the lesson says so.
Does it cost anything or use credits for AI?
No AI is used, so nothing is charged for it. The lab runs like any other container lab.