Skip to content

Commit 5f5ca3c

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 024ea45 commit 5f5ca3c

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";
@@ -1213,9 +1215,41 @@ Bool_t TRootSniffer::ExecuteCmd(const std::string &path, const std::string &opti
12131215
return kTRUE;
12141216
}
12151217

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

0 commit comments

Comments
 (0)