Skip to content

Commit d9aca6d

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 64606bd commit d9aca6d

1 file changed

Lines changed: 35 additions & 2 deletions

File tree

net/http/src/TRootSniffer.cxx

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <memory>
3434
#include <vector>
3535
#include <string.h>
36+
#include <ctype.h>
3637

3738
const char *item_prop_kind = "_kind";
3839
const char *item_prop_more = "_more";
@@ -1209,9 +1210,41 @@ Bool_t TRootSniffer::ExecuteCmd(const std::string &path, const std::string &opti
12091210
return kTRUE;
12101211
}
12111212

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

0 commit comments

Comments
 (0)