Repository navigation
Conversation
| if cleared { | ||
| out.Count = 1 | ||
| } | ||
| case "remove": |
There was a problem hiding this comment.
Important: An administrator can delete their own account (and every project in it) from the admin page with no password or recent sign-in. /api/account/delete requires both, through Login or recentSignIn, but manage → apply "remove" (and "reset") accepts any administrator session plus confirmed: true. Anyone holding a stolen or left-open admin session can wipe any account, their own included, with no reauthentication. Fix: require reauthentication (the current password, or recentSignIn) for destructive admin actions, or at least refuse remove on the actor's own ID and send them to the self-service flow.
| if err := putPassword(ctx, tx, u.ID, hash); err != nil { | ||
| return auth.User{}, "", err | ||
| } | ||
| if err := s.markVerified(ctx, tx, u.ID); err != nil { |
There was a problem hiding this comment.
Important: Resetting the password of an unconfirmed account marks it confirmed, but the squatter's data stays. issuePassword calls markVerified and never calls clearUnverified, which ConfirmByProvider runs for exactly this case. Example: someone signs up for victim@x, adds an AI provider or a git remote token, and never confirms. The admin resets the password for the real owner, and the owner now gets a confirmed account still carrying the attacker's connections and settings. Fix: in the reset and add paths, run clearUnverified(ctx, tx, u.ID) before markVerified when the account is not yet verified.
| func (s *Service) StorageBytes(ctx context.Context, id string) (int64, error) { | ||
| defer lockRepo(id)() | ||
| var bytes int64 | ||
| err := filepath.WalkDir(s.Path(id), func(_ string, entry fs.DirEntry, err error) error { |
There was a problem hiding this comment.
Important: The account report fails as a whole whenever one owned project has no directory. filepath.WalkDir on a missing root passes the ENOENT to the callback, which returns it, so accountUsageAndStorage returns an error and the admin sees 'Could not load account usage and storage.' This happens while a purge has renamed the directory to purgePrefix+id but the row is still listed, or for a project whose directory was lost. Fix: treat os.ErrNotExist on the root as 0 bytes (if errors.Is(err, fs.ErrNotExist) && path == root { return filepath.SkipDir }, or check it before walking).
| // StorageBytes measures regular files in a project, including Git history | ||
| // and excluding generated build data. It never follows symbolic links. | ||
| func (s *Service) StorageBytes(ctx context.Context, id string) (int64, error) { | ||
| defer lockRepo(id)() |
There was a problem hiding this comment.
Nit (optional): StorageBytes holds lockRepo(id) for the whole recursive walk, .git included. The report measures every project of the account one after another, so opening an account in the admin page blocks that person's saves, checkpoints and pushes on large repositories until the walk ends. A disk-usage estimate doesn't need the repository lock. Fix: walk without lockRepo, and tolerate files vanishing mid-walk (skip fs.ErrNotExist).
| } | ||
| u := auth.User{ID: newID(), Email: email} | ||
| at := s.now().Unix() | ||
| if _, err := tx.ExecContext(ctx, `INSERT INTO users (id, email, created_at, email_verified_at, is_admin) |
There was a problem hiding this comment.
Pre-existing (not from this change, not blocking): A request already past session lookup can recreate an account an admin just deleted or renamed. The sessions middleware sets identity to the session's email, then Middleware → resolve → createTrusted inserts a fresh, confirmed account for that address. If it was the only account, n == 0 also makes the new account an administrator and adopts the ownerless projects. The new self-delete-from-admin and rename paths make this easier to hit. Fix: in password mode, resolve identities by the session's user ID rather than re-creating by email, or refuse creation when the identity came from a session.
| } | ||
| defer tx.Rollback() | ||
| var one int | ||
| err = tx.QueryRowContext(ctx, `SELECT 1 FROM users WHERE email = ?`, to).Scan(&one) |
There was a problem hiding this comment.
Nit (optional): Changing an account's email to the address it already has fails with 'An account already has this email address.' The existence check SELECT 1 FROM users WHERE email = ? matches the account being renamed. Fix: add AND id != ? (and treat a no-op rename as success), or return a clearer message.
| return out, "", err | ||
| } | ||
| switch in.Action { | ||
| case "reset": |
There was a problem hiding this comment.
Nit (optional): Nothing stops an administrator from removing the last administrator, themselves included. remove (and resetting or renaming one's own account) goes through with no check. After that, nobody can open Account administration until an operator runs refract users admin on the server. Fix: refuse remove when the target is the only remaining admin, or at least warn in the dialog.
Closes #82.
Summary
refract users report <email> [since].refract users admin <email>grant for existing installations. Renaming an account revokes its sessions and outstanding email links. Account removal checks project reservations up front and reports any partial deletion.For deployments behind a reverse proxy, use Refract's built-in sign-in or Cloudflare Access for account administration.
Verification
make test, TypeScript, formatting, lint, and Spanish strings