Skip to content

Fix HomeMatic Script injection in hmscript_escapeString - #132

Open
claymore666 wants to merge 1 commit into
eq-3:masterfrom
claymore666:security/hmscript-escape-backslash
Open

Fix HomeMatic Script injection in hmscript_escapeString#132
claymore666 wants to merge 1 commit into
eq-3:masterfrom
claymore666:security/hmscript-escape-backslash

Conversation

@claymore666

Copy link
Copy Markdown

What

Escape the backslash character (first) in hmscript_escapeString.

Why

hmscript_escapeString escaped the quote character but not the backslash. Because the generated HomeMatic Script var 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 a LEVEL USER JSON-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_escapeString proc, emitting the var name = "..."; line for a breakout vector and benign values, and modelling ReGa's string-literal decoding:

  • Before: the crafted value closed the literal early and the trailing tokens were parsed as executable script.
  • After: the same value stays contained within the literal; benign values (including those with quotes and backslashes) round-trip correctly.

The change is ASCII-only and the file's existing ISO-8859-1 encoding is preserved.

Refs #131

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).
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.

1 participant