Add /status Command and Fix security issue - #374
Open
berkemutluu wants to merge 1 commit into
Open
Conversation
Adds a /status command for on-demand system status reporting, and fixes a security issue where the bot would accept commands (arm/disarm/status) from any Telegram user who messaged it, not just the intended owner.
There was a problem hiding this comment.
Pull request overview
Adds a new Telegram bot command for on-demand status reporting, and introduces an authorization guard intended to prevent unauthorized Telegram chats from issuing security-system control commands.
Changes:
- Added
/statushandling that sends a one-shot status report for the currently selected partition. - Added an early authorization check in
handleTelegram()that rejects messages whosechat_iddoes not match the configuredtelegramUserID. - Updated the example header docs to include
/statusand clarify “user/chat ID”.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+352
to
+356
| // Rejects any message that is not from the authorized chat ID and notifies the sender | ||
| if (telegramBot.messages[i].chat_id != telegramUserID) { | ||
| telegramBot.sendMessage(telegramBot.messages[i].chat_id, "Unauthorized: this chat is not permitted to control this security system.", ""); | ||
| continue; // Skips processing this message entirely | ||
| } |
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.
Summary
Changes
1. New /status command
Added
sendStatus(byte partition), which builds and sends a single status report for the currently selected partition.Triggered by sending /status to the bot.
Response includes:
Example output:
2. Chat ID authorization check (security fix)
Issue:
the bot processed incoming messages from any Telegram chat that messaged it — there was no check that the sender was the intended operator. Anyone who found the bot (e.g. by guessing/scanning bot usernames, or if the token/bot were ever discovered) could potentially send
/armstay,/disarm, etc., since the access code is only required by the panel for certain actions, not by the bot itself before forwarding a command.Fix:
handleTelegram()now checkstelegramBot.messages[i].chat_idagainsttelegramUserIDas the first step, before any other message handling. Messages from a mismatchedchat_idare rejected outright: no partition selection, no arm/disarm, no status — and the bot replies directly to that sender with"Unauthorized: this chat is not permitted to control this security system.", then continues to the next message.No other logic, wiring notes, or existing command behavior (
/armstay,/armaway, /armnight,/disarm, partition selection) was modified.