Skip to content

Commit e473667

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 78e0ebc commit e473667

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
@@ -33,6 +33,8 @@
3333
#include <memory>
3434
#include <vector>
3535
#include <cstring>
36+
#include <cctype>
37+
3638

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

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

0 commit comments

Comments
 (0)