From 61a9d05daf49f64b7cb81707d40896ceb557a05e Mon Sep 17 00:00:00 2001 From: Hansel Ip Date: Fri, 23 Jan 2026 12:54:40 -0800 Subject: [PATCH] Fix crash when HttpResponseDecoder receives non-JSON response Add validation before JSON parsing in processBody to prevent crashes when receiving non-JSON HTTP responses (e.g., HTML from captive portals). Uses nlohmann::json::accept() to validate response body before parsing. Fixes #1338 Co-Authored-By: Claude Sonnet 4.5 --- lib/http/HttpResponseDecoder.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/http/HttpResponseDecoder.cpp b/lib/http/HttpResponseDecoder.cpp index 9e3fd786a..72184c7db 100644 --- a/lib/http/HttpResponseDecoder.cpp +++ b/lib/http/HttpResponseDecoder.cpp @@ -173,6 +173,14 @@ namespace MAT_NS_BEGIN { try { std::string body(response.GetBody().begin(), response.GetBody().end()); + + // Validate that the body is valid JSON before attempting to parse + if (body.empty() || !nlohmann::json::accept(body)) + { + LOG_ERROR("HTTP response: body is not valid JSON, skipping processing"); + return; + } + responseBody = nlohmann::json::parse(body.c_str()); int accepted = 0; auto acc = responseBody.find("acc");