fix: keep header and proxy credentials out of the ffmpeg input options error refs #7801 (#7802)

This commit is contained in:
Jash Ambaliya authored and GitHub committed 2026-11-26 21:36:32 -05:00
1 parent ec60196a65
commit 9399bc2d6e
4 files changed
+56 -1

No files matched your search

+1 -1
View File
@@ -462,7 +462,7 @@ int FfmpegCamera::OpenFfmpeg() {
ret = av_dict_parse_string(&opts, mOptions.c_str(), "=", kOptionSeparators, 0);
if (ret < 0) {
Error("Could not parse ffmpeg input options '%s'. Options must be key=value pairs separated by commas or "
"new lines, such as tls_verify=0, not ffmpeg command line flags like -tls_verify 0.", mOptions.c_str());
"new lines, such as tls_verify=0, not ffmpeg command line flags like -tls_verify 0.", options_for_log(mOptions).c_str());
}
// "loop=1" is handled by us (seek-to-start on EOF), not by ffmpeg, which
+24
View File
@@ -694,6 +694,30 @@ std::string request_for_log(const std::string &request) {
return out;
}
std::string options_for_log(const std::string &options) {
std::string out;
out.reserve(options.size());
std::size_t start = 0;
while (start < options.size()) {
std::size_t sep = options.find_first_of(kOptionSeparators, start);
std::size_t end = (sep == std::string::npos) ? options.size() : sep;
std::string entry = options.substr(start, end - start);
std::size_t eq = entry.find('=');
std::string key = (eq == std::string::npos) ? "" : StringToLower(TrimSpaces(entry.substr(0, eq)));
if (key == "headers" or key == "cookies" or key == "http_proxy") {
out += entry.substr(0, eq + 1) + "<not logged>";
} else if (StringToLower(entry).find("authorization") != std::string::npos) {
out += "<not logged>";
} else {
out += entry;
}
if (sep == std::string::npos) break;
out += options[sep];
start = sep + 1;
}
return out;
}
std::string remove_newlines( std::string str ) {
while (!str.empty() && str.find("\n") != std::string::npos)
str.erase(std::remove(str.begin(), str.end(), '\n'), str.cend());
+4
View File
@@ -197,6 +197,10 @@ std::string url_for_log(const std::string &url);
// url_for_log() and the value of any Authorization or Proxy-Authorization
// header (Basic carries user:password, only base64-encoded) replaced.
std::string request_for_log(const std::string &request);
// A monitor's Options string as it may be logged: the values of headers,
// cookies and http_proxy (which carry credentials) and any entry mentioning
// authorization are replaced with "<not logged>".
std::string options_for_log(const std::string &options);
std::string UriEncode(const std::string &value);
// url with user:pass@ inserted after its scheme://, as stored (not encoded: a
+27
View File
@@ -556,6 +556,33 @@ TEST_CASE("request_for_log") {
}
}
TEST_CASE("options_for_log") {
SECTION("a headers value is removed") {
REQUIRE(options_for_log("headers=Authorization: Basic dXNlcjpwYXNz") == "headers=<not logged>");
}
SECTION("the separators around a removed value are kept") {
REQUIRE(options_for_log("tls_verify=0,headers=Authorization: Bearer abc,timeout=5")
== "tls_verify=0,headers=<not logged>,timeout=5");
}
SECTION("a newline separated options string") {
REQUIRE(options_for_log("cookies=sid=abc\ntimeout=5000000")
== "cookies=<not logged>\ntimeout=5000000");
}
SECTION("a proxy url carrying credentials is removed") {
REQUIRE(options_for_log("http_proxy=http://u:p@host:3128") == "http_proxy=<not logged>");
}
SECTION("a command-line style authorization value without '=' is removed") {
REQUIRE(options_for_log("-headers Authorization: Basic xyz") == "<not logged>");
}
SECTION("options without credentials are unchanged") {
std::string opts = "tls_verify=0,rw_timeout=5000000";
REQUIRE(options_for_log(opts) == opts);
}
SECTION("the empty string") {
REQUIRE(options_for_log("") == "");
}
}
TEST_CASE("url_for_log") {
SECTION("plain url is unchanged") {
REQUIRE(url_for_log("rtsp://127.0.0.1:8554/cam") == "rtsp://127.0.0.1:8554/cam");