Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
377 changes: 377 additions & 0 deletions docs/libxml2-json-review-2026-04-14.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions headers/modsecurity/audit_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <iostream>
#include <fstream>
#include <string>
#include <string_view>
#endif

#ifndef HEADERS_MODSECURITY_AUDIT_LOG_H_
Expand Down
3 changes: 2 additions & 1 deletion headers/modsecurity/rules_set_phases.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#ifdef __cplusplus
#include <ctime>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
Expand Down Expand Up @@ -60,4 +61,4 @@ class RulesSetPhases {
} // namespace modsecurity
#endif

#endif // HEADERS_MODSECURITY_RULES_SET_PHASES_H_
#endif // HEADERS_MODSECURITY_RULES_SET_PHASES_H_
1 change: 1 addition & 0 deletions headers/modsecurity/rules_set_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#ifdef __cplusplus
#include <ctime>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
Expand Down
2 changes: 2 additions & 0 deletions src/actions/ctl/rule_remove_by_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
*
*/

#include <list>
#include <string>
#include <utility>

#include "modsecurity/actions/action.h"
#include "modsecurity/transaction.h"
Expand Down
1 change: 1 addition & 0 deletions src/anchored_set_variable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <ctime>
#include <iostream>
#include <fstream>
#include <memory>
#include <string>
#include <vector>

Expand Down
1 change: 1 addition & 0 deletions src/anchored_variable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <ctime>
#include <iostream>
#include <fstream>
#include <memory>
#include <string>
#include <vector>

Expand Down
1 change: 1 addition & 0 deletions src/audit_log/audit_log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <ctype.h>

#include <fstream>
#include <string_view>

#include "modsecurity/transaction.h"
#include "modsecurity/rule_message.h"
Expand Down
1 change: 1 addition & 0 deletions src/operators/pm_from_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include "src/operators/pm_from_file.h"

#include <memory>
#include <string>

#include "src/operators/operator.h"
Expand Down
1 change: 1 addition & 0 deletions src/operators/validate_byte_range.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include "src/operators/validate_byte_range.h"

#include <array>
#include <cctype>
#include <cstring>
#include <string>
Expand Down
21 changes: 10 additions & 11 deletions src/request_body_processor/json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,21 @@
#include "src/request_body_processor/json.h"

#include <chrono>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <string>

#include "modsecurity/transaction.h"
#include "src/request_body_processor/json_adapter.h"
#include "src/request_body_processor/json_instrumentation.h"


namespace modsecurity::RequestBodyProcessor {

static const double json_depth_limit_default = 10000.0;
static const char* json_depth_limit_exceeded_msg = ". Parsing depth limit exceeded";
static const char *const json_depth_limit_exceeded_msg =
". Parsing depth limit exceeded";

namespace {

Expand Down Expand Up @@ -119,11 +122,7 @@ JsonSinkStatus addStringViewAsSinkStatus(JSON *json, std::string_view value) {
} // namespace

JSON::JSON(Transaction *transaction) : m_transaction(transaction),
m_current_key(""),
m_data(""),
m_max_depth(json_depth_limit_default),
m_current_depth(0),
m_depth_limit_exceeded(false) {
m_max_depth(json_depth_limit_default) {
}


Expand Down Expand Up @@ -185,11 +184,11 @@ bool JSON::complete(std::string *err) {


int JSON::addArgument(const std::string& value) {
std::string data("");
std::string data;
std::string path;

for (size_t i = 0; i < m_containers.size(); i++) {
const JSONContainerArray *a = dynamic_cast<JSONContainerArray *>(
for (size_t i = 0; i < m_containers.size(); i++) {
const auto *a = dynamic_cast<JSONContainerArray *>(
m_containers[i].get());
path = path + m_containers[i]->m_name;
if (a != nullptr) {
Expand All @@ -199,8 +198,8 @@ int JSON::addArgument(const std::string& value) {
}
}

if (m_containers.size() > 0) {
JSONContainerArray *a = dynamic_cast<JSONContainerArray *>(
if (!m_containers.empty()) {
auto *a = dynamic_cast<JSONContainerArray *>(
m_containers.back().get());
if (a) {
a->m_elementCounter++;
Expand Down
27 changes: 15 additions & 12 deletions src/request_body_processor/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,41 @@
#ifndef SRC_REQUEST_BODY_PROCESSOR_JSON_H_
#define SRC_REQUEST_BODY_PROCESSOR_JSON_H_

#include <cstddef>
#include <cstdint>
#include <deque>
#include <memory>
#include <string>
#include <string_view>

#include "modsecurity/transaction.h"
#include "modsecurity/rules_set.h"
#include "src/request_body_processor/json_backend.h"

namespace modsecurity {
class Transaction;
}


namespace modsecurity::RequestBodyProcessor {


class JSONContainer {
public:
explicit JSONContainer(const std::string &name) : m_name(name) { }
virtual ~JSONContainer() { }
virtual ~JSONContainer() = default;
std::string m_name;
};


class JSONContainerArray : public JSONContainer {
public:
explicit JSONContainerArray(const std::string &name) : JSONContainer(name),
m_elementCounter(0) { }
size_t m_elementCounter;
using JSONContainer::JSONContainer;
size_t m_elementCounter = 0;
};


class JSONContainerMap : public JSONContainer {
public:
explicit JSONContainerMap(const std::string &name) : JSONContainer(name) { }
using JSONContainer::JSONContainer;
};


Expand Down Expand Up @@ -88,7 +91,7 @@ class JSON : public JsonEventSink {

std::string getCurrentKey(bool emptyIsNull = false) {
std::string ret(m_current_key);
if (m_containers.size() == 0) {
if (m_containers.empty()) {
return "json";
}
if (m_current_key.empty()) {
Expand All @@ -109,12 +112,12 @@ class JSON : public JsonEventSink {
void clearContainers();

std::deque<std::unique_ptr<JSONContainer>> m_containers;
Transaction *m_transaction;
Transaction *m_transaction = nullptr;
std::string m_current_key;
std::string m_data;
double m_max_depth;
int64_t m_current_depth;
bool m_depth_limit_exceeded;
double m_max_depth = 0.0;
int64_t m_current_depth = 0;
bool m_depth_limit_exceeded = false;
};


Expand Down
13 changes: 8 additions & 5 deletions src/request_body_processor/json_backend_jsoncons.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@

#include <cctype>
#include <chrono>
#include <cstddef>
#include <cstdint>
#include <string>
#include <string_view>
#include <system_error>
#include <utility>

#include "src/request_body_processor/json_instrumentation.h"
#include <jsoncons/json_cursor.hpp>
Expand Down Expand Up @@ -704,7 +704,7 @@ JsonParseResult parseDocumentWithJsoncons(const std::string &input,
std::chrono::steady_clock::now() - event_loop_start).count()));
};
const auto finish_with_event_loop = [&record_event_loop](
JsonParseResult result) {
const JsonParseResult &result) {
record_event_loop();
return result;
};
Expand All @@ -717,17 +717,19 @@ JsonParseResult parseDocumentWithJsoncons(const std::string &input,
cursor.current(), cursor.context()); !result.ok()) {
#ifdef MSC_JSON_AUDIT_INSTRUMENTATION
return finish_with_event_loop(result);
#endif
#else
return result;
#endif
}

cursor.next(error);
if (error) {
#ifdef MSC_JSON_AUDIT_INSTRUMENTATION
return finish_with_event_loop(
fromJsonconsError(error, cursor.context()));
#endif
#else
return fromJsonconsError(error, cursor.context());
#endif
}
}

Expand All @@ -736,8 +738,9 @@ JsonParseResult parseDocumentWithJsoncons(const std::string &input,
#ifdef MSC_JSON_AUDIT_INSTRUMENTATION
return finish_with_event_loop(fromJsonconsError(error,
cursor.context()));
#endif
#else
return fromJsonconsError(error, cursor.context());
#endif
}

#ifdef MSC_JSON_AUDIT_INSTRUMENTATION
Expand Down
7 changes: 4 additions & 3 deletions src/request_body_processor/json_backend_simdjson.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <algorithm>
#include <chrono>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <string>
Expand Down Expand Up @@ -107,12 +108,12 @@ simdjson::ondemand::parser &getReusableSimdjsonParser() {
if (parser == nullptr) {
#ifdef MSC_JSON_AUDIT_INSTRUMENTATION
const auto parser_start = std::chrono::steady_clock::now();
parser.reset(new simdjson::ondemand::parser());
parser = std::make_unique<simdjson::ondemand::parser>();
recordSimdjsonParserConstruction(static_cast<std::uint64_t>(
std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::steady_clock::now() - parser_start).count()));
#else
parser.reset(new simdjson::ondemand::parser());
parser = std::make_unique<simdjson::ondemand::parser>();
#endif
}
return *parser;
Expand Down Expand Up @@ -398,7 +399,7 @@ class JsonBackendWalker {
"handling a boolean");
}

JsonParseResult enforceTechnicalDepth(simdjson::ondemand::value value) {
JsonParseResult enforceTechnicalDepth(simdjson::ondemand::value value) const {
const int32_t current_depth = value.current_depth();
if (current_depth <= 0) {
return makeResult(JsonParseStatus::InternalError,
Expand Down
2 changes: 2 additions & 0 deletions src/request_body_processor/json_instrumentation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "src/request_body_processor/json_instrumentation.h"

#include <chrono>
#include <cstddef>
#include <cstdint>

namespace modsecurity::RequestBodyProcessor {
namespace {
Expand Down
1 change: 1 addition & 0 deletions src/request_body_processor/multipart.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include "src/request_body_processor/multipart.h"

#include <cstddef>
#include <time.h>
#include <stdio.h>
#include <string.h>
Expand Down
3 changes: 3 additions & 0 deletions src/request_body_processor/multipart.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@
*
*/

#include <cstddef>
#include <memory>
#include <string>
#include <iostream>
#include <list>
#include <unordered_map>
#include <utility>
#include <vector>

#ifndef SRC_REQUEST_BODY_PROCESSOR_MULTIPART_H_
#define SRC_REQUEST_BODY_PROCESSOR_MULTIPART_H_
Expand Down
Loading