diff --git a/frameworks/native/ability/native/ability_runtime/js_ui_ability.cpp b/frameworks/native/ability/native/ability_runtime/js_ui_ability.cpp index 2f959f60a0..4980846fcc 100644 --- a/frameworks/native/ability/native/ability_runtime/js_ui_ability.cpp +++ b/frameworks/native/ability/native/ability_runtime/js_ui_ability.cpp @@ -17,6 +17,7 @@ #include #include +#include #include "ability_business_error.h" #include "ability_delegator_registry.h" @@ -2611,6 +2612,16 @@ std::string ExtractBaseName(const std::string &path) } return path.substr(slashPos, dotPos - slashPos); } + +bool IsBlockedSkillKeyName(const std::string &name) +{ + static const std::unordered_set BLOCKED = { + "constructor", "__proto__", "__defineGetter__", "__defineSetter__", + "__lookupGetter__", "__lookupSetter__", "toString", "toLocaleString", + "valueOf", "hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable" + }; + return BLOCKED.count(name) > 0; +} } // namespace napi_value JsUIAbility::LoadSkillFunction( @@ -2651,6 +2662,11 @@ bool JsUIAbility::TryLoadSkillEntry(const std::string &srcEntry, const std::shared_ptr ¶m, napi_env env, napi_value &outJsObj, napi_value &method) { + if (IsBlockedSkillKeyName(param->functionName_)) { + TAG_LOGW(AAFwkTag::UIABILITY, "blocked skill function name:%{public}s", + param->functionName_.c_str()); + return false; + } std::string srcPath(param->moduleName_ + "/" + srcEntry); auto pos = srcPath.rfind('.'); if (pos == std::string::npos) { @@ -2699,6 +2715,10 @@ std::vector JsUIAbility::BuildSkillCallArgs(napi_env env, auto valStr = AppExecFwk::WantParams::GetStringByType(value, typeId); TAG_LOGI(AAFwkTag::UIABILITY, "skillArg key:%{public}s value:%{public}s", key.c_str(), valStr.c_str()); + if (IsBlockedSkillKeyName(key)) { + TAG_LOGW(AAFwkTag::UIABILITY, "skip blocked skillArg key:%{public}s", key.c_str()); + continue; + } napi_value keyName = nullptr; napi_create_string_utf8(env, key.c_str(), NAPI_AUTO_LENGTH, &keyName); bool hasOwn = false; diff --git a/frameworks/native/ability/native/js_service_extension.cpp b/frameworks/native/ability/native/js_service_extension.cpp index 7a42ea4ad6..d4b9cc15c1 100644 --- a/frameworks/native/ability/native/js_service_extension.cpp +++ b/frameworks/native/ability/native/js_service_extension.cpp @@ -15,6 +15,8 @@ #include "js_service_extension.h" +#include + #include "ability_business_error.h" #include "ability_handler.h" #include "ability_info.h" @@ -594,6 +596,16 @@ std::string ExtractBaseName(const std::string &path) } return path.substr(slashPos, dotPos - slashPos); } + +bool IsBlockedSkillKeyName(const std::string &name) +{ + static const std::unordered_set BLOCKED = { + "constructor", "__proto__", "__defineGetter__", "__defineSetter__", + "__lookupGetter__", "__lookupSetter__", "toString", "toLocaleString", + "valueOf", "hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable" + }; + return BLOCKED.count(name) > 0; +} } // namespace napi_value JsServiceExtension::LoadSkillFunction( @@ -634,6 +646,11 @@ bool JsServiceExtension::TryLoadSkillEntry(const std::string &srcEntry, const std::shared_ptr ¶m, napi_env env, napi_value &outJsObj, napi_value &method) { + if (IsBlockedSkillKeyName(param->functionName_)) { + TAG_LOGW(AAFwkTag::SERVICE_EXT, "blocked skill function name:%{public}s", + param->functionName_.c_str()); + return false; + } std::string srcPath(param->moduleName_ + "/" + srcEntry); auto pos = srcPath.rfind('.'); if (pos == std::string::npos) { @@ -682,6 +699,10 @@ std::vector JsServiceExtension::BuildSkillCallArgs(napi_env env, auto valStr = AppExecFwk::WantParams::GetStringByType(value, typeId); TAG_LOGI(AAFwkTag::SERVICE_EXT, "skillArg key:%{public}s value:%{public}s", key.c_str(), valStr.c_str()); + if (IsBlockedSkillKeyName(key)) { + TAG_LOGW(AAFwkTag::SERVICE_EXT, "skip blocked skillArg key:%{public}s", key.c_str()); + continue; + } napi_value keyName = nullptr; napi_create_string_utf8(env, key.c_str(), NAPI_AUTO_LENGTH, &keyName); bool hasOwn = false;