!19430 merge 523 into master

new cross user embeddedUI

Created-by: wlh2624_DS
Commit-by: wlh2624_DS
Merged-by: openharmony_ci
Description: **IssueNo**:
https://gitcode.com/openharmony/ability_ability_runtime/issues/15321

**Description**:

**稳定性自检:**
| 自检项                                                       | 自检结果  |
| ------------------------------------------------------------ | -------- |
| 涉及跨进程调用的相关操作需要抛至主线程或加锁防止并发              |          |
| 成员变量进行赋值或创建需要排查并发                               |          |
| 谨慎在lambda表达式中使用引用捕获                                |          |
| 谨慎在未经拷贝的情况下使用外部传入的string、C字符串               |          |
| map\vector\list\set等stl模板类使用时需要排查并发                |          |
| 谨慎考虑加锁范围                                               |          |
| 在IPC通信中谨慎使用同步通信方式                                 |          |
| 禁止传递this指针至其他模块或线程(特别是eventhandler任务)        |          |
| 禁止将外部传入的裸指针在内部直接构造智能指针                      |          |
| 禁止多个独立创建的智能指针管理同一地址                           |          |
| 禁止在析构函数中抛异步任务                                      |          |
| 禁止js对象在非js线程(例如在IPC线程)创建、使用或销毁             |          |
| 禁止在对外接口中未经判空直接使用外部传入的指针                    |          |
| 禁止接口返回局部变量引用                                        |          |
| 禁止在信号函数中加锁                                            |          |
| 禁止在关键流程(SA启动、应用启动等主流程)执行耗时的操作           |          |
| 禁止将同一个cpp编译在不同的so中                                 |          |

**安全编码自检:**
| 自检项                                                          | 自检结果 |
| -------------------------------------------------------------- | -------- |
| 裸指针避免通过隐式转换构造为sptr                                 |          |
| json对象在取值之前必须先判断类型,避免类型不匹配                   |          |
| 序列化时必须对传入的数组大小进行校验,避免出现超大数组              |          |
| 避免使用未明确位宽的整型,选择使用int8_t、uint8_t等类型            |          |
| 外部传入的路径要做规范化校验,对路径中的.、..、../等特殊字符严格校验 |          |
| 指针变量、表示资源描述符的变量、bool变量必须赋初值                  |          |
| readParcelable获取的对象使用前需要判空                            |          |
| 分配和释放内存的函数需要成对出现                                   |          |
| 申请内存后异常退出前需要及时进行内存释放                            |          |
| 内存申请前必须对内存大小进行合法性校验                              |          |
| 内存分配后必须判断是否成功                                         |          |
| 禁止使用realloc、alloca函数                                       |          |
| 禁止打印文件路径、口令等敏感信息,如有需要,使用private修饰          |          |
| 禁止打印内存地址                                                  |          |
| 整数之间运算时必须严格检查,确保不会出现溢出、反转、除0               |          |
| 禁止对有符号整数进行位操作符运算                                    |          |
| 禁止对指针进行逻辑或位运算                                         |          |
| 循环次数如果收外部数据控制,需要检验其合法性                         |          |
| 禁止使用内存操作类危险函数,需要使用安全函数                         |          |
| 谨慎使用不可重入函数                                               |          |
| 必须检查安全函数的返回值,并进行正确处理                             |          |
| 禁止仅通过TokenType类型判断绕过权限校验                             |          |

**TDD Result**:

**XTS Result**:

### 是否已执行L0用例
- [ ] 已验证
- [ ] 不涉及。如不涉及,请写明理由


See merge request: openharmony/ability_ability_runtime!19430
This commit is contained in:
openharmony_ci
2026-05-26 23:22:37 +08:00
19 changed files with 159 additions and 24 deletions
@@ -34,6 +34,11 @@ public:
private:
void CreateDebugRecord(
const AAFwk::AbilityRequest &abilityRequest, std::shared_ptr<AAFwk::BaseExtensionRecord> abilityRecord);
int32_t EmbeddedUIPreCheck(const AAFwk::AbilityRequest &abilityRequest, const std::string &hostBundleName);
bool CheckAllowCrossUserEmbeddedUI(const AAFwk::AbilityRequest &abilityRequest, const std::string &hostBundleName);
int32_t CheckHostBundleName(const AAFwk::AbilityRequest &abilityRequest, const std::string &hostBundleName);
bool IsInAllowList(const std::vector<AppExecFwk::ExtensionAbilityInfo> &extensionInfos,
const std::string &extensionName, const std::string &callerAppIdentifier);
};
} // namespace AbilityRuntime
} // namespace OHOS
@@ -75,29 +75,7 @@ int32_t ExtensionRecordFactory::PreCheck(const AAFwk::AbilityRequest &abilityReq
if (preCheckFlag == 0) {
return ERR_OK;
}
if ((preCheckFlag & PRE_CHECK_FLAG_CALLED_WITHIN_THE_BUNDLE) &&
hostBundleName != AbilityConfig::SCENEBOARD_BUNDLE_NAME) {
if (hostBundleName != abilityRequest.abilityInfo.applicationName) {
if (abilityRequest.isTargetPlugin && abilityRequest.hostBundleName == hostBundleName &&
abilityRequest.abilityInfo.extensionAbilityType == ExtensionAbilityType::EMBEDDED_UI) {
return ERR_OK;
}
TAG_LOGW(AAFwkTag::ABILITYMGR, "not called");
return ERR_INVALID_VALUE;
}
// There may exist preload extension, the session info is nullptr
if (abilityRequest.sessionInfo != nullptr) {
auto callerToken = abilityRequest.sessionInfo->callerToken;
auto callerAbilityRecord = AAFwk::Token::GetAbilityRecordByToken(callerToken);
CHECK_POINTER_AND_RETURN(callerAbilityRecord, ERR_INVALID_VALUE);
AppExecFwk::AbilityInfo abilityInfo = callerAbilityRecord->GetAbilityInfo();
if (abilityInfo.type != AbilityType::PAGE) {
TAG_LOGW(AAFwkTag::ABILITYMGR, "not UIAbility");
return ERR_INVALID_VALUE;
}
}
}
if (preCheckFlag & PRE_CHECK_FLAG_MULTIPLE_PROCESSES) {
if (!AppUtils::GetInstance().IsMultiProcessModel()) {
TAG_LOGW(AAFwkTag::ABILITYMGR, "not multi process model");
@@ -18,6 +18,8 @@
#include "hilog_tag_wrapper.h"
#include "multi_instance_utils.h"
#include "ui_extension_record.h"
#include "permission_verification.h"
#include "ability_util.h"
namespace OHOS {
namespace AbilityRuntime {
@@ -47,10 +49,118 @@ bool UIExtensionRecordFactory::NeedReuse(const AAFwk::AbilityRequest &abilityReq
return true;
}
bool UIExtensionRecordFactory::IsInAllowList(const std::vector<AppExecFwk::ExtensionAbilityInfo> &extensionInfos,
const std::string &extensionName, const std::string &callerAppIdentifier)
{
for (const AppExecFwk::ExtensionAbilityInfo &info : extensionInfos) {
if (info.type == AppExecFwk::ExtensionAbilityType::EMBEDDED_UI && info.name == extensionName) {
auto it = std::find_if(info.appIdentifierAllowList.begin(),
info.appIdentifierAllowList.end(),
[callerAppIdentifier](const std::string &allowAppId) {
return allowAppId == callerAppIdentifier || allowAppId == "allow_all";
});
return it != info.appIdentifierAllowList.end();
}
}
return false;
}
bool UIExtensionRecordFactory::CheckAllowCrossUserEmbeddedUI(
const AAFwk::AbilityRequest &abilityRequest, const std::string &hostBundleName)
{
if (!AAFwk::PermissionVerification::GetInstance()->VerifySupportCrossAppEmbedForOaPermission()) {
TAG_LOGD(AAFwkTag::ABILITYMGR, "no permission to cross user embeddedUI");
return false;
}
auto bms = AAFwk::AbilityUtil::GetBundleManagerHelper();
CHECK_POINTER_AND_RETURN(bms, false);
std::string callerAppIdentifier = abilityRequest.want.GetStringParam(AAFwk::Want::PARAM_RESV_CALLER_APP_IDENTIFIER);
if (callerAppIdentifier.empty()) {
AppExecFwk::SignatureInfo signatureInfo;
if (IN_PROCESS_CALL(bms->GetSignatureInfoByBundleName(hostBundleName, signatureInfo)) != ERR_OK) {
TAG_LOGE(AAFwkTag::ABILITYMGR,
"bms GetSignatureInfoByBundleName error, bundleName: %{public}s",
hostBundleName.c_str());
return false;
};
callerAppIdentifier = signatureInfo.appIdentifier;
}
AppExecFwk::BundleInfo targetBundleInfo;
std::string targetBundleName = abilityRequest.abilityInfo.bundleName;
if (!IN_PROCESS_CALL(bms->GetBundleInfo(targetBundleName,
AppExecFwk::BundleFlag::GET_BUNDLE_WITH_EXTENSION_INFO,
targetBundleInfo,
abilityRequest.userId))) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "bms GetBundleInfo error, BundleFlag: GET_BUNDLE_WITH_EXTENSION_INFO");
return false;
}
if (IsInAllowList(targetBundleInfo.extensionInfos, abilityRequest.abilityInfo.name, callerAppIdentifier)) {
TAG_LOGI(AAFwkTag::ABILITYMGR, "allow cross user embeddedUI bundleName:%{public}s", hostBundleName.c_str());
return true;
}
return false;
}
int32_t UIExtensionRecordFactory::CheckHostBundleName(
const AAFwk::AbilityRequest &abilityRequest, const std::string &hostBundleName)
{
if (hostBundleName == abilityRequest.abilityInfo.applicationName ||
CheckAllowCrossUserEmbeddedUI(abilityRequest, hostBundleName) ||
(abilityRequest.isTargetPlugin && abilityRequest.hostBundleName == hostBundleName)) {
return ERR_OK;
}
TAG_LOGW(AAFwkTag::ABILITYMGR, "not called");
return ERR_INVALID_VALUE;
}
int32_t UIExtensionRecordFactory::EmbeddedUIPreCheck(
const AAFwk::AbilityRequest &abilityRequest, const std::string &hostBundleName)
{
if (hostBundleName == AAFwk::AbilityConfig::SCENEBOARD_BUNDLE_NAME) {
return ERR_OK;
}
auto result = CheckHostBundleName(abilityRequest, hostBundleName);
if (result != ERR_OK) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "PreCheck error:%{public}d", result);
return result;
}
// There may exist preload extension, the session info is nullptr
if (abilityRequest.sessionInfo != nullptr) {
auto callerToken = abilityRequest.sessionInfo->callerToken;
auto callerAbilityRecord = AAFwk::Token::GetAbilityRecordByToken(callerToken);
CHECK_POINTER_AND_RETURN(callerAbilityRecord, ERR_INVALID_VALUE);
AppExecFwk::AbilityInfo abilityInfo = callerAbilityRecord->GetAbilityInfo();
if (abilityInfo.type != AppExecFwk::AbilityType::PAGE) {
TAG_LOGW(AAFwkTag::ABILITYMGR, "not UIAbility");
return ERR_INVALID_VALUE;
}
}
return ERR_OK;
}
int32_t UIExtensionRecordFactory::PreCheck(
const AAFwk::AbilityRequest &abilityRequest, const std::string &hostBundleName)
{
return ExtensionRecordFactory::PreCheck(abilityRequest, hostBundleName);
auto result = ExtensionRecordFactory::PreCheck(abilityRequest, hostBundleName);
if (result != ERR_OK) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "PreCheck error:%{public}d", result);
return result;
}
if (abilityRequest.abilityInfo.extensionAbilityType == AppExecFwk::ExtensionAbilityType::EMBEDDED_UI) {
result = EmbeddedUIPreCheck(abilityRequest, hostBundleName);
if (result != ERR_OK) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "EmbeddedUIPreCheck error:%{public}d", result);
return result;
}
}
return ERR_OK;
}
int32_t UIExtensionRecordFactory::CreateRecord(
@@ -33,6 +33,7 @@ constexpr const char* PERMISSION_UPDATE_APP_CONFIGURATION = "ohos.permission.UPD
constexpr const char* PERMISSION_INSTALL_BUNDLE = "ohos.permission.INSTALL_BUNDLE";
constexpr const char* PERMISSION_LISTEN_BUNDLE_CHANGE = "ohos.permission.LISTEN_BUNDLE_CHANGE";
constexpr const char* PERMISSION_GET_BUNDLE_INFO_PRIVILEGED = "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED";
constexpr const char* PERMISSION_SUPPORT_CROSS_APP_EMBED_FOR_OA = "ohos.permission.SUPPORT_CROSS_APP_EMBED_FOR_OA";
constexpr const char* PERMISSION_START_INVISIBLE_ABILITY = "ohos.permission.START_INVISIBLE_ABILITY";
constexpr const char* PERMISSION_START_ABILITIES_FROM_BACKGROUND = "ohos.permission.START_ABILITIES_FROM_BACKGROUND";
constexpr const char* PERMISSION_START_ABILIIES_FROM_BACKGROUND = "ohos.permission.START_ABILIIES_FROM_BACKGROUND";
@@ -133,6 +133,7 @@ struct VerificationInfo {
bool VerifyCustomSandbox(uint32_t accessTokenId) const;
bool VerifySupportCrossAppEmbedForOaPermission() const;
private:
DISALLOW_COPY_AND_MOVE(PermissionVerification);
@@ -264,6 +264,16 @@ bool PermissionVerification::VerifyGetBundleInfoPrivilegedPermission() const
return false;
}
bool PermissionVerification::VerifySupportCrossAppEmbedForOaPermission() const
{
if (VerifyCallingPermission(PermissionConstants::PERMISSION_SUPPORT_CROSS_APP_EMBED_FOR_OA)) {
TAG_LOGI(AAFwkTag::DEFAULT,
"Permission %{public}s granted", PermissionConstants::PERMISSION_SUPPORT_CROSS_APP_EMBED_FOR_OA);
return true;
}
return false;
}
bool PermissionVerification::VerifyStartRecentAbilityPermission() const
{
if (VerifyCallingPermission(PermissionConstants::PERMISSION_START_RECENT_ABILITY)) {
@@ -69,11 +69,13 @@ ohos_fuzztest("ExtensionRecordManagerFuzzTest") {
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_native_path}/appkit:appkit_manager_helper",
"${ability_runtime_path}/utils/global/common:runtime_utils",
"${ability_runtime_path}/utils/server/startup:startup_util",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"${ability_runtime_services_path}/common:task_handler_wrap",
"${ability_runtime_services_path}/common:hisysevent_report",
"${ability_runtime_services_path}/common:perm_verification",
]
external_deps = [
@@ -68,11 +68,13 @@ ohos_fuzztest("ExtensionRecordManageraFuzzTest") {
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_native_path}/appkit:appkit_manager_helper",
"${ability_runtime_path}/utils/global/common:runtime_utils",
"${ability_runtime_path}/utils/server/startup:startup_util",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"${ability_runtime_services_path}/common:task_handler_wrap",
"${ability_runtime_services_path}/common:hisysevent_report",
"${ability_runtime_services_path}/common:perm_verification",
]
external_deps = [
@@ -71,11 +71,13 @@ ohos_fuzztest("ExtensionRecordManagerbFuzzTest") {
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_native_path}/appkit:appkit_manager_helper",
"${ability_runtime_path}/utils/global/common:runtime_utils",
"${ability_runtime_path}/utils/server/startup:startup_util",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"${ability_runtime_services_path}/common:task_handler_wrap",
"${ability_runtime_services_path}/common:hisysevent_report",
"${ability_runtime_services_path}/common:perm_verification",
]
external_deps = [
@@ -71,11 +71,13 @@ ohos_fuzztest("ExtensionRecordManagercFuzzTest") {
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_native_path}/appkit:appkit_manager_helper",
"${ability_runtime_path}/utils/global/common:runtime_utils",
"${ability_runtime_path}/utils/server/startup:startup_util",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"${ability_runtime_services_path}/common:task_handler_wrap",
"${ability_runtime_services_path}/common:hisysevent_report",
"${ability_runtime_services_path}/common:perm_verification",
]
external_deps = [
@@ -53,7 +53,9 @@ ohos_fuzztest("UIExtensionRecordFactoryFuzzTest") {
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_native_path}/appkit:appkit_manager_helper",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"${ability_runtime_services_path}/common:perm_verification",
]
external_deps = [
@@ -312,5 +312,10 @@ int PermissionVerification::CheckCallModularObjectExtensionPermission(
{
return ERR_OK;
}
bool PermissionVerification::VerifySupportCrossAppEmbedForOaPermission() const
{
return true;
}
} // namespace AAFwk
} // namespace OHOS
@@ -313,5 +313,10 @@ int PermissionVerification::CheckCallModularObjectExtensionPermission(
{
return ERR_OK;
}
bool PermissionVerification::VerifySupportCrossAppEmbedForOaPermission() const
{
return true;
}
} // namespace AAFwk
} // namespace OHOS
@@ -77,6 +77,7 @@ ohos_unittest("extension_record_manager_second_test") {
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_native_path}/appkit:appkit_manager_helper",
"${ability_runtime_path}/utils/global/common:runtime_utils",
"${ability_runtime_path}/utils/server/startup:startup_util",
"${ability_runtime_services_path}/abilitymgr:abilityms",
@@ -93,7 +93,8 @@ public:
bool JudgeCallerIsAllowedToUseSystemAPI() const;
bool JudgeCallerIsAllowedToUseSystemAPIByTokenId(uint64_t specifiedFullTokenId) const;
bool IsSystemAppCall() const;
bool VerifySupportCrossAppEmbedForOaPermission() const;
};
} // namespace AAFwk
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_PERMISSION_VERIFICATION_H
#endif // OHOS_ABILITY_RUNTIME_PERMISSION_VERIFICATION_H
@@ -124,5 +124,9 @@ bool PermissionVerification::IsSystemAppCall() const
{
return true;
}
bool PermissionVerification::VerifySupportCrossAppEmbedForOaPermission() const
{
return true;
}
} // namespace AAFwk
} // namespace OHOS
@@ -68,9 +68,11 @@ ohos_unittest("extension_record_manager_test") {
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_native_path}/appkit:appkit_manager_helper",
"${ability_runtime_path}/utils/global/common:runtime_utils",
"${ability_runtime_path}/utils/server/startup:startup_util",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"${ability_runtime_services_path}/common:perm_verification",
]
external_deps = [
@@ -65,6 +65,7 @@ ohos_unittest("ui_extension_record_factory_test") {
"${ability_runtime_native_path}/ability/native:auto_startup_callback",
"${ability_runtime_native_path}/ability/native:ui_extension",
"${ability_runtime_native_path}/appkit:app_context",
"${ability_runtime_native_path}/appkit:appkit_manager_helper",
"${ability_runtime_native_path}/appkit:appkit_native",
"${ability_runtime_path}/utils/server/startup:startup_util",
"${ability_runtime_services_path}/abilitymgr:abilityms",
@@ -67,6 +67,7 @@ ohos_unittest("window_focus_changed_listener_test") {
"${ability_runtime_native_path}/ability/native:auto_startup_callback",
"${ability_runtime_native_path}/ability/native:ui_extension",
"${ability_runtime_native_path}/appkit:app_context",
"${ability_runtime_native_path}/appkit:appkit_manager_helper",
"${ability_runtime_native_path}/appkit:appkit_native",
"${ability_runtime_path}/utils/server/startup:startup_util",
"${ability_runtime_services_path}/abilitymgr:abilityms",