summaryrefslogtreecommitdiff
path: root/redfish-core/src/utils
diff options
context:
space:
mode:
authorEd Tanous <edtanous@google.com>2022-02-08 14:24:30 +0300
committerEd Tanous <ed@tanous.net>2023-02-17 20:01:21 +0300
commit1aa0c2b84be62a20d8c37a11ad877e0a8a48c69d (patch)
tree60a3f45204bcc8947f25db6e64cc3cd5d01f0648 /redfish-core/src/utils
parent6177a301de5cefdb4a31601ec2d899f4309fc6c2 (diff)
downloadbmcweb-1aa0c2b84be62a20d8c37a11ad877e0a8a48c69d.tar.xz
Add option for validating content-type header
For systems implementing to the OWASP security guidelines[1] (of which all should ideally) we should be checking the content-type header all times that we parse a request as JSON. This commit adds an option for parsing content-type, and sets a default of "must get content-type". Ideally this would not be a breaking change, but given the number of guides and scripts that omit the content type, it seems worthwhile to add a trapdoor, such that people can opt into their own model on how they would like to see this checking work. Tested: ``` curl --insecure -H "Content-Type: application/json" -X POST -D headers.txt https://${bmc}/redfish/v1/SessionService/Sessions -d '{"UserName":"root", "Password":"0penBmc"}' ``` Succeeds. Removing Content-Type argument causes bmc to return Base.1.13.0.UnrecognizedRequestBody. [1] cheatsheetseries.owasp.org/cheatsheets/REST_Security_Cheat_Sheet.html Change-Id: Iaa47dd563b40036ff2fc2cacb70d941fd8853038 Signed-off-by: Ed Tanous <edtanous@google.com>
Diffstat (limited to 'redfish-core/src/utils')
-rw-r--r--redfish-core/src/utils/json_utils.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/redfish-core/src/utils/json_utils.cpp b/redfish-core/src/utils/json_utils.cpp
index a47b4d8217..89723ccd12 100644
--- a/redfish-core/src/utils/json_utils.cpp
+++ b/redfish-core/src/utils/json_utils.cpp
@@ -15,6 +15,13 @@
*/
#include "utils/json_utils.hpp"
+#include "error_messages.hpp"
+#include "http/http_request.hpp"
+#include "http/http_response.hpp"
+#include "http/parsing.hpp"
+
+#include <nlohmann/json.hpp>
+
namespace redfish
{
@@ -24,14 +31,17 @@ namespace json_util
bool processJsonFromRequest(crow::Response& res, const crow::Request& req,
nlohmann::json& reqJson)
{
+ JsonParseResult ret = parseRequestAsJson(req, reqJson);
+ if (ret == JsonParseResult::BadContentType)
+ {
+ messages::unrecognizedRequestBody(res);
+ return false;
+ }
reqJson = nlohmann::json::parse(req.body, nullptr, false);
if (reqJson.is_discarded())
{
messages::malformedJSON(res);
-
- res.end();
-
return false;
}