CY10: Capstone: a clinic app you can vouch for
Project 2: fixing the app, with proof
🎯You'll be able to
Fix the app's code flaws, login and session weaknesses and settings, each with a test that failed first.
🏠The everyday picture
An electrician who fixes faults hands over a test certificate for each circuit, so the next electrician knows exactly what was done and checked.
📘What it really is
- Code in
app/: bookings.py: placeholders insearch_patients,html.escapeinrender_note, role and ownership checks inget_booking.auth.py: scrypt with a random salt and a constant-time check, one failure message, a dummy hash for unknown users, a lock after five failures in 15 minutes, random tokens, 8-hour sessions checked on the server, and a protected cookie.web.py: the security headers on every page.config.pyandconfig/settings.json: debug only in development, secrets from the environment, refusing to start in production without a proper secret.- Housekeeping:
.envin.gitignore. - Fix notes in
docs/fix-notes.mdwith the sectionsdocs/FORMATS.mdlists: the fixes, the tests, what someone could have done with each flaw, and what wasn't verified.
📝A worked example
Input: test 6 failing in the starter, because unknown users get "No such user".
Steps:
- Read the failure: unknown users and wrong passwords must get the same message.
- Change
loginto return "Wrong user ID or password." for both, and check a dummy hash for unknown users so timing is similar. - Add the lock: count failures in the last 15 minutes before checking the password.
Expected output: test 6 passing, and a fix note naming the flaw, the change and the test.
🌍Where it's used
- Security fix pull requests with tests.
- Retests after an assessment, which check each finding again.
- Secure coding reviews that look for the same patterns.
📝Case scenario
A team fixed the injection flaw in March without a test, then removed the fix during a refactor in June. In the capstone, every fix has a test, so the same refactor would fail at once.
🖱️Try it
After finishing, run python -m pytest tests/test_fixes.py -q. Success: 10 passed, and your fix notes name a test for each fix.
⚠️Common mistakes
- Fixing the starter's example only. Sign: one query fixed. Fix: search
app/for the same pattern. - Breaking real use. Sign: D'Souza not found. Fix: test ordinary input too.
- A weak fallback secret. Sign: production starts without a key. Fix: fail closed.
🛠️For your project
Project 2 is complete when its 10 tests pass and its marking guide is ticked with evidence.
✅Quick check
Which test checks that the right password still has to wait during a lock?
Show the answer
Test 6.
What must the fix notes say for each fix?
Show the answer
The flaw, the change, the test that proves it, and what someone could have done with the flaw.
