Repository navigation
fix(users): enforce role limits on bulk quota and expiry updates - #1005
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
WalkthroughBulk expiration and data-limit updates now share target eligibility rules, validate adjusted values against role limits, and apply guarded updates. API routes and Telegram handlers pass the acting admin to these operations. ChangesBulk user limit updates
Priority: ➖ Normal Estimated code review effort: 4 (Complex) | ~45 minutes Change: Bug fix Sequence Diagram(s)sequenceDiagram
participant Admin
participant UserRouter
participant UserOperation
participant BulkCRUD
Admin->>UserRouter: Submit bulk expiration request
UserRouter->>UserOperation: Pass session, request, and admin
UserOperation->>BulkCRUD: Select and lock eligible targets
BulkCRUD-->>UserOperation: Return target IDs and current values
UserOperation->>UserOperation: Validate adjusted values against role limits
UserOperation->>BulkCRUD: Update targets within final-value bounds
BulkCRUD-->>UserOperation: Return update result or conflict
Suggested reviewers: Merge Risk: ⚪ Minimal · up to Bulk quota and expiry updates now apply the same role limits as individual updates, and the API and Telegram handlers pass the acting admin through. No merge-blocking issue was found. Pre-merge checks |
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
…am up to 2026-10-17 Owner rule of 2026-10-14: upstream changes are ported only from final upstream releases. Checked with git ls-remote on 2026-10-17 20:53 UTC; no new release since panel v5.4.1, node v0.5.4 and node_bridge_py v0.9.2 (GitHub releases, PyPI and npm also unchanged). Panel: the 79 Port queue entries are all dev-only, so they move to the new "Held for an upstream release" section with their security classification and without deadlines, and the queue is empty. Upstream dev moved to a2fb313 with 25 commits: PasarGuard#1019 is waived (the fork deleted the notifier workflow), the other 24 are held, three of them classified security: yes (PasarGuard#1004 role permissions on custom API keys, PasarGuard#1005 role limits on bulk updates, PasarGuard#1008 role disconnect policy). New branches feat/live-core-apply and two masque commits are UNMERGED-WIP; fix/xray-wg-allocation-view is the same patch as held ba27c1cc6. Node: five earlier dev-only picks are on fork main 0071e2c with trailers and leave the queue; the other eight queue entries and four new dev commits (PasarGuard#58, PasarGuard#55, PasarGuard#104, PasarGuard#106) are held, with f72ac0ef (PasarGuard#99) and a3d2d2fe (PasarGuard#101) marked as fixed by the fork's own fixes per the 2026-10-14 decisions. PasarGuard#100 (refuse to start without a valid API_KEY) is ported by design: fork commit 88162e2 already fails fast. node_bridge_py: 27be206 is ported on fork main 6116922; 22f1ef79 and the v0.9.2 bump bec9cb22 are recorded as ported by design (the one flagged line belongs to the fork's own add_backend, and the fork labels itself 0.9.2+singbox); upstream main's new PasarGuard#24 (9fa9f264) is held. scripts: fork main 51edabb has upstream main bba95f274 as an ancestor, so its thirteen queue lines are ported (decision 7 keeps them). Against live upstream the panel gate is green (282 commits, 0 unported, 103 held, 0 owed) and every fork tracker is green.
…arGuard#1005) Fork resolution: - app/db/crud/bulk.py: the limit targets are read and locked with the fork's lock shape (SELECT ... ORDER BY users.id FOR UPDATE, the same as _lock_bulk_targets), keep the fork's allowed_group_ids filter, and the write goes through the fork's _lock_bulk_targets / _apply_to_locked_targets chunked path. With validated target_ids the re-lock is per id chunk in ascending order and a vanished target, or a chunk whose guarded UPDATE matches fewer rows (bounds re-checked in SQL), rolls back the whole batch with BulkUserUpdateConflict (409). - app/operation/user.py: bulk_modify_expire/datalimit now require the admin (every caller already passed it) and keep get_allowed_group_ids. - app/routers/user.py and app/telegram/handlers/admin/bulk_actions.py already passed the admin in the fork; the fork Telegram handler is kept unchanged. Tests: tests/api/test_bulk_role_limits.py (the RED commit before this pick). (cherry picked from commit ab45a61)
…asarGuard#1005 in the sync ledger Both port-queue entries said nothing about a port while their cherry-pick -x carriers were already on main: 8527b40 for 4574d0c (PasarGuard#1000) and 9ea80e0 for ab45a61 (PasarGuard#1005), each with the RED test it landed with. They become PARTIAL entries naming the carrier, the measured reflected-hunk counts (1 of 5 and 8 of 20) and why the remainder is unreflected: upstream's load_group_inbounds needs 0aad1b7 (PasarGuard#967), still owed, and the rest is the fork's own lock and chunk shape standing in for upstream's.
The PasarGuard#1005 row said the two overflow-window cases fail "on MySQL error 1441, a 500". The run shows the bulk UPDATE failing with MySQL error 1441 on MySQL and no BulkUserResultOutOfRange on SQLite; the HTTP status was never measured, so the row no longer names one.
Summary
Bulk quota and expiry adjustments currently discard the authenticated admin, allowing non-owner roles with
users.update=ALLto bypass caps enforced by individual updates. Pass the actor through the API and Telegram handlers and check manual-write access and effective role/per-admin limits for every final value before writing. Dry runs enforce the same rules.For constrained roles, read only the target IDs and changed values, lock the rows before writes, and apply the update to that validated selection. Recheck final-value bounds in SQL and roll back the entire batch with HTTP 409 if a target changed and no longer meets the guards. Owners and roles without relevant bounds retain the existing bulk SQL path.
Quota previews, updates, and status reloads now share the same target predicate, including the existing subtraction rule that skips nonpositive resulting quotas. Unlimited values remain unchanged. Expiry validation and write bounds use one reference time for the batch.
Type of change
Testing
git diff --checkpassed.Notes for reviewers
Four production Python files change. No test files, documentation files, migrations or dependencies are included. The existing success response and node sync for changed statuses are preserved.
Integration validation of the five open audit PRs on current dev: all patches applied together without conflicts, and 400 local tests passed in isolated fresh SQLite runs. Ruff passed on all 11 touched production files.
Summary by CodeRabbit