Skip to content

Commit 5bf85a8

Browse files
committed
Improve parameter validation in HTTP server
1 parent 9c890de commit 5bf85a8

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

Source/Utils/OpenEphysHttpServer.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,7 @@ class OpenEphysHttpServer : juce::Thread
11151115
}
11161116
catch (json::exception& e)
11171117
{
1118+
LOGE ("HTTPServer - Failed to parse request body. Exception: ", e.what());
11181119
res.set_content (e.what(), "text/plain");
11191120
res.status = 400;
11201121
return;
@@ -1124,6 +1125,7 @@ class OpenEphysHttpServer : juce::Thread
11241125

11251126
if (val.isUndefined())
11261127
{
1128+
LOGE ("HTTPServer - Value is undefined after conversion.");
11271129
res.set_content ("Request value could not be converted.", "text/plain");
11281130
res.status = 400;
11291131
return;
@@ -1222,6 +1224,7 @@ class OpenEphysHttpServer : juce::Thread
12221224
}
12231225
catch (json::exception& e)
12241226
{
1227+
LOGE ("HTTPServer - Failed to parse request body. Exception: ", e.what());
12251228
res.set_content (e.what(), "text/plain");
12261229
res.status = 400;
12271230
return;
@@ -1231,11 +1234,24 @@ class OpenEphysHttpServer : juce::Thread
12311234

12321235
if (val.isUndefined())
12331236
{
1237+
LOGE ("HTTPServer - Value is undefined after conversion.");
12341238
res.set_content ("Request value could not be converted.", "text/plain");
12351239
res.status = 400;
12361240
return;
12371241
}
12381242

1243+
if (parameter->getType() == Parameter::MASK_CHANNELS_PARAM
1244+
|| parameter->getType() == Parameter::SELECTED_CHANNELS_PARAM)
1245+
{
1246+
if (! val.isArray())
1247+
{
1248+
LOGE ("HTTPServer - Value for masked and selected channels parameter should be an array.");
1249+
res.set_content ("Value for masked and selected channels parameter should be an array.", "text/plain");
1250+
res.status = 400;
1251+
return;
1252+
}
1253+
}
1254+
12391255
std::promise<void> parameterChanged;
12401256
std::future<void> parameterChangedFuture = parameterChanged.get_future();
12411257

@@ -1440,7 +1456,7 @@ class OpenEphysHttpServer : juce::Thread
14401456
{
14411457
(*parameter_json)["name"] = parameter->getName().toStdString();
14421458
(*parameter_json)["type"] = parameter->getParameterTypeString().toStdString();
1443-
(*parameter_json)["value"] = parameter->getValue().toString().toStdString();
1459+
(*parameter_json)["value"] = parameter->getValueAsString().toStdString();
14441460
}
14451461

14461462
inline static void parameters_to_json (GenericProcessor* processor, std::vector<json>* parameters_json)

0 commit comments

Comments
 (0)