fix: harden camera API endpoints (CUB-234) #12

Merged
overseer merged 2 commits from agent/dex/CUB-234-harden-camera-endpoints into dev 2026-05-28 06:59:11 -04:00
Owner

Overview

Hardens all camera API endpoints with input validation, structured error responses, and proper SQL handling.

Changes

Input Validation (new harden.go)

  • Content-Type validation on all POST endpoints
  • Request body size limit (64KB)
  • Field length: camera_id ≤ 64, friendly_name ≤ 128, mode ≤ 32, resolution ≤ 32
  • FPS range: 0-240
  • Battery percentage range: 0-100

Structured Error Responses

  • Replaced ad-hoc map[string]string errors with typed APIError {error, code, details}
  • Consistent format across all endpoints

Bug Fixes

  • MacAddress model field: string*string (fixes NULL scan errors)
  • isUniqueConstraintErr: now matches both camera_id and mac_address constraint violations
  • splitSQL: strips -- line comments before splitting on semicolons (fixes migration failures with modernc.org/sqlite)

Tests

  • 30 integration tests covering all endpoints
  • All tests PASS

Files Changed

  • internal/api/harden.go — new validation and response helpers
  • internal/api/cameras.go — hardened GET/POST camera handlers
  • internal/api/recording.go — hardened start/stop handlers
  • internal/api/status.go — hardened PushStatus handler
  • internal/api/camera_test.go — 30 integration tests
  • internal/db/db.go — fixed SQL line comment stripping
  • pkg/models/camera.go — MacAddress → *string

Closes CUB-234

## Overview Hardens all camera API endpoints with input validation, structured error responses, and proper SQL handling. ## Changes ### Input Validation (new `harden.go`) - Content-Type validation on all POST endpoints - Request body size limit (64KB) - Field length: `camera_id` ≤ 64, `friendly_name` ≤ 128, `mode` ≤ 32, `resolution` ≤ 32 - FPS range: 0-240 - Battery percentage range: 0-100 ### Structured Error Responses - Replaced ad-hoc `map[string]string` errors with typed `APIError {error, code, details}` - Consistent format across all endpoints ### Bug Fixes - `MacAddress` model field: `string` → `*string` (fixes NULL scan errors) - `isUniqueConstraintErr`: now matches both `camera_id` and `mac_address` constraint violations - `splitSQL`: strips `--` line comments before splitting on semicolons (fixes migration failures with `modernc.org/sqlite`) ### Tests - **30 integration tests** covering all endpoints - All tests PASS ### Files Changed - `internal/api/harden.go` — new validation and response helpers - `internal/api/cameras.go` — hardened GET/POST camera handlers - `internal/api/recording.go` — hardened start/stop handlers - `internal/api/status.go` — hardened PushStatus handler - `internal/api/camera_test.go` — 30 integration tests - `internal/db/db.go` — fixed SQL line comment stripping - `pkg/models/camera.go` — MacAddress → *string Closes CUB-234
Otto added 1 commit 2026-05-23 08:52:11 -04:00
fix: harden camera API endpoints (CUB-234)
CI/CD / lint-and-typecheck (pull_request) Failing after 12m11s
CI/CD / test (pull_request) Has been cancelled
CI/CD / build (pull_request) Has been cancelled
CI/CD / deploy (pull_request) Has been cancelled
1f253283f8
- Add request validation: Content-Type check, body size limit (64KB)
- Add field length validation (camera_id: 64, friendly_name: 128, mode: 32, resolution: 32)
- Add FPS range validation (0-240)
- Add battery_pct range validation (0-100)
- Replace ad-hoc map[string]string errors with structured APIError {error, code, details}
- Fix isUniqueConstraintErr to catch both camera_id and mac_address constraint violations
- Fix MacAddress model field from string to *string for NULL handling
- Fix splitSQL to strip -- line comments before splitting (was causing migration failures with modernc.org/sqlite)
- Add 30 integration tests covering all endpoints
- All tests pass: ok github.com/cubecraft/remoterig/internal/api
overseer added 1 commit 2026-05-28 06:59:01 -04:00
Merge branch 'dev' into agent/dex/CUB-234-harden-camera-endpoints
CI/CD / lint-and-typecheck (pull_request) Successful in 7s
CI/CD / test (pull_request) Successful in 8s
CI/CD / build (pull_request) Failing after 9s
CI/CD / deploy (pull_request) Has been skipped
81f168e8a4
overseer merged commit cc1b05a4e7 into dev 2026-05-28 06:59:11 -04:00
overseer deleted branch agent/dex/CUB-234-harden-camera-endpoints 2026-05-28 06:59:11 -04:00
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: CubeCraft-Creations/remote-rig#12