Skip to content

fix(auth): enforce signup policy before account commit - #2716

Merged
Quick104 merged 7 commits into
mainfrom
fix/invited-signup-disabled-race
Nov 5, 2026
Merged

Quick104 merged 7 commits into
mainfrom
fix/invited-signup-disabled-race

Conversation

@Quick104

@Quick104 Quick104 commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #2714
Related issue: N/A
Validation tasks: unavailable (missing read:project; inspected #1196 C1/C2 and #1197 C1/C2 are unaffected).

An invited signup could pass its initial policy check, then create an account after an administrator disabled public signup. Recheck the policy inside the account transaction so a disabling mutation that commits first prevents account creation and invite consumption.

Approach

Use the existing settings mutation lock already held by the local-password guard. Preserve local-password enforcement, invite validation and atomic account/profile/use accounting. Add deterministic two-service PostgreSQL coverage and both native API error mappings. CI now runs the new and newly enabled tests. The local-password recheck test turns the global local-password setting off, so it runs in the serial external-auth database job; the others are database contracts.

Apple and Android already handle these errors. Jellyfin has no invite-code signup path. Admin invitations and initial setup use separate transactions. The accounts manual remains accurate.

Validation

  • Source-plus-failing-test proof on disposable PostgreSQL: disable-first fails before and passes after; signup-first, retry, rollback and exhaustion controls pass. Final focused tests pass under the race detector.
  • Live check on a disposable server, built first from main and then from this branch. An administrator turns public signup off while an invited POST /api/v2/auth/signup waits on the settings lock behind that change; a database session holds the lock briefly so the two requests run in that order. On main the signup returns 201, creates the account and spends an invite use. On this branch it returns 403 permission_denied, creates no account and leaves the invite unspent. An ordinary invited signup on this branch still returns 201.
  • All 148 database pins and the database contracts pass (277 after the local-password recheck test moved to the external-auth job, which passes with it on a fresh database). Build, formatting, vet, changed-line and router-recovery lint, web checks (8,367 tests), generated contracts, hygiene checks and Prometheus rules pass.
  • The full Go suite has baseline failures in resource capabilities, Dolby Vision playback expectations and NFO filesystem tests. All six failing test functions independently reproduce on base 365e3d436.
  • test: remove low-value and never-run tests #2817 had deleted three test files this branch relies on. local_signup_policy_db_test.go is restored unchanged: it holds the local-password recheck test that this branch runs in the external-auth job, and the helper the serialization test uses. TestInvitedAccountAtomicDB and TestInvitedAccountWrappedPostgresDB stay deleted and are off the contract list.
  • Rebased onto main at 2d5f22e7d. The only conflict was in scripts/ci/db-contracts.txt, where both sides added lines; both are kept. After the rebase, TestSignupPolicySerializationDB and TestSignupCommitPolicyErrorsDB fail on main. On this branch they pass under -race against PostgreSQL 18, together with the other signup and external sign-in database tests this branch touches. Build, vet, formatting, make lint-changed and the internal/auth, internal/apiv2 and internal/api/handlers unit tests pass. The full Go suite was not rerun after this rebase.
  • Full validation-board assessment is unavailable because the token lacks read:project. Saved public passed cases listed above trace to unchanged paths.

Evidence

Evidence: https://evidence.siloserver.org/r/silo-server/pr-2716/

Risks

One additional settings read per invited signup. No migration, new setting, default or API contract change.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • The Evidence section documents the changed behavior and verification limits.

AI Disclosure

  • Harness: Codex and Claude Code through T3 Code.
  • Tools: Codex coding tools, T3 delegated reviews, Modern Go Guidelines CLI, GitHub CLI and Silo workflow/evidence tools.
  • Models: gpt-6.1-sol at xhigh for implementation and code reviews; claude-opus-5-5 at high for plan and adversarial review.
  • Involvement: AI-generated implementation, tests and prose; no human verification claimed.
  • Adversarial review: The Claude plan review prompted fixture corrections and mandatory CI coverage. Sol code review found no defects; final sweep also found no defects. Claude reviewed the PR at 1f533168ebb4742c601adce92f509eb306600620, checking settings writers, transaction ordering, rollback, callers and error mappings; it found no defects and posted no review. A later /silo review (Claude Code, claude-opus-5-5, with a Codex gpt-6.1-sol round) found the local-password recheck test could fail unrelated contract tests that share its database, and moved it to the external-auth job in 8f8a72b74.
  • Rebase: Claude Code (claude-opus-5-5) rebased the branch, restored the deleted test file and updated the contract list.

Note

Recheck signup policy inside UserRepository.CreateInvited transaction

Fixes a race where signup could succeed after signup.enabled was disabled, because the policy was only checked before the invite transaction started.

  • CreateInvited in repository.go now reads signup.enabled within the transaction, after the local-password-login guard, and returns ErrSignupDisabled before redeeming the invite or creating the account and profile.
  • Adds database tests covering the fix: stale preflight settings via signup_policy_db_test.go, policy recheck before invite spend via local_signup_policy_db_test.go, and two-connection lock-ordering cases in signup_policy_db_test.go.
  • Registers the new tests in the CI database-test filters and database contract list, and documents the recheck behavior in auth-api.md.
  • Risk: signup requests that pass preflight but hit a disabled signup.enabled at commit now return ErrSignupDisabled; check callers of CreateInvited for handling of this error.

Macroscope summarized e7ec62e.

@silo-triage silo-triage Bot added the size/L 200–499 added + deleted lines (all files); change volume, not priority. label Oct 19, 2026
@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

Invited signup now rechecks the signup setting under the settings mutation lock before redeeming an invite. Database tests cover concurrent policy changes, invite usage, and disabled-policy responses from the v1 and v2 signup routes.

Changes: Invited signup policy

Layer / File(s) Summary
Recheck policy before invite redemption
internal/auth/repository.go, docs/auth-api.md
CreateInvited reads signup.enabled under the existing transaction lock before redeeming an invite. If the value is not "true", it returns the setting-read error or ErrSignupDisabled. The API documentation describes the policy check.
Test policy serialization and invite handling
internal/auth/signup_policy_db_test.go, internal/auth/signup_atomic_test.go, internal/auth/external_sign_in_db_test.go, internal/auth/signup_wrapped_provider_test.go, .github/workflows/trusted-linux-ci.yml, scripts/ci/db-contracts.txt
Database tests cover signup and disable ordering, invite usage, and account and profile counts. Test setup enables signup where needed, and CI entries include the relevant database tests.
Verify signup policy errors in API routes
internal/apiv2/signup_policy_db_test.go
A database-backed test checks that v1 and v2 signup routes reject requests when signup is disabled, without persisting accounts, profiles, or invite usage.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: rhainland

Merge Risk: Minimal · up to 8f8a7

Invited signup now refuses to redeem an invite once public signup has been disabled, closing the race window. The change is covered by database tests and the other reviewed risks were resolved, so it looks ready to merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: enforcing the signup policy before account creation commits.
Linked Issues check Passed Issue #2714 requires an in-flight invited signup to fail when the disabling mutation commits first, with no account, profile, or invite use persisted. CreateInvited now reads signup.enabled after …
Out of Scope Changes check Passed The changes stay within issue #2714. The repository change implements the policy recheck. The PostgreSQL tests, API mapping tests, fixture updates, CI registration, workflow update, and auth documenta…
Description check Passed The description is specific and on-topic. It names the signup policy recheck inside the invite/account transaction, the settings mutation lock, the affected files and tests, and the risk of ErrSignupD…
Full details: Linked Issues check

Explanation

Issue #2714 requires an in-flight invited signup to fail when the disabling mutation commits first, with no account, profile, or invite use persisted. CreateInvited now reads signup.enabled after acquiring the existing settings mutation lock and before redeemCode. The new TestSignupPolicySerializationDB covers both transaction orders, error behavior, rollback, and invite exhaustion. TestSignupCommitPolicyErrorsDB covers stale preflight reads for native v1 and v2 routes and verifies the disabled error mappings and zero persistence.

Full details: Out of Scope Changes check

Explanation

The changes stay within issue #2714. The repository change implements the policy recheck. The PostgreSQL tests, API mapping tests, fixture updates, CI registration, workflow update, and auth documentation support the required behavior or its verification. No unrelated product behavior, migration, setting, or API contract change is introduced.

Full details: Description check

Explanation

The description is specific and on-topic. It names the signup policy recheck inside the invite/account transaction, the settings mutation lock, the affected files and tests, and the risk of ErrSignupDisabled at commit. It matches the raw summary of changes (CreateInvited recheck, new DB tests, CI contract list, auth-api.md), so it passes the lenient relevance test.

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
ℹ️ Recent review info

⚙️ Run configuration

  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c77801e3-fbd2-49aa-b1d1-168187ec076e
📥 Commits

Reviewing files that changed from the base of the PR and between 365e3d4 and 8f8a72b.

📒 Files selected for processing: 9

  • .github/workflows/trusted-linux-ci.yml
  • docs/auth-api.md
  • internal/apiv2/signup_policy_db_test.go
  • internal/auth/external_sign_in_db_test.go
  • internal/auth/repository.go
  • internal/auth/signup_atomic_test.go
  • internal/auth/signup_policy_db_test.go
  • internal/auth/signup_wrapped_provider_test.go
  • scripts/ci/db-contracts.txt

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.

@silo-kody

silo-kody Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@silo-triage silo-triage Bot added bug Something isn't working go Pull requests that update go code impact: security Auth, privacy, or permission boundary priority: P0 Fix/merge first: data-loss, security, or widespread breakage labels Oct 19, 2026

@Quick104 Quick104 left a comment •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Review of 1f533168e. The fix is right: the in-transaction read runs after the settings advisory lock that every server_settings writer takes, so a disable that commits first refuses the signup, and one that comes later waits for the signup's commit. The new tests fail on the base CreateInvited (an account, a profile and a spent invite after the disable) and pass on this head, including under -race.

One finding, in the CI wiring. I'm fixing it in a commit on this branch, so there's no need to change it yourself.

A cross-provider round (Codex, gpt-6.1-sol) raised that the recheck assumes READ COMMITTED: under a database-wide default_transaction_isolation = 'repeatable read', the snapshot would predate the lock wait. I'm not treating that as a finding for this PR. The local-password guard in the same transaction, and the settings mutation path that reads current values after taking the same lock, already rely on PostgreSQL's default isolation, so pinning it here alone wouldn't make this path safe under a different database default.

AI disclosure: this review was run by Claude Code (claude-opus-5-5) with a Codex gpt-6.1-sol cross-provider round, on behalf of the PR author.

Comment thread scripts/ci/db-contracts.txt Resolved
@silo-kody

silo-kody Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌
⚠️ 1 Kody Rule(s) were not evaluated

These rules declare that they need repository context beyond this diff, and the review could not retrieve it, so they were not judged on this pull request:

  • Preserve optional store capabilities through production wrappers

@Quick104

Quick104 commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor Author

/silo review summary

Reviewed 1f533168e; the fix is at 8f8a72b74. Rechecking signup.enabled inside the CreateInvited transaction, after the settings advisory lock, closes the race in #2714. Every production writer of server_settings takes that lock, Service.Signup is the only caller of CreateInvited, and admin invitations, initial setup and external sign-in create accounts through other paths. The in-transaction refusal reaches v1 as 403 signup_disabled and v2 as the permission-denied problem, the same as the preflight refusal.

Verification. On a throwaway, migrated PostgreSQL database: TestSignupPolicySerializationDB and TestSignupCommitPolicyErrorsDB fail with the base CreateInvited, which still creates the account and spends the invite (v1 returns 201), and pass on this head. The focused auth and apiv2 tests pass under -race, the go-db-auth internal/auth step passes on a fresh database, make test-db-contracts passes all 277 entries, and make lint-changed reports no issues. I did not run a live HTTP race against a running server; the tests use the real repositories and HTTP handlers in-process.

Addressed

  • Medium, CI: TestSignupRechecksLocalPolicyBeforeSpendingInviteDB turns the global local-password setting off while the contract run executes other packages in parallel against the same database. Invitation and Jellyfin login contract tests could then fail with "local password sign-in is turned off on this server". Fixed in 8f8a72b74, which moves the test to the serial go-db-auth job.

Considered and not changed

  • The Codex round pointed out that the recheck assumes READ COMMITTED isolation. The local-password guard and the settings mutation path already make the same assumption, so this PR adds no new exposure, and pinning the isolation level for this one transaction would not cover them.
  • The signup.enabled == "true" rule is now checked in three places. They agree for every value the admin settings path can store.

Remaining issues: none.

Validated features: the board check could not run because the token lacks read:project. A text scan of Validation tasks found #1196 C1/C2 and #1197 C1/C2. C1 in each shares no code with this change. For C2, an invited signup with signup on makes the same writes as before. Validation tasks: stays as the PR body states it.

User manual: unaffected. The fix makes signup follow the admin setting; the manual does not describe this race.

Apple and Android: no follow-up needed. Both apps already handle signup_disabled, and jellycompat has no invite-code signup path. #2715 also adds entries to scripts/ci/db-contracts.txt; whichever merges second may need a trivial rebase.

CI on 8f8a72b74: everything passes except ci / Go test, which fails in TestAdminDefaultChangeReachesEveryViewer (internal/api/handlers). That test fails on every run on current main. The cause is the interaction between #2365, which added it, and #2718 (4859f6fb0); it passes on #2718's parent. It is unrelated to this PR and doesn't count against the scores. A fix PR for main is coming separately.

Fit: 9/10 · Readiness: 8/10 — conditional (assuming CI is green)

  • Fit: it closes an admin-policy bypass at the boundary that already serializes signup with settings changes. It adds no setting or API surface, and costs one indexed read per invited signup.
  • Readiness: the fix and its tests hold up, and the CI wiring problem is fixed. It holds at 8 because the validation-board check could not run and no live-server race was performed.

AI disclosure: Claude Code (claude-opus-5-5) ran this review with read-only subagents and a Codex gpt-6.1-sol cross-provider round, on behalf of the PR author. It wrote commit 8f8a72b74.

@macroscopeapp

macroscopeapp Bot commented Oct 20, 2026

Copy link
Copy Markdown

The four cases in #1196 (C1–C2) and #1197 (C1–C2) are unaffected. Their access-group checks and group-assigned invitations use the admin invitation flow (invitations.Service.Accept → AccountProvisioner.CreateAccountInTransaction), not UserRepository.CreateInvited, which this diff changes for public invite-code signup.

The current Validation tasks: line says “unavailable” and names only unaffected cases. Please replace it with exactly:

Validation tasks: none

Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed.

Posted via Macroscope — v1 validation impact

@silo-kody

silo-kody Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

Comment thread internal/auth/signup_policy_db_test.go Resolved
@silo-kody

silo-kody Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

Quick104 and others added 7 commits November 4, 2026 22:25
Serialize the signup decision with settings mutations before redeeming an invite. Keep account/profile writes and invite accounting atomic, and run the policy ordering and API mapping database contracts in CI.

Co-authored-by: Codex <[email protected]>
TestSignupRechecksLocalPolicyBeforeSpendingInviteDB turns the global
auth.local_password_login row off for part of its run. In the database
contract run every listed package shares one database and runs in
parallel, so invitation and Jellyfin login contract tests could fail
with "local password sign-in is turned off" while it ran. Run it in the
go-db-auth job, beside TestSignupRefusedWhileLocalLoginIsOffDB, where
these tests run one at a time in a fresh database.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
#2817 deleted local_signup_policy_db_test.go because no CI job ran it. This
branch now runs TestSignupRechecksLocalPolicyBeforeSpendingInviteDB in the
serial auth DB job, and signup_policy_db_test.go uses its paused repository
helper, so restore the file unchanged.

#2817 also deleted TestInvitedAccountAtomicDB and
TestInvitedAccountWrappedPostgresDB; drop them from the DB contract list,
which fails on listed tests that do not exist.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Quick104
Quick104 force-pushed the fix/invited-signup-disabled-race branch from 8cd89b8 to e7ec62e Compare November 5, 2026 03:47
@silo-kody

silo-kody Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌
⚠️ 4 Kody Rule(s) were not evaluated

These rules declare that they need repository context beyond this diff, and the review could not retrieve it, so they were not judged on this pull request:

  • Preserve optional store capabilities through production wrappers
  • Detach mandatory cleanup from request cancellation and bound its lifetime
  • Preserve durable media identity and share identity-evidence precedence
  • Bound decoder throughput trades and share direct-play eligibility

@Quick104
Quick104 merged commit f3b7596 into main Nov 5, 2026
26 checks passed
@Quick104
Quick104 deleted the fix/invited-signup-disabled-race branch November 5, 2026 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code impact: security Auth, privacy, or permission boundary priority: P0 Fix/merge first: data-loss, security, or widespread breakage size/L 200–499 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] In-flight signup can finish after public signup is disabled

1 participant