FACTORY_OUTCOME: COMPLETED The auth and home-screen app (PWA) code works and is now tested. `python3 -m unittest tests.test_mobile_auth -v` passes: 34 ran, 1 skipped. The skip is expected: the system `python3` has no FastAPI, so a second test re-runs the real-app tests with the console's venv Python instead, and those pass. The full suite passes too (239 tests, 3 skipped). This includes the `HttpSmokeTests` test that was failing at the end of the last task. Apache Basic Auth is unchanged. The app stays in its current mode, where Apache is the only login and app sessions are off. The scheduler is off: there is no scheduler table in the live database and no timer. Nothing was sent to anyone. **What the tests check** (`tests/test_mobile_auth.py`; no network, no real secrets, only temporary databases): - **Session cookie:** it is HttpOnly, Secure and SameSite=Lax, limited to this host, and lasts 30 days. The server stores only a hash of each token, in an auth database readable only by the owner. Sessions expire after 30 days. - **Logout:** signs out this device and clears the cookie. "Sign out everywhere" signs out all devices, and so does a password change or deleting the user. - **Login:** passwords are stored hashed, and error messages don't reveal which usernames exist. A user is locked out after 5 failed attempts. The return link after login can't send users to another site. - **Security token (CSRF):** forms without the right token are rejected, as are requests from other sites, non-form bodies and oversized forms, and nothing is saved. The token from before login stops working after login. - **Caching:** pages are never cached. CSS, JS and icons are cached for a year under a versioned address, and anything else must be re-checked. Only known files are served. - **Home-screen app:** the manifest and icons are correct. - **Fresh startup:** there is no offline cache (service worker) or browser storage. When the app comes back to the screen, it checks the server's version and reloads, but it won't reload over unsaved input. - **Full login flow:** login, staying signed in and logout were tested through the real app, plus a check that in the current mode no auth database is created. **Fixes I made** - `app/pwa.py`: the version tag now also covers the icon code. Before, an icon change would have kept the same long-cached address, so phones would have kept showing the old icon. - `app/main.py`: opening `/login` in the current mode no longer creates an empty `data/auth.db`. - `tests/test_review_queue.py`: `HttpSmokeTests` now sends the security token, which was the cause of its failure. This is a small change to an older test outside the files you named. I made it because it's the same CSRF behaviour this task covers. - Copies of the files from before the change are in `/tmp/auth-backup/`. **Docs:** `docs/mobile-and-auth.md` describes the current setup, what is tested, the changes above, how to roll back, and the migration steps. I ran the user-management commands from the steps against a throwaway database. **Decisions for you** - **Restart:** I didn't restart the running console, so the two fixes take effect at the next `sudo systemctl restart lead-generation`. The restart is safe because the login setup doesn't change. - **Moving to app logins needs your written approval:** - Steps 2–4 in the doc are each marked as needing it: turning on app logins while Apache's login stays in front, removing Apache's login (a separate decision), and adding HSTS. - Step 1 can be done early: it creates the user and has no visible effect. - Once Apache's login is removed, anyone who knows the username can lock the owner out for 15 minutes. The doc suggests adding rate limiting before that step.