文档

打开 URL 判断逻辑

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

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

// 判断打开的 URL 是否在白名单内
NSString *urlWhiteList = @"xxxx";
NSURL *url = [NSURL URLWithString:@"https://example.com/products/xxx"];
if (![url.host isEqualToString:urlWhiteList]) {
    return;
}

// 打开在线 URL
[[MPNebulaAdapterInterface shareInstance] startH5ViewControllerWithParams:@{@"url": @"https://example.com/products/xxx"}];

// 基于 URL 创建 vc
MPH5WebViewController *vc = (MPH5WebViewController *)[[MPNebulaAdapterInterface shareInstance] createH5ViewController:@{@"url":@"https://example.com/products/xxx"}];
重要

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

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