Skip to content

fix(api): restrict MQTT sample endpoint to admins and disallow wildcard topics#56

Open
Micsi wants to merge 1 commit into
mainfrom
codex/propose-fix-for-mqtt-payload-vulnerability
Open

fix(api): restrict MQTT sample endpoint to admins and disallow wildcard topics#56
Micsi wants to merge 1 commit into
mainfrom
codex/propose-fix-for-mqtt-payload-vulnerability

Conversation

@Micsi
Copy link
Copy Markdown
Owner

@Micsi Micsi commented May 18, 2026

Motivation

  • The GET /instances/{instance_id}/mqtt/sample endpoint previously allowed any authenticated user to subscribe with server-side adapter credentials to an arbitrary topic, which could disclose sensitive broker payloads.
  • Wildcard topics and empty topics increase the risk of broad or unintended data disclosure when the server subscribes on behalf of callers.

Description

  • Require admin-level authorization for the sampling endpoint by switching the dependency from get_current_user to get_admin_user in obs/api/v1/adapters.py for mqtt_sample_payload to prevent low-privileged API keys from invoking it.
  • Add topic validation in obs/api/v1/adapters.py to strip() the topic, reject empty topics, and return HTTP 400 if the topic contains MQTT wildcard characters # or +.
  • Preserve existing behavior and timeout handling for single-topic sampling and error handling when aiomqtt is unavailable or the MQTT connection fails.

Testing

  • Ran python -m compileall obs/api/v1/adapters.py and the module compiled successfully with no syntax errors.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant