Escape quotes, backslashes, $ and non-ASCII in text sent to RouterOS

1 hour ago

Until now, a comment containing quotation marks could make a MikroTik tool fail, or silently store something else. This pull request escapes free text before it goes into a RouterOS command, so a comment, a log prefix, an SSID or a password lands on the router exactly as the caller wrote it. It covers thirty-nine tools.

Ask about this presentation

Chapters

  1. 0:00Free text reaches RouterOS intact
  2. 0:21What was broken
  3. 0:48The fix
  4. 1:26Evidence
  5. 1:54Not in this pull request
Show transcript
  1. Until now, a comment containing quotation marks could make a MikroTik tool fail, or silently store something else. This pull request escapes free text before it goes into a RouterOS command, so a comment, a log prefix, an SSID or a password lands on the router exactly as the caller wrote it. It covers thirty-nine tools.

    Slide text

    Comments, passwords and SSIDs now reach RouterOS exactly as written

    Quotes, backslashes, dollar signs and accents are escaped first

  2. Inside a double quoted string, RouterOS reads quote, backslash and dollar as syntax, and it turns raw UTF-8 bytes into blanks. A comment with quotes is refused. A backslash becomes a backspace. A dollar amount loses its number. And accented or Japanese text is cut off. A password with any of these was set to a different password than the one given. About twenty tools answered success while the router was unchanged.

    Slide text

    Four kinds of text were stored wrong

    say "hi" refused: expected end of command
    a\b stored with a backspace in it
    cost $5 stored as cost, since $5 is a variable
    café 日本 stored as caf and blanks
  3. The helper already existed for a few filters. It now escapes quote, backslash and dollar. It also sends control and non-ASCII characters as backslash hex byte escapes, which RouterOS stores and prints back correctly. Plain ASCII text is unchanged. The write tools use it for comments, log prefixes, TXT text, SSIDs and passwords. For add user and update user, both the raw and the escaped password are declared for log redaction, so the escaped form never reaches the log. The private helper in the wireless module goes away, since it missed the dollar sign.

    Slide text

    One helper now quotes every free-text value

    ros_quoted, 55 call sites in 15 modules

    Escape quote, backslash, dollar
    Bytes control and non-ASCII sent as \XX
    Passwords raw and escaped form both redacted from the log
  4. The new test file drives every affected tool. Forty-seven of its fifty-four cases fail on master and all pass here, and the whole unit suite passes. In the lab, the grid of sixteen create tools against nine kinds of text went from eighty-five exact matches to all one hundred fifty-three, on RouterOS 7.21 and 7.25. And a user created with a nasty password logs in with it, and after an update only the new password works.

    Slide text

    Every tool now stores the text exactly

    47 of 54 new unit tests fail on master, all pass here
    85 to 153 of 153 tool and text combinations stored exactly, RouterOS 7.21 and 7.25
    1 password with quotes, backslash, dollar and accents logs in over SSH
  5. The author lists what is left. Names, identifiers and the filter values of read tools are still interpolated as they are. Tools that say added successfully for any reply without the word error still do so for other refusals, such as a wrong interface name, and that is a separate fix. And the write tools in the two open pull requests, one twenty-seven and one eighty-eight, need the same helper. A reviewer should check the call sites in users and wireless first, since those carry passwords.

    Slide text

    Names, success messages and two open pull requests still need work

    Names and identifiers still interpolated as written
    Success messages some tools still say added for other refusals
    PRs 127 and 188 their write tools need the helper too

What happened in AI today, in your inbox

One short email each evening. Read it and you’re caught up.

Built with ❤️ in New York