Fix HomeMatic Script injection in hmscript_escapeString - #132
Open
claymore666 wants to merge 1 commit into
Open
Conversation
hmscript_escapeString escaped quotes but never escaped the backslash character itself. A user-supplied string value containing a backslash positioned before a quote would, once the quote was escaped to \", be decoded by ReGa as an escaped backslash that closes the generated `var name = "...";` literal early — turning the remainder of the input into executable HomeMatic Script. Because the API funnels user input through this helper, an authenticated low-privilege (LEVEL USER) caller could reach system.Exec and run OS commands as root. Escape backslash first so backslashes introduced by escaping are themselves escaped. This also fixes silent loss of literal backslashes in benign values (e.g. Windows-style paths).
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.
What
Escape the backslash character (first) in
hmscript_escapeString.Why
hmscript_escapeStringescaped the quote character but not the backslash. Because the generated HomeMatic Scriptvar name = "<value>";declarations are decoded by ReGa (which performs its own backslash-escape handling), a crafted string value could terminate the literal early and have the remainder executed as live HomeMatic Script — reachable by aLEVEL USERJSON-RPC caller and able to run OS commands as root.Escaping the backslash first ensures any backslash introduced by the escaping step is itself escaped, so crafted input stays inert inside the literal. This also fixes a pre-existing bug where legitimate backslashes in values (e.g. Windows-style paths) were silently dropped.
Verification
The fix was validated by sourcing the real
hmscript_escapeStringproc, emitting thevar name = "...";line for a breakout vector and benign values, and modelling ReGa's string-literal decoding:The change is ASCII-only and the file's existing ISO-8859-1 encoding is preserved.
Refs #131