From 84b617567f61e1790ac45577411de9dd98e52fff Mon Sep 17 00:00:00 2001 From: Igor Unanua Date: Tue, 5 Mar 2024 13:48:05 +0100 Subject: [PATCH] Replace obj.GetPropertyNames() call with napi_get_all_property_names() --- src/convert.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/convert.cpp b/src/convert.cpp index 815fadf3..eb40f089 100644 --- a/src/convert.cpp +++ b/src/convert.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -84,7 +85,22 @@ ddwaf_object* to_ddwaf_object_object( } } - Napi::Array properties = obj.GetPropertyNames(); + + napi_value result; + napi_status status = napi_get_all_property_names(env, + obj, + napi_key_own_only, + napi_key_skip_symbols, + napi_key_keep_numbers, + &result); + + if ((status) != napi_ok) { + mlog("Error getting object properties"); + return nullptr; + } + + Napi::Array properties = Napi::Array(env, result); + uint32_t len = properties.Length(); if (lim && len > DDWAF_MAX_CONTAINER_SIZE) { len = DDWAF_MAX_CONTAINER_SIZE; @@ -103,11 +119,7 @@ ddwaf_object* to_ddwaf_object_object( for (uint32_t i = 0; i < len; ++i) { mlog("Getting properties"); Napi::Value keyV = properties.Get(i); - if (!obj.HasOwnProperty(keyV) || !keyV.IsString()) { - // We avoid inherited properties here. - // If the key is not a String, well this is weird - continue; - } + std::string key = keyV.ToString().Utf8Value(); Napi::Value valV = obj.Get(keyV); mlog("Looping into ToPWArgs");