[Databuckets] Nested Databuckets Protections and Improvements (#4748)

* Check for valid JSON before using it

* Do not allow nested keys to set be set an expiration

* Prevent overwriting of existing object or array

* Nested deletion support

* Update data_bucket.cpp

* Test cases

* More test cases, fix

* Update databuckets.cpp

* Update databuckets.cpp

* Basic databucket tests

* Update databuckets.cpp

* Update databuckets.cpp
This commit is contained in:
Chris Miles
2025-03-04 13:16:21 -06:00
committed by GitHub
parent 3638d157b2
commit 0615864d51
8 changed files with 422 additions and 52 deletions
+3 -10
View File
@@ -45,18 +45,11 @@ struct LootStateData {
}
};
inline bool IsValidJson(const std::string& json) {
rapidjson::Document doc;
rapidjson::ParseResult result = doc.Parse(json.c_str());
return result;
}
inline void LoadLootStateData(Zone *zone, NPC *npc, const std::string &loot_data)
{
LootStateData l{};
if (!IsValidJson(loot_data)) {
if (!Strings::IsValidJson(loot_data)) {
LogZoneState("Invalid JSON data for NPC [{}]", npc->GetNPCTypeID());
return;
}
@@ -178,7 +171,7 @@ inline std::string GetLootSerialized(Corpse *c)
inline void LoadNPCEntityVariables(NPC *n, const std::string &entity_variables)
{
if (!IsValidJson(entity_variables)) {
if (!Strings::IsValidJson(entity_variables)) {
LogZoneState("Invalid JSON data for NPC [{}]", n->GetNPCTypeID());
return;
}
@@ -203,7 +196,7 @@ inline void LoadNPCEntityVariables(NPC *n, const std::string &entity_variables)
inline void LoadNPCBuffs(NPC *n, const std::string &buffs)
{
if (!IsValidJson(buffs)) {
if (!Strings::IsValidJson(buffs)) {
LogZoneState("Invalid JSON data for NPC [{}]", n->GetNPCTypeID());
return;
}