文档

打开 URL 判断逻辑

为了更好的保障打开 URL 时的 App 的安全性,可在容器调用相关 URL 之前对 URL 进行判断,如果打开的不是白名单内的 URL 则禁止调用。

建议在调用如下接口前进行 URL 判断:

public class MPNebula {
    /**
    * 启动在线 URL
    *
    * @param url 在线地址
    */
    public static void startUrl(String url);
    
    /**
    * 启动在线 URL
    *
    * @param url   在线地址
    * @param param 启动参数
    */
    public static void startUrl(String url, Bundle param);
}

// 创建page
public static final void openH5(String url) {
    if (TextUtils.isEmpty(url)) {
        return;
    }
    H5Service h5Service = LauncherApplicationAgent.getInstance().getMicroApplicationContext()
            .findServiceByInterface(H5Service.class.getName());
    H5Bundle bundle = new H5Bundle();
    Bundle param = new Bundle();
    // 打开的在线地址
    param.putString(H5Param.LONG_URL,url);
    bundle.setParams(param);
    if (h5Service != null) {
        // 同步创建api
        H5Page h5Page=h5Service.createPage(activity,bundle);
        
        // 异步创建api
        h5Service.createPageAsync(activity, bundle, h5PageReadyListener);
    }
}
注意

URL 要进行精准匹配,至少要匹配到 URI 类的 scheme 和 host 信息,慎用或不用正则匹配,严格避免使用 contains、startsWith、endsWith、indexOf 等不精准函数。

  • 本页导读 (0)
文档反馈