Skip to content

Open sign-up with admin approval; fix OAuth linking, duplicate usernames, root container - #41

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

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

Conversation

@zzuse

@zzuse zzuse commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes four medium findings from the security audit.

1. Open registration, safely

Open sign-up was never the problem; the problem was that any new account could touch the family's shared filter.

  • Sign-up is open again by default (ALLOW_REGISTRATION=False still closes it).
  • New accounts start unapproved (users.is_approved). They get their own todo list, notes and draft blog posts, and nothing else.
  • Only approved accounts and the admin can:
    • use the rule buttons that change the network filter (/rules_toggle/disable_ai, /exec_rules/...)
    • trigger email/Discord notifications
    • publish public blog posts (theirs are saved as drafts)
  • New Accounts card on MGMT: waiting accounts first, each with an Approve / Remove approval button (POST /users/<id>/approve, admin only).
  • Unapproved users see a "waiting for the admin's approval" notice after login.

2. Google/GitHub sign-in no longer links by unverified email

  • Only a provider-verified email is used. GitHub no longer falls back to an unverified address or the public profile email; Google must report email_verified.
  • An existing account is matched by email only if it was itself created by a provider (numeric provider id). An account made with the register form (UUID id) is reachable only with its password. So pre-registering with someone's email and your own password no longer captures their later Google login.
  • Side effect: someone who registered with the form and later tries Google with the same email is refused, with a message to use their password.

3. Unique usernames

  • A Google/GitHub display name that is already taken gets a suffix (Alex-2), because todo lists are keyed by username.
  • migrate.py adds a unique index on users.username. If duplicates already exist, it skips the index and prints a notice instead of failing.
  • User.id default is now a UUID string, not a UUID object (same stored value on Postgres; fixes SQLite in tests).

4. Container no longer runs as root

  • Dockerfile: the app runs as unprivileged user app (APP_UID/APP_GID build args, default 1000). Playwright's Firefox is installed to a shared path so that user can launch it; git safe.directory is set for the mounted rules repo.
  • docker-compose.yml: the SSH mount is ${SSH_KEY_DIR:-~/.ssh} → /home/app/.ssh:ro. The README explains using a folder with only a deploy key for the rules repository.

Deploy steps

  1. Run the migration right after deploying: docker exec safefamily_app python scripts/migrate.py. The app reads users.is_approved, so pages error until it has run.
  2. Existing accounts all become approved. Review the new Accounts card and remove approval from any you don't recognise.
  3. If id -u on the server isn't 1000, set APP_UID/APP_GID in .env before rebuilding. If ./logs was created by the old root container: sudo chown -R $(id -u):$(id -g) logs.

Testing

  • pytest -q: 485 passed, coverage 89%. ruff check . clean on 0.17.4.
  • New tests/test_accounts.py (25 tests):
    • an unapproved account can't change the filter, run rules, notify or publish; an approved one can
    • only the admin can approve
    • the GitHub unverified-email takeover and the pre-registered-email capture are both refused
    • username suffixing
  • Migration run on PostgreSQL 16:
    • existing rows stay approved and new rows start unapproved
    • re-running is safe
    • the unique index is created, and it is skipped with a notice when duplicates exist
  • Not tested: the Docker image was not built (no Docker in the dev environment). After deploying, check "Push Block List to GitHub" on MGMT and the next gas-price report, which depend on the SSH mount and the Firefox path. The MGMT Accounts card was rendered from its template in a test, not viewed live.

Generated by Claude Code

…container

Registration: open again by default. A new account is unapproved
(users.is_approved) and only gets its own todo list, notes and draft posts.
Only approved accounts and the admin can use the rule buttons that change
the network filter (disable_ai, exec_rules), trigger email/Discord
notifications, or publish public blog posts. The admin approves accounts in
a new Accounts card on MGMT. ALLOW_REGISTRATION=False still closes sign-up.

OAuth: Google/GitHub sign-in only uses a provider-verified email (GitHub no
longer falls back to an unverified address; Google must report
email_verified). An existing account is matched by email only if it was
itself created by a provider, so a later Google login can't land in an
account someone pre-registered with the victim's address and their own
password.

Usernames: Google/GitHub display names that are taken get a suffix
(Alex-2), because todo lists are keyed by username. migrate.py adds a
unique index on users.username, skipped with a notice while duplicates
exist.

Container: the app runs as an unprivileged user (APP_UID/APP_GID, default
1000) instead of root, and the SSH mount is SSH_KEY_DIR (default ~/.ssh) at
/home/app/.ssh so a dedicated deploy key can be used.

migrate.py must be run after deploying: the app now reads users.is_approved.

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 14, 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-14T14:15:39.651425Z 5d2e001 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: 5d2e001f62

ℹ️ 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 scripts/migrate.py Resolved
Comment thread src/safe_family/core/models.py Resolved
The README quickstart loaded scripts/schema.sql and stopped, but that
snapshot has no users.is_approved (nor lotto_photos), so login would fail
on a database built that way. The quickstart now runs migrate.py and says
why it is required.

Also write the PL/pgSQL block's final END with a semicolon. PostgreSQL 16
accepted it without one, but the terminated form is the documented one.

Verified on PostgreSQL 16: schema.sql + migrate.py (run twice), then
register and login succeed and the new account is unapproved.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012k19dCKBK4J2UdDMJd5gLv
@zzuse
zzuse merged commit c599ea7 into main Nov 16, 2026
2 checks passed
@zzuse
zzuse deleted the claude/lotto-number-recognition-training-q8yi3x branch November 16, 2026 22:17
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