viewcontroller 在 loadHTMLString baseURL 方法中使用 NULL baseURL 参数:数据定理

viewcontroller using a NULL baseURL argument with the loadHTMLString baseURL method : data theorem

我遇到了问题"MyViewcontroller using a NULL baseURL argument with the loadHTMLString baseURL method : data theorem"- 我已经成功完成了我的任务并且一切正常。

问题出在 OSWAP 安全漏洞扫描中,它显示了上述错误。

我的代码片段:-

  NSString *aHtmlString = kEmptyString;

    // Getting the bool from configuration plist
    NSString *thePlistPath = [[NSBundle mainBundle] pathForResource:@"config" ofType:@"plist"];
    NSDictionary *theURLdata = [[NSDictionary alloc] initWithContentsOfFile:thePlistPath];
    is

ServerFAQAvailable = [[theURLdata valueForKey:kIsServerFAQAvailableKey] boolValue];

if (one || two || three) {
   aHtmlString = [self loadFAQFor];
} else {
  aHtmlString = [self loadFAQForwithout];
}
NSURL *baseURL = [NSURL fileURLWithPath:thePlistPath];

[self.faqWebView loadHTMLString:aHtmlString baseURL:baseURL]; 

更新:

if (one || two || three) {
       aHtmlString = [self loadFAQFor];
    } else {
      aHtmlString = [self loadFAQForwithout];
    }
    NSURL *baseURL = [NSURL fileURLWithPath:@"about:blank"];

    [self.faqWebView loadHTMLString:aHtmlString baseURL:baseURL];

仍然显示扫描问题

问题出在 baseURL: 参数上。 html 字符串不需要 BaseURL,它通常用于相对链接。如果您只想显示一些 html,您确定需要它吗?

标记的安全问题是有道理的(我的理解,大致):如果将 webview 的 baseURL 设置为本地文件系统,则(最终)通过该 webview 加载的页面可以访问本地资源。

尝试为 baseURL: 传递 nil 应该消除此警告。

baseURL 应该是[[NSBunld mainBunld] bunldPath],你可以这样试试..

NSString *path = [[NSBundle mainBundle]bundlePath];
NSString *htmlPath = [[NSBundle mainBundle] pathForResource:self.htmlName ofType:@"html"];
NSString *htmlContent = [NSString stringWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error:nil];
[self.webView loadHTMLString:htmlContent baseURL:[NSURL fileURLWithPath:path]];