From 5846ae3525cf7f9d6024edc330b2cf58f4b8ffbc Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Sun, 8 Nov 2026 17:45:14 +0100 Subject: op-mode: T9587: reject control characters in operator commands The special character check for operator-level users allowed any whitespace, including newlines. Tag node values are substituted into a shell command which runs as root, so an operator could append arbitrary commands, e.g. "vyos-op-run show interfaces ethernet $'eth0\nid'". Only plain spaces are accepted now, everything else is rejected before privileges are raised. The operator smoketest covers this case. --- src/ocaml/vyos_op_run.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ocaml/vyos_op_run.ml b/src/ocaml/vyos_op_run.ml index 69028792e..71fb1d769 100644 --- a/src/ocaml/vyos_op_run.ml +++ b/src/ocaml/vyos_op_run.ml @@ -240,7 +240,7 @@ let has_unsafe_characters cmd = (* XXX: this function is highly restrictive now, until we are completely certain that shell escape cannot happen down the line inside VyOS op mode scripts. - Alphanumeric characters, hyphens, dots, and whitespace + Alphanumeric characters, hyphens, dots, and plain spaces should allow operator users to use most commands that take interface names, FQDNs, and config entities like IPsec peer names. @@ -256,7 +256,7 @@ let has_unsafe_characters cmd = *) let () = Logs.debug @@ fun m -> m "Checking the command for unsafe characters" in try - let _ = Pcre2.exec ~pat:{|[^a-zA-Z0-9_\-\.\s]|} cmd in + let _ = Pcre2.exec ~pat:{|[^a-zA-Z0-9_\-\. ]|} cmd in let () = Printf.fprintf stderr "Command [%s] contains special characters \ that operator-level users are not allowed to use\n" cmd -- cgit v1.2.3