Skip to content

Commit 61a9d05

Browse files
Hansel Ipclaude
andcommitted
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 <noreply@anthropic.com>
1 parent 97f7f8f commit 61a9d05

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

lib/http/HttpResponseDecoder.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,14 @@ namespace MAT_NS_BEGIN {
173173
try
174174
{
175175
std::string body(response.GetBody().begin(), response.GetBody().end());
176+
177+
// Validate that the body is valid JSON before attempting to parse
178+
if (body.empty() || !nlohmann::json::accept(body))
179+
{
180+
LOG_ERROR("HTTP response: body is not valid JSON, skipping processing");
181+
return;
182+
}
183+
176184
responseBody = nlohmann::json::parse(body.c_str());
177185
int accepted = 0;
178186
auto acc = responseBody.find("acc");

0 commit comments

Comments
 (0)