Skip to content

fix: stop anonymous session rows, ignore import/, cover risky paths with tests - #12

Merged
coko7 merged 1 commit into
mainfrom
fix/audit-findings
Nov 29, 2026
Merged

coko7 merged 1 commit into
mainfrom
fix/audit-findings

Conversation

@coko7

@coko7 coko7 commented Nov 29, 2026

Copy link
Copy Markdown
Owner

Fixes from a pre-launch audit. Internal only: no changelog entry, version stays 2.0.0.

Must fix

Unknown session cookies created database rows. with_always_save(true) saves the session on every response. When a request carries a session id the store doesn't know and the handler never reads the session, tower-sessions creates a brand-new empty row. That happened for /static/*, POSTs refused by the origin check (403) and wrong methods (405). Each row lived 30 days, and no login was needed: 5 requests with a made-up cookie gave 5 rows.

  • with_always_save removed. Ctx sets the 30-day OnInactivity expiry only when a player is logged in, so their window still slides.
  • oauth_start saves with a 10-minute expiry, so abandoned OAuth logins are cleaned up within the hour.
  • Static files no longer cost a session read and write for logged-in players.

Should fix

  • import/ is ignored in .gitignore and .dockerignore. It holds the original photos, whose EXIF time and GPS are the answers, and it sits inside a public repo.
  • New tests for risky paths with none:
    • The OAuth callback refuses a missing, wrong or reused state, and sends nothing to the provider. A local listener catches any outgoing request.
    • picture import and picture edit --time refuse to change an answer once players guessed. --force still works, and hints stay editable.
    • Every edition in EDITIONS has an edition.y<year> name. The README step for adding a year now mentions it.

Nice to have

  • The day page loads /day/N/picture?v=<file>, so re-importing a picture after unlock skips the one-day browser cache.
  • Home and profile use a new db::user_guesses query instead of loading every guess of the edition.
  • The profile reuses Provider::label instead of a second list of provider names.

Test plan

  • cargo fmt --check, cargo clippy --all-targets --locked -- -D warnings, cargo test --locked: 35 pass
  • Each new test fails when the rule it guards is broken (checked in a scratch copy): state comparison removed, state not single use, import guard off, edit guard off, 2027 edition without a name, user_id filter dropped
  • After deploy: a logged-in session stays valid across visits

Co-Authored-By: lazytrek 352825308+lazytrek@users.noreply.github.com

…ith tests

- Sessions: drop with_always_save. It saved a new empty row for every
  unknown session cookie on responses that never read the session
  (static files, 403 origin refusals, 405), each kept 30 days. Ctx now
  slides the 30-day expiry for logged-in players only, and abandoned
  OAuth logins expire after 10 minutes.
- Ignore import/ in git and Docker: it holds the original photos, whose
  EXIF time and GPS are the answers, and the v1 users export.
- Tests: the OAuth callback refuses a missing, wrong or reused state
  without contacting the provider; picture import/edit keep the answer
  once players guessed; every edition has a name in the locales.
- The day page's picture URL carries the file name, so a replaced
  picture is not served from the one-day browser cache.
- Home and profile query only the player's own guesses.
- The profile reuses Provider::label instead of a second list of names.

Co-Authored-By: lazytrek <352825308+lazytrek@users.noreply.github.com>
@coko7
coko7 merged commit be57942 into main Nov 29, 2026
2 checks passed
@coko7
coko7 deleted the fix/audit-findings branch November 29, 2026 17:58
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.

1 participant