Security hardening: sanitize MQTT topics, fix bounds check, reduce lo…#14
Open
Security hardening: sanitize MQTT topics, fix bounds check, reduce lo…#14
Conversation
…g exposure
- Strip MQTT wildcard characters (#, +, /) from user-provided topic
segments via new SanitizeSegment method, preventing topic traversal
from subdevice nicknames sourced from gateway API
- Add bounds check on topic.Split('/') before array indexing in
MQTT command handler to prevent IndexOutOfRangeException
- Remove full message payloads from Warning-level log lines on
publish failure (topic-only logging now)
- Delete stale Ecowitt.Controller/Dockerfile targeting .NET 8 / Debug
- Remove unused FluentValidation, Swashbuckle package references
There was a problem hiding this comment.
Pull request overview
Security hardening for MQTT topic handling and logging in the controller’s MQTT integration, plus some cleanup of build artifacts and unused dependencies.
Changes:
- Introduces segment-level MQTT topic sanitization to prevent wildcard/topic traversal injection via gateway/subdevice names.
- Adds a defensive bounds check when parsing Home Assistant command topics to avoid
IndexOutOfRangeException. - Reduces log exposure by removing full payloads from Warning-level publish-failure logs; removes unused package references and deletes a stale Dockerfile.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/Ecowitt.Controller/Service/Mqtt/MqttService.Publisher.cs |
Removes message payload from Warning logs on publish failures. |
src/Ecowitt.Controller/Service/Mqtt/MqttService.Events.cs |
Adds Split('/') bounds check before indexing when handling HA command topics. |
src/Ecowitt.Controller/Service/Mqtt/MqttService.DiscoveryPublisher.cs |
Switches discovery topic building to sanitize only user-provided segments. |
src/Ecowitt.Controller/Service/Mqtt/MqttService.Consumer.cs |
Aligns discovery removal topic generation with new segment sanitization. |
src/Ecowitt.Controller/Service/Mqtt/MqttPathBuilder.cs |
Adds SanitizeSegment and updates topic builders to sanitize each segment. |
src/Ecowitt.Controller/Ecowitt.Controller.csproj |
Removes unused FluentValidation/Swashbuckle-related package references. |
src/Ecowitt.Controller/Dockerfile |
Deletes stale .NET 8 Debug Dockerfile. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
…d tests - Parse subdevice ID relative to the "subdevices" segment instead of a fixed index, so multi-segment base topics work correctly - Remove unused Sanitize method (all callers migrated to SanitizeSegment) - Replace old Sanitize tests with SanitizeSegment tests covering slash, hash, plus, and combined wildcard stripping
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…g exposure