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

时间:2016-06-29 14:49:34

标签: ios objective-c iphone security uiwebview

我面临的问题是“MyViewcontroller使用带有loadHTMLString baseURL方法的NULL baseURL参数:数据定理” - 我已成功完成任务并且一切正常。

问题出在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];

仍然显示我的扫描问题

2 个答案:

答案 0 :(得分:5)

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

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

尝试为baseURL:传递nil应该保持此警告。

答案 1 :(得分:1)

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]];
相关问题