Skip to content

Security: require API key for firmware snapshot endpoint (VULN-002)#115

Open
tobiasmcnulty wants to merge 6 commits intomainfrom
security/vuln-002-firmware-auth
Open

Security: require API key for firmware snapshot endpoint (VULN-002)#115
tobiasmcnulty wants to merge 6 commits intomainfrom
security/vuln-002-firmware-auth

Conversation

@tobiasmcnulty
Copy link
Copy Markdown
Member

Fixes #113.

Summary

Adds mandatory MDM_FIRMWARE_API_KEY bearer-token authentication to firmware_snapshot_view. Requests without a valid key receive HTTP 401. If the key is not configured in the environment, the endpoint also returns 401 (previously it was silently unauthenticated).

Key changes

  • config/settings/base.py: new MDM_FIRMWARE_API_KEY = os.getenv("MDM_FIRMWARE_API_KEY", "") setting
  • apps/mdm/views.py: mandatory auth gate before any body parsing; missing key now returns 401 instead of logging a warning
  • tests/mdm/test_security.py (new): TestFirmwareSnapshotAuth — regression tests for unauthenticated, correctly-keyed, wrong-keyed, and missing-key cases
  • tests/mdm/test_views.py (new on main): TestFirmwareSnapshotView with set_api_key autouse fixture so that existing functional tests pass under mandatory auth

Required Operator Action

Set MDM_FIRMWARE_API_KEY in the environment and update all firmware-reporting devices to include Authorization: Bearer <key>.

Conflict resolution note

This cherry-pick spans two commits from 99-policy-editor-v2 (d6fa0ce and c574a04). d6fa0ce also contained unrelated policy_add view changes (scoped to the feature branch's policy editor refactor) which were excluded during conflict resolution. tests/mdm/test_views.py does not exist on main; a minimal file was created containing only TestFirmwareSnapshotView.

Cherry-picked from

Commits d6fa0ce and c574a04 on 99-policy-editor-v2.

@tobiasmcnulty tobiasmcnulty changed the title Security/vuln 002 firmware auth Security: require API key for firmware snapshot endpoint (VULN-002) Mar 23, 2026
Co-authored-by: Tobias McNulty <tobias@caktusgroup.com>
@tobiasmcnulty tobiasmcnulty marked this pull request as ready for review March 23, 2026 14:08
@tobiasmcnulty tobiasmcnulty marked this pull request as draft March 23, 2026 14:12
@tobiasmcnulty
Copy link
Copy Markdown
Member Author

@copelco @simonkagwi What do you think of this change? We could add the API key to the firmware app's managed configuration (or even generate and push it out automatically via Publish MDM). Probably a good idea long-term, and there's no harm in adding this now since it's not actively in use?

@tobiasmcnulty tobiasmcnulty marked this pull request as ready for review March 23, 2026 14:13
Copy link
Copy Markdown
Contributor

@simonkagwi simonkagwi left a comment

Choose a reason for hiding this comment

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

Looks good to me, I just have one small suggestion on the comment in the settings file. Adding the API key to the app's managed configuration sounds good too. 👍

Co-authored-by: simonkagwi <skagwi@caktusgroup.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Security: unauthenticated @csrf_exempt firmware snapshot endpoint allows arbitrary data injection (VULN-002)

2 participants