Skip to content

fix(security): add RBAC permission checks to all device API endpoints#361

Merged
robotlearning123 merged 1 commit intomainfrom
fix/device-api-missing-auth
Mar 28, 2026
Merged

fix(security): add RBAC permission checks to all device API endpoints#361
robotlearning123 merged 1 commit intomainfrom
fix/device-api-missing-auth

Conversation

@robotlearning123
Copy link
Copy Markdown
Member

Bug

All 5 device API endpoints (/api/v1/devices/) had zero authentication/authorization checks. Any user (including visitors) could:

  • Spoof heartbeats to inject fake devices or overwrite IPs
  • List/get all device records (info leak)
  • Update device metadata (arbitrary writes)
  • Mark devices offline (denial of service)

Root Cause

The devices.py route module was added without require_permission() dependency injection, unlike all other route modules (equipment, orders, vendors, etc.).

Fix

  1. Added from lab_manager.api.auth import require_permission import
  2. Added dependencies=[Depends(require_permission(...))] to all 5 endpoints:
    • POST /heartbeatmanage_devices
    • GET /view_equipment
    • GET /{id}view_equipment
    • PATCH /{id}manage_devices
    • POST /{id}/offlinemanage_devices
  3. Added manage_devices to ALL_PERMISSIONS in auth.py
  4. 5 new tests verify 401 on all endpoints when auth enabled

Test

18 passed in 4.21s (13 existing + 5 new auth tests)

🤖 Found and fixed by bug-hunter autonomous loop (cycle 47).

Comment thread tests/test_documents_route_coverage.py Fixed
Comment thread tests/test_documents_route_coverage.py Fixed
Comment thread tests/test_documents_route_coverage.py Fixed
Comment thread tests/test_documents_route_coverage.py Fixed
Comment thread tests/test_documents_route_coverage.py Fixed
Comment thread tests/test_documents_route_coverage.py Fixed
Comment thread tests/test_documents_route_coverage.py Fixed
Comment thread tests/test_documents_route_coverage.py Fixed
Comment thread tests/test_documents_route_coverage.py Fixed
Comment thread tests/test_documents_route_coverage.py Fixed
@robotlearning123 robotlearning123 force-pushed the fix/device-api-missing-auth branch from f7fff2a to 86c8ec9 Compare March 28, 2026 19:35
Comment thread tests/test_documents_route_coverage.py Fixed
Comment thread tests/test_documents_route_coverage.py Fixed
Comment thread tests/test_documents_route_coverage.py Fixed
Comment thread tests/test_documents_route_coverage.py Fixed
Comment thread tests/test_documents_route_coverage.py Fixed
Comment thread tests/test_documents_route_coverage.py Fixed
Comment thread tests/test_documents_route_coverage.py Fixed
Comment thread tests/test_documents_route_coverage.py Fixed
Comment thread tests/test_documents_route_coverage.py Fixed
Comment thread tests/test_documents_route_coverage.py Fixed
@robotlearning123 robotlearning123 force-pushed the fix/device-api-missing-auth branch 4 times, most recently from 2c595ff to 2f5372b Compare March 28, 2026 21:42
@github-actions github-actions Bot added the ci-verified All required CI checks have passed label Mar 28, 2026
All 5 device endpoints (heartbeat, list, get, update, mark-offline)
had zero authentication. Any user could:
- Spoof heartbeats to inject fake devices or overwrite IPs
- List/get all device records (info leak)
- Update device metadata (arbitrary writes)
- Mark devices offline (denial of service)

Fix: add require_permission() dependency to each endpoint:
- heartbeat, update, offline: manage_devices (new permission)
- list, get: view_equipment (existing)
- Added manage_devices to ALL_PERMISSIONS (PI/admin get it)

5 new auth-gate tests verify 401 on all endpoints when auth enabled.
@robotlearning123 robotlearning123 force-pushed the fix/device-api-missing-auth branch from 2f5372b to f5420fd Compare March 28, 2026 22:19
@robotlearning123 robotlearning123 merged commit a456532 into main Mar 28, 2026
22 checks passed
@robotlearning123 robotlearning123 deleted the fix/device-api-missing-auth branch March 28, 2026 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-verified All required CI checks have passed python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants