Skip to content

fix(auth): stop another account denying a device sign-in it did not approve - #2938

Merged
Quick104 merged 4 commits into
Silo-Server:mainfrom
Rhainland:fix/2897-device-deny-approved-by-other
Oct 23, 2026
Merged

Quick104 merged 4 commits into
Silo-Server:mainfrom
Rhainland:fix/2897-device-deny-approved-by-other

Conversation

@Rhainland

@Rhainland Rhainland commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #2897
Related issue: N/A
Validation tasks: none affected

Once one account approved a TV's device sign-in, a second account holding the
same code could still deny it before the TV collected its tokens. The deny
replaced the approval, so the TV saw denied and never signed in. Approve
already refuses a second account with 409 approval_conflict; deny did not.
Deny now refuses it the same way, so the first approval holds.

The approving account can still deny its own approval to withdraw it before the
device collects it. Anyone can still deny a request that is pending, or one
whose approving account or profile was deleted, since the device can no longer
collect it.

Approach

DeviceLoginService.Deny now takes the deciding account. If the request is
approved by a different account it returns ErrDeviceLoginConflict, which the
shared decision handler already maps to 409 approval_conflict. The UPDATE
carries the same condition, so a deny that races a second account's approval
also gets 409 and does not overwrite it.

The handler is shared by /api/v1 and /api/v2 deny, so both change. 409 is
already a documented deny response on both, and the change fails closed, so it
fits the v1 rule that only critical fixes land there. The v2 OpenAPI document
and fixtures do not change. Jellyfin Quick Connect has no deny route.

docs/architecture/device-login.md ("Who decides") and docs/auth-api.md
describe the rule. The deny.any_account and deny.approved scenario text in
the v1 auth catalog and the deny retry note in contracts/api/v2/migration.json
said any deny overrides an approval; they now state the new rule. Recorded
expectations are unchanged.

Validation

  • New Postgres test for Deny: a second account's deny is refused and the TV
    still collects the approval. The approving account's own deny withdraws it.
    An approval whose approving account or profile was deleted can still be
    denied by any account. It runs in CI's "Test device sign-in against Postgres"
    step. It failed before the fix.
  • go test for internal/auth (with Postgres, including -race on the device
    sign-in tests), internal/api/handlers and internal/apiv2: pass.
  • Device deny scenario cases in internal/scenariocatalog/executor (frozen v1
    deny.approved, deny.any_account and the refusals): pass. Other cases in
    TestRequiredDeviceDecisionsAcceptance, all poll and session checks, fail
    the same way on main, so this change did not cause them.
  • make lint-changed, gofmt, goimports, make verify-local-paths: clean.

Evidence

The visible change is in the device sign-in flow: once account A approves a TV's sign-in code, account B's deny no longer cancels it. These responses come from the real /api/v2 handlers and device login service, run in-process against a local Postgres with two real accounts. Before is main at be6527e50; after is this branch at 53e9f602a. Codes and tokens are redacted.

A starts the device request with POST /api/v2/auth/device/start, then approves it with POST /api/v2/auth/device/approve, which answers 200 {"status":"approved"} on both. Then B denies the same code:

before
POST /api/v2/auth/device/deny   (account B)  -> 200 {"status":"denied"}
GET  /api/v2/auth/device?code=<user-code>    -> 200 {"status":"denied", ...}
POST /api/v2/auth/device/poll                -> 200 {"status":"denied","poll_after":3, ...}

after
POST /api/v2/auth/device/deny   (account B)  -> 409 {"type":".../problems/conflict","title":"Conflict","status":409,"detail":"Device login request was approved by another identity"}
GET  /api/v2/auth/device?code=<user-code>    -> 200 {"status":"approved", ...}
POST /api/v2/auth/device/poll                -> 200 {"status":"approved","tokens":{"access_token":"<redacted>", ..., "user":{"id":"<account-A-id>", ...}}, ...}

Risks

A client that let a different account deny an approved request now gets 409.
The web activate page already treats 409 on deny as "the request moved on" and
reloads it.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code (via T3 Code)
  • Tool(s): Claude Code; Codex CLI (code review)
  • Model(s): claude-opus-5-5; gpt-6.1-sol (code review)
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: independent reviews of the branch diff by claude-opus-5-5 and gpt-6.1-sol, reconciled; no correctness or spec findings. One low finding, fixed: the frozen v1 scenario catalog still said deny checks no ownership.

Note

Fix cross-account device login denial with ownership check in DeviceLoginService.Deny

  • DeviceLoginService.Deny now takes the denier's user ID. It rejects an approved request when a different linked account approved it, and returns ErrDeviceLoginConflict (device_login.go).
  • The approving account can still withdraw its own uncollected approval, pending requests remain denyable by any account, and approvals with a deleted approver stay denyable by any account.
  • auth.AuthHandler.DenyDeviceLogin passes the authenticated user ID through to the service (auth_device.go).
  • Updates docs, generated scenario contracts, and adds a DB test covering cross-account conflicts, same-account withdrawal, and deleted-approver denial (device_login_db_test.go).
  • Behavioral Change: Deny no longer lets any account deny a live approval owned by another account; the SQL update only accepts approved requests whose approver is null or matches the denier.

Macroscope summarized 094f8d8.

@silo-triage silo-triage Bot added the size/M 50–199 added + deleted lines (all files); change volume, not priority. label Oct 22, 2026
@silo-kody

silo-kody Bot commented Oct 22, 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 ❌

@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 07df58d6-84a9-4c02-a168-5a58d6d65745
📥 Commits

Reviewing files that changed from the base of the PR and between 19f59ef and 094f8d8.

📒 Files selected for processing: 8
  • contracts/api/v2/migration.json
  • contracts/api/v2/scenarios/api/api-v1-auth.json
  • contracts/api/v2/scenarios/tools/gen_auth.py
  • docs/architecture/device-login.md
  • docs/auth-api.md
  • internal/api/handlers/auth_device.go
  • internal/auth/device_login.go
  • internal/auth/device_login_db_test.go

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

📝 Walkthrough

Device-login denial now returns a conflict when another account approved the request. The approving account can withdraw its approval, and any account can deny a pending request or an approval whose approver was deleted. API scenarios and documentation describe these rules.

Changes: Device-login denial ownership

Layer / File(s) Summary
Denial rules and API expectations
contracts/api/v2/migration.json, contracts/api/v2/scenarios/api/api-v1-auth.json, contracts/api/v2/scenarios/tools/gen_auth.py, docs/architecture/device-login.md, docs/auth-api.md
The API scenarios and documentation describe conflicts for denial of another account’s approval. They also describe withdrawal by the approving account and denial when the approver is deleted.
Ownership enforcement and database tests
internal/auth/device_login.go, internal/api/handlers/auth_device.go, internal/auth/device_login_db_test.go
Deny receives the denier’s user ID and rejects a different account’s approval. The database update allows pending requests, approvals by the denier, and approvals with a null approver ID. Database tests cover these cases.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Possibly related PRs

Suggested labels: api-v2

Suggested reviewers: quick104

Merge Risk: ⚪ Minimal · up to 094f8

Another account cannot withdraw an approval, including when approval races with denial. The reviewed change is ready to merge after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 4 files. (4 skipped: 4… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title states the main change: denial by another account is refused for a device sign-in that account did not approve. It matches the summarized changes to DeviceLoginService.Deny, the handler pass…
Description check Passed The description explains the problem (a second account could deny an approved device sign-in before the TV collected tokens), the approach (Deny takes the deciding account and returns ErrDeviceLoginCo…
Linked Issues check Passed Issue #2897 requires that a different account cannot deny an approved device sign-in, or that the behavior is documented. The PR implements the stricter behavior. DeviceLoginService.Deny checks the …
Out of Scope Changes check Passed The changes stay within issue #2897. The service and handler changes implement denial ownership. The database test verifies the required behavior. The contract, scenario, and documentation updates des…
Full details: Title check

Explanation

The title states the main change: denial by another account is refused for a device sign-in that account did not approve. It matches the summarized changes to DeviceLoginService.Deny, the handler pass-through, and the docs and tests. It names the affected area (auth) and the behavior, so a teammate scanning history can tell what changed.

Full details: Description check

Explanation

The description explains the problem (a second account could deny an approved device sign-in before the TV collected tokens), the approach (Deny takes the deciding account and returns ErrDeviceLoginConflict, mapped to 409 approval_conflict, with a matching UPDATE condition), the docs and scenario text changes, the validation steps, and a risk note. It is directly related to the changeset.

Full details: Linked Issues check

Explanation

Issue #2897 requires that a different account cannot deny an approved device sign-in, or that the behavior is documented. The PR implements the stricter behavior. DeviceLoginService.Deny checks the approving account and returns ErrDeviceLoginConflict for a different account. Its conditional UPDATE also prevents a racing deny from overwriting another account's approval. The shared handler passes the authenticated user ID. The database test covers cross-account denial, same-account withdrawal, and denial after approver deletion. The API and architecture documentation and v1 scenario text describe the new rule.

Full details: Out of Scope Changes check

Explanation

The changes stay within issue #2897. The service and handler changes implement denial ownership. The database test verifies the required behavior. The contract, scenario, and documentation updates describe the changed API behavior and retry rule. No unrelated product behavior or unrelated files appear in the reviewed diff.

Full details: Docstring Coverage

Explanation

Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 4 files. (4 skipped: 4 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@macroscopeapp

macroscopeapp Bot commented Oct 22, 2026

Copy link
Copy Markdown

The Evidence section says Evidence: none, no user-visible change, but the changed deny behavior is visible in the device-activation flow: a second account’s deny now conflicts, and the page reloads to show that the first account’s approval still holds instead of declining the sign-in.

  • Device-activation flow — add a short recording showing one account approving and another account attempting to deny, with the approval remaining in effect; identify the surface and build or commit, and include phone-width if the change is visible there.

Suggested fix: No diff — add the recording under Evidence or link to it from the Evidence section.

Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness.

Posted via Macroscope — Visible change evidence

@silo-triage silo-triage Bot added bug Something isn't working evidence-required Needs before-and-after evidence before the Evidence check passes go Pull requests that update go code impact: security Auth, privacy, or permission boundary priority: P1 Core-path bug; painful workaround — next after P0 labels Oct 22, 2026
@silo-kody

silo-kody Bot commented Oct 22, 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 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review of 2b928db. The fix is right: deny now follows the same first-approval-holds rule as approve, the conditional UPDATE closes the race with a second account's approval, and the new DB test fails on main when its Deny calls are adapted to the old signature. I found one low-severity regression and some stale contract text. I'm fixing all of them in a commit on this branch, so there's no need to change anything yourself.

One item outside the diff: contracts/api/v2/migration.json (denyDeviceLogin retry_safety_note) still says the denial is UPDATE ... WHERE status IN (pending, approved), and the deny.approved scenario description in gen_auth.py and api-v1-auth.json still says a deny "overrides the approval" without saying it has to come from the approving account. Both get updated in the same commit.

Comment thread internal/auth/device_login.go Resolved
Comment thread docs/architecture/device-login.md Resolved
Comment thread docs/auth-api.md Resolved
Rhainland and others added 4 commits October 23, 2026 14:45
…pprove

Deny cleared any approved request, so a second account holding the code
could cancel a TV sign-in someone else had approved before the TV
collected it. Deny now refuses such a request with 409 approval_conflict,
as approve already does; the approving account can still withdraw its
own approval.
Deleting the approving profile or account sets approved_by_user_id NULL
and leaves the request approved but uncollectable. The new deny check
refused that row for everyone; treat a NULL approver as deniable again.

Also name the v2 problem code in the device-login architecture doc,
state approve-handoff's profile-level rule in auth-api.md, and update
the deny retry note and deny.approved scenario text.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Quick104
Quick104 force-pushed the fix/2897-device-deny-approved-by-other branch from 2b928db to 094f8d8 Compare October 23, 2026 18:48
@silo-kody

silo-kody Bot commented Oct 23, 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

Copy link
Copy Markdown
Contributor

Review summary (reviewed 2b928db, fixes pushed as 094f8d8)

The fix holds. Deny now refuses a request another account approved, as approve already did, and the conditional UPDATE keeps that rule when a deny races a second account's approval. I checked both API versions, which share the handler, and the Jellyfin Quick Connect side: jellycompat has no deny route, six-digit codes still reach deny only through v2 with the account's own session, and their lookups are still rate-limited. The web activate page already reloads on 409 from deny. The Apple and Android apps treat a non-200 deny as a failure, so neither needs a change.

Addressed in 094f8d8 (the branch was rebased onto current main, so its history was rewritten):

  • An approval whose approving profile or account was deleted (the foreign keys set approved_by_user_id NULL) could no longer be denied by anyone. It can be again, and the new DB test covers that case.
  • docs/architecture/device-login.md now names the v2 problem code (conflict) next to v1's approval_conflict, and says any profile of the approving account can withdraw.
  • docs/auth-api.md now states approve-handoff's profile-level conflict rule separately from deny's account-level one.
  • The denyDeviceLogin retry note in contracts/api/v2/migration.json and the deny.approved scenario description no longer say any deny overrides an approval.

Left for maintainers: no contract scenario covers the new 409 on deny. Only the Go DB test pins it. A deny.conflict row next to approve.conflict would need executor fixture work, so I left it out.

Tests: TestDeviceLoginDenyApprovedByAnotherAccountDB doesn't compile on main because Deny gained a parameter. With the extra argument removed, it fails on main (deny by another account error = <nil>) and passes on this branch. The added orphaned-approval case failed on 2b928db and passes now. go test for internal/auth (Postgres, -race on the device sign-in tests), internal/api/handlers and internal/apiv2 passes, as do make lint-changed, verify-size-ratchet, verify-bidi, verify-local-paths, verify-scenario-catalogs and verify-migration-ledger.

Cross-provider review: gpt-6.1-sol (xhigh) reviewed 2b928db and found nothing.

Validated features: no passed case on the v1.0 board touches device sign-in. Validation tasks: none.

User manual: unaffected. The TV sign-in page doesn't describe deny or approvals from another account.

Apple/Android parity: none needed. This is a server-side authority check.

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

Fit: it closes a real authority gap in device sign-in at the service that owns the rule, matches approve's existing behavior, and adds no new surface. Readiness: the behavior is shown by a test that fails without the fix, and the one edge case it opened is fixed and covered.

@macroscopeapp

macroscopeapp Bot commented Oct 23, 2026

Copy link
Copy Markdown

The Evidence section now shows before-and-after API responses, but this change is a multi-step device sign-in flow. Add a short recording of one account approving, another attempting to deny, and the device still receiving the approval; identify the surface and build or commit.

Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness.

Posted via Macroscope — Visible change evidence

@coderabbitai coderabbitai Bot added the api-v2 API v2 / Huma migration program (epic #135); long-running, stacked by phase label Oct 23, 2026
@Quick104
Quick104 merged commit c4c3320 into Silo-Server:main Oct 23, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-v2 API v2 / Huma migration program (epic #135); long-running, stacked by phase bug Something isn't working evidence-required Needs before-and-after evidence before the Evidence check passes go Pull requests that update go code impact: security Auth, privacy, or permission boundary priority: P1 Core-path bug; painful workaround — next after P0 size/M 50–199 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Another account can deny a TV sign-in someone already approved

2 participants