Add untrusted connection security infrastructure (v3)

Replace the v2 blacklist approach with a per-command flag system.
Commands must opt in to being available for untrusted connections
via flag_untrusted_safe (0x400), checked in call_command() which
catches all execution paths including nested commands.

Infrastructure changes:
- Add flag_untrusted_safe to CommandMap
- Add untrusted_error exception type for proper error codes
- Enforce trust check in both call_command() overloads
- Add catch blocks in xmlrpc_c, xmlrpc_tinyxml2, and jsonrpc handlers
- Port SCGI trust state management from v2 (thread_local, header parsing)
- Add _U macro variants in command_helpers.h for safe command registration
- Add CMD2_VAR_*_U and CMD2_VAR_*_U_GET variants for variables
This commit is contained in:
Xirvik
2026-03-01 16:39:45 +00:00
committed by Jari Sundell
parent 38fc815d52
commit 598914908f
10 changed files with 199 additions and 21 deletions
+6 -2
View File
@@ -31,7 +31,7 @@ const int XMLRPC_PARSE_ERROR = -503;
// const int XMLRPC_NETWORK_ERROR = -504;
// const int XMLRPC_TIMEOUT_ERROR = -505;
const int XMLRPC_NO_SUCH_METHOD_ERROR = -506;
// const int XMLRPC_REQUEST_REFUSED_ERROR = -507;
const int XMLRPC_REQUEST_REFUSED_ERROR = -507;
// const int XMLRPC_INTROSPECTION_DISABLED_ERROR = -508;
const int XMLRPC_LIMIT_EXCEEDED_ERROR = -509;
// const int XMLRPC_INVALID_UTF8_ERROR = -510;
@@ -238,7 +238,11 @@ execute_command(std::string method_name, const tinyxml2::XMLElement* params_elem
throw rpc_error(XMLRPC_TYPE_ERROR, "invalid parameters: too few");
}
return rpc::commands.call_command(cmd_itr, params_raw, target);
try {
return rpc::commands.call_command(cmd_itr, params_raw, target);
} catch (untrusted_error& e) {
throw rpc_error(XMLRPC_REQUEST_REFUSED_ERROR, e.what());
}
}
void