patch wednesday
last week you broke things. this week you fix them. we hand you a small members-portal web app with five deliberate security bugs. find each one, run the exploit, read the real-world CVE, and ship the proper fix.
the app is a tiny flask members portal. every bug lives in its own file under
challenges/, and every bug ships with two kinds of test: an exploit test that fails
while the bug is there, and normal-use tests that check the feature still works. so you can't
win by deleting the feature, and you can't win with a blocklist of "bad characters" — the exploit
tests try several shapes of the same trick. a fix counts when the tests go green.
- on the template repo, click use this template → create a new repository, keep it public, and clone your copy.
- open the actions tab: your first run is a red cross with five failing tests, one per bug.
- pick a bug below, open its file in
challenges/, and fix the one function it points at. git add . && git commit -m "fix" && git push— github re-runs the tests. green means patched.
each lab below runs the real exploit in your browser against a faithful copy of the broken logic — nothing is sent anywhere, and no real system is touched. flip the vulnerable / patched switch to watch the same payload stop working once the bug is fixed.
the login query pastes your username and password straight into a SQL string, so a crafted username can change what the query means and log you in with no valid password. the fix is to stop mixing input into the query text at all — use placeholders.
// challenges/login.py · fix check_login()
a pre-auth SQL injection in Drupal 7 core's database layer. sites were mass-compromised within hours of disclosure — Drupal later said any site not patched within 7 hours should be assumed hacked.
the fix: Drupal 7.32 changed the database API to expand array arguments as proper parameterized placeholders instead of building the query by hand — exactly what you'll do here. OWASP SQLi prevention →
logged-in members read notes at /notes/<id>. the handler looks the note up by
id and hands it back — without checking who it belongs to. change the number in the URL and you
read anyone's notes. the fix is a missing ownership check.
// challenges/notes.py · fix handle()
an authenticated user could download other members' private files just by changing the file
id in the request — the same missing-ownership-check you're fixing, one ?id= apart.
the fix: check that the logged-in user actually owns the object before returning it; treat someone else's id exactly like one that doesn't exist. PortSwigger: IDOR →
context: OWASP ranks Broken Access Control the #1 web risk.
the download handler joins the name you give it onto the public files folder and
opens whatever comes out. put ../ segments in the name and you walk out of the folder
and read files you shouldn't. blocking the literal "../" is not enough — resolve
the real path and check it stays inside the folder.
// challenges/files.py · fix download()
a path-traversal flaw in the Apache web server: ..%2e-style sequences escaped the
document root to read (and, with CGI, run) arbitrary files. actively exploited in the wild within days.
the fix: Apache 2.4.50/2.4.51 properly normalised and confined the
resolved path to the configured root. in your version: resolve the real path and require it to live
inside the public folder (flask's send_from_directory does this).
OWASP: Path Traversal →
links bounce you onward through /go?next=..., and the handler redirects to whatever
next says — including a full URL on another site. an attacker sends a link to
our trusted domain that quietly forwards to a lookalike phishing page. allow only redirects
that stay on this site.
// challenges/redirect_after_login.py · fix safe_target()
a "URL redirection to untrusted site" bug: the app would forward users to an attacker-supplied
address, handing phishers a link that starts on a trusted domain. the classic shape is a login
?next= parameter — exactly this one.
the fix: accept only a single local path (empty host, starts with one
/ but not //); anything pointing at another host falls back to /.
OWASP: unvalidated redirects →
the "reachability check" pastes the host you type into a shell command string. shell punctuation
(;, &&, |) lets you tack on a second command of your
choice. the fix is to stop using a shell at all — pass the program and its arguments as a list,
so the input can only ever be one argument.
// challenges/tools.py · fix run_check()
a flaw in Bash let attacker-controlled data smuggle trailing commands into a shell — a web request could run arbitrary commands on the server. one of the most widely exploited bugs of the decade.
the fix: never hand untrusted input to a shell. pass the program and its args
as a list with no shell=True, so the whole input is a single argument and nothing
extra can run. OWASP: command injection defense →