Skip to content

fix: make the sensitive_data_exposure lab usable under Docker Compose - #581

Open
PRAteek-singHWY wants to merge 1 commit into
adeyosemanputra:masterfrom
PRAteek-singHWY:fix/sensitive-data-lab-access
Open

PRAteek-singHWY wants to merge 1 commit into
adeyosemanputra:masterfrom
PRAteek-singHWY:fix/sensitive-data-lab-access

Conversation

@PRAteek-singHWY

@PRAteek-singHWY PRAteek-singHWY commented Nov 5, 2026 •

Copy link
Copy Markdown

Summary

The Sensitive Data Exposure lab couldn't be used under Docker Compose. Its hostname had underscores, which Django rejects, and once that was out of the way, logging into the lab replaced PyGoat's session cookie and ForwardAuth locked you out. This PR fixes both, so the lab loads and you can log into it while staying logged into PyGoat.

Problem / Motivation

  1. Lab hostnames were lab-<user>-<lab_name>.<domain>, and every lab name has an underscore. The Flask labs don't care, but sensitive_data_exposure is a Django app and answers every request with DisallowedHost (400), so not even its login page loads.
  2. PyGoat shares its session cookie with the lab subdomains so traefik_auth_verify can check who owns the lab. The lab uses the same default cookie name, sessionid. After logging into the lab, the browser sends two sessionid cookies, Django keeps the lab's one, and ForwardAuth returns 401 for every page after the login.

Fixes #580

Solution / Approach

  • Hostname: a new _get_lab_hostname() builds the hostname with - in place of _ in the lab part, for example lab-alice-sensitive-data-exposure.lvh.me. start_lab returns that URL, and the Traefik Host() rule uses it. Container names don't change, so the quota, stop and list logic is untouched. traefik_auth_verify accepts both the dashed and the old underscore form of each known lab, so labs that are already running keep working until they're restarted.
  • Session cookie: set SESSION_COOKIE_NAME = "pygoat_sessionid" next to the other shared-cookie settings, so no lab can replace PyGoat's session. Nothing reads the cookie by name, so no other code changes.

Files Changed

File Change
challenge/views.py Add _get_lab_hostname(), use it for the returned lab URL and the Traefik Host() rule
introduction/views.py Accept the dashed lab name in traefik_auth_verify
pygoat/settings.py Set SESSION_COOKIE_NAME = "pygoat_sessionid"
challenge/tests.py Test that start_lab returns a dashed URL and Host rule, while the container name stays the same
introduction/tests.py Tests for dashed hostnames (owner allowed, other user forbidden) and for a lab sessionid sent next to PyGoat's

Impact

  • Lab URLs change from lab-<user>-xss_lab... to lab-<user>-xss-lab.... The sidebar uses the URL the server returns, so nothing else needs updating.
  • Everyone is logged out once after upgrading, since the old sessionid cookie isn't read anymore. They just log in again.
  • Lab isolation is unchanged. On the new hostnames, anonymous requests still get 401 and another user still gets 403, also when a stray sessionid cookie is present.
  • Tested end to end on the Docker Compose stack in Chrome. The sensitive_data_exposure lab loads, logging in as demo goes to the profile page, and its other pages load. The XSS lab works on its new hostname, stopping one lab or all labs from PyGoat still works, and the PyGoat session stays logged in throughout.
  • The full test suite passes (58 tests), the 3 new tests fail on master, and flake8 shows no new warnings.

Lab hostnames used the lab name as is, which has underscores. The
sensitive_data_exposure lab is a Django app and rejects those hosts with
DisallowedHost, so the lab part of the hostname now uses dashes.
traefik_auth_verify accepts both forms so running labs keep working.

The lab also sets its own "sessionid" cookie, which replaced PyGoat's
shared session cookie on the lab host and made ForwardAuth return 401
after logging into the lab. PyGoat's session cookie is now named
"pygoat_sessionid".

Fixes adeyosemanputra#580

Signed-off-by: PRAteek-singHWY <prateek23022004@gmail.com>
@PRAteek-singHWY

Copy link
Copy Markdown
Author

Hi @RupakBiswas-2304 This PR fixes #580, where the Sensitive Data Exposure lab couldn't be used under Docker Compose.
The lab is a Django app, so it rejected its own hostname because of the underscores in the lab name. Lab hostnames now use dashes instead, and the auth check accepts both forms so labs that are already running keep working.
Logging into the lab also replaced PyGoat's session cookie, since both used the name sessionid, and every page after the login returned 401. PyGoat's session cookie is now called pygoat_sessionid, so the two don't clash anymore.

I tested it end to end on the Docker Compose stack, and the lab now loads and you stay logged into PyGoat after logging into it.

Happy to iterate based on your review.
Thank you.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: sensitive_data_exposure lab can't be used under Docker Compose (DisallowedHost, then 401 after logging into the lab)

1 participant