Skip to content

Fix five high-severity security findings; add crop-before-upload for lotto photos - #40

Merged
zzuse merged 3 commits into
mainfrom
claude/lotto-number-recognition-training-q8yi3x
Nov 13, 2026
Merged

zzuse merged 3 commits into
mainfrom
claude/lotto-number-recognition-training-q8yi3x

Conversation

@zzuse

@zzuse zzuse commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

This PR carries two separate changes on one branch: the security fixes (commits 9d2f8c5, 489d23b) and a lotto upload feature (commit a067199).

Part 1: security fixes

Fixes the five high-severity findings from the security audit. Each was reproduced on a local instance (PostgreSQL) before the fix and re-tested after.

# Finding Fix
1 Anyone could register (1-character password accepted), then change the family's filter Registration is closed by default. ALLOW_REGISTRATION=True opens it. Passwords need 8+ characters.
2 Todo routes trusted the username or id in the request update_todo, delete_todo, mark_done, mark_status and exec_rules act only for the owner or an admin
3 Admin actions were GET links, so an <img> in a blog post could switch off filtering in the admin's browser Those routes are POST-only, and cross-site writes are refused
4 An uploaded HTML or SVG note attachment ran script in other users' browsers Only image (not SVG), audio and video render inline. Everything else downloads, with nosniff.
5 /auth/callback?code=<script>… was reflected as HTML Response is text/plain

Behaviour changes to know before merging

  • Registration is closed after deploy. The register form, POST /auth/register and first-time Google/GitHub sign-in are refused; existing accounts log in as before. To add a family member, set ALLOW_REGISTRATION=True in .env, restart, let them sign up, then remove it. Documented in the README.
  • Accounts created while registration was open are not removed. Review the users table for any you don't recognise.
  • MGMT buttons now submit by POST: Enable/Disable All Rules, Stop/Allow All Traffic, Push Block List, Import Block List and the block-list Delete button. Bookmarks or scripts that call these URLs with GET will get 405.
  • Non-media note attachments (PDF, text, HTML and so on) now download instead of opening in the browser tab.

Details

  • Cross-site write check (reject_cross_site_writes in app.py): a POST/PUT/DELETE whose Origin (or Referer) does not name the request's own host is refused with 403, including hostless values such as Origin: null. Requests with neither header (the mobile app, scripts) pass through, so the notesync API is unaffected. This complements SameSite=Lax; it is not a per-form CSRF token.
  • Registration input: missing fields, a duplicate email and a non-JSON body now return 400 instead of 500. The register form shows the error instead of crashing on a wrong template path.
  • nosniff: every response now carries X-Content-Type-Options: nosniff.
  • Test setup: the test fixtures open registration by default, and the todo tests' shared login helper runs as an admin unless a test sets its own user. One existing test (test_mark_todo_status_success) had a user marking another user's task, which encoded the bug, so it now marks the user's own.

Not in this PR

The medium and low findings from the audit:

  • logout not revoking tokens
  • OAuth linking accounts by unverified email
  • non-unique usernames
  • Postgres published on all interfaces
  • the container running as root with ~/.ssh mounted
  • login brute-force limits
  • unauthenticated POST /logs
  • outdated dependencies
  • missing HSTS/CSP headers and the cookie Secure flag

Part 2: crop before upload (lotto)

A photo of one tray usually catches the edge of the neighbouring trays, whose tickets would then be counted twice. The upload form on /lotto now shows a preview of each chosen photo with a crop frame:

  • drag on the photo to draw the frame, drag inside it to move, drag a corner to resize, Use whole photo to reset
  • on upload, a framed photo is replaced by a JPEG of just that region, cut from the full-resolution image (capped at 16 MP for the iOS canvas limit)
  • photos without a frame are uploaded untouched
  • it runs in the browser after the existing HEIC conversion, so the server is unchanged

Testing

  • pytest -q: 460 passed. ruff check . clean on 0.17.4.
  • Security: new tests/test_security_fixes.py covers each fix, including that legitimate use still works. Re-ran the audit's attack script against this branch on PostgreSQL:
    • registration returns 403
    • cross-user todo edit, delete and exec_rules return 403
    • the uploaded HTML file is served as an application/octet-stream attachment
    • /auth/callback is text/plain
  • Crop, in a browser (Playwright) with a real 1512×2016 display photo:
    • a tap leaves the photo whole
    • drag, corner-resize and move produced a 1331×544 frame, and the stored photo is exactly 1331×544
    • a second photo, framed and then reset, arrived byte-for-byte identical to the original
    • at iPhone 13 size, touch dragging works and the page has no sideways scroll
  • Not tested in a browser: the MGMT page buttons, since that page needs the full Postgres schema; their routes are covered by the tests. The crop was not tested on a real iPhone, only in emulation.

🤖 Generated with Claude Code

https://claude.ai/code/session_012k19dCKBK4J2UdDMJd5gLv

1. Registration is closed unless ALLOW_REGISTRATION=True (register form,
   POST /auth/register and first-time Google/GitHub sign-in). Passwords need
   8+ characters; missing fields, duplicate emails and non-JSON bodies get a
   400 instead of a 500, and the register form no longer crashes on errors.
2. Todo routes check ownership: update_todo, delete_todo, mark_done,
   mark_status and exec_rules act only for the owner or an admin. The
   username or id in the request is no longer trusted.
3. Admin actions that change filtering are POST-only (rules_toggle
   enable/disable, stop/enable traffic, delete_block, auto_push,
   auto_import), so an <img> in a blog post or a link can't fire them.
   State-changing requests whose Origin/Referer names another host are
   refused.
4. Note media is rendered inline only for image (not SVG), audio and video
   types; everything else is sent as a download, with nosniff. An uploaded
   HTML file can no longer run script with the viewer's login.
5. /auth/callback returns text/plain, so its code parameter can't inject
   script.

All responses now carry X-Content-Type-Options: nosniff.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012k19dCKBK4J2UdDMJd5gLv
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T19:40:52.033335Z 9d2f8c5 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9d2f8c514f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/safe_family/app.py Resolved
Origin: null (sandboxed frames and other opaque origins) parsed to an empty
host and was let through, also skipping the Referer fallback. Any Origin or
Referer that doesn't name our own host is now refused; requests with neither
header still pass.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012k19dCKBK4J2UdDMJd5gLv
A tray photo usually includes the edge of neighbouring trays, whose tickets
would be counted twice. After choosing photos, each one now shows a preview
with a crop frame: drag to draw it, drag inside to move, drag a corner to
resize, "Use whole photo" to reset. On upload, framed photos are replaced by
a JPEG of just that region cut from the full-resolution image (capped at
16 MP for the iOS canvas limit); unframed photos are uploaded untouched.

Runs entirely in the browser after the existing HEIC conversion, so the
server is unchanged.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012k19dCKBK4J2UdDMJd5gLv
@zzuse zzuse changed the title Fix five high-severity findings from the security audit Fix five high-severity security findings; add crop-before-upload for lotto photos Nov 13, 2026
@zzuse
zzuse merged commit e67d16c into main Nov 13, 2026
2 checks passed
@zzuse
zzuse deleted the claude/lotto-number-recognition-training-q8yi3x branch November 13, 2026 16:55
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.

2 participants