Skip to content

Commit dce5745

Browse files
committed
[http] analyze arguments of cmd.json
While here arbitrary string injected into ProcessLine, ensure that only numeric argument is not quoted. All other arguments kinds will be quoted and prevent execution of potentially dangerous code
1 parent 24b49ca commit dce5745

1 file changed

Lines changed: 36 additions & 2 deletions

File tree

net/http/src/TRootSniffer.cxx

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include <memory>
3333
#include <vector>
3434
#include <cstring>
35+
#include <cctype>
36+
3537

3638
const char *item_prop_kind = "_kind";
3739
const char *item_prop_more = "_more";
@@ -1216,9 +1218,41 @@ Bool_t TRootSniffer::ExecuteCmd(const std::string &path, const std::string &opti
12161218
return kTRUE;
12171219
}
12181220

1219-
TString svalue = DecodeUrlOptionValue(argvalue, kTRUE);
12201221
argname = TString("%") + argname + TString("%");
1221-
method.ReplaceAll(argname, svalue);
1222+
auto p = method.Index(argname);
1223+
if (p == kNPOS)
1224+
continue;
1225+
1226+
method.Remove(p, argname.Length());
1227+
1228+
if ((p > 0) && (p < method.Length()) && (method.Length() > 1) && (method[p-1] == '"') && (method[p] == '"')) {
1229+
// command definition has quotes around argument
1230+
// one can insert value from URL removing quotes
1231+
method.Insert(p, DecodeUrlOptionValue(argvalue, kTRUE));
1232+
continue;
1233+
}
1234+
1235+
// extract argument without removing quotes
1236+
TString svalue = DecodeUrlOptionValue(argvalue, kFALSE);
1237+
1238+
if ((svalue.Length() > 1) && (svalue[0] == '"') && (svalue[svalue.Length() - 1] == '"')) {
1239+
// if value itself has quotes, all special symbols already escaped and one can insert it as is
1240+
method.Insert(p, svalue);
1241+
continue;
1242+
}
1243+
1244+
Bool_t is_numeric = kTRUE;
1245+
// expect decimal, hex or float values here, E/e also belong to hex
1246+
for(Size_t i = 0; is_numeric && (i < svalue.Length()); ++i)
1247+
is_numeric = std::isxdigit(svalue[i]) || std::strchr(".+-", svalue[i]);
1248+
1249+
// always quote content which not numeric
1250+
if (!is_numeric)
1251+
svalue = "\"" + svalue + "\"";
1252+
else if (svalue.IsNull())
1253+
svalue = "0";
1254+
1255+
method.Insert(p, svalue);
12221256
}
12231257
}
12241258

0 commit comments

Comments
 (0)