Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CodeQL - Unsafe WebView fetch #9

Open
sgasurion opened this issue Aug 1, 2024 · 0 comments
Open

CodeQL - Unsafe WebView fetch #9

sgasurion opened this issue Aug 1, 2024 · 0 comments

Comments

@sgasurion
Copy link

Hi Team,

We've been running CodeQL scans regularly on our code base and have encountered an issue that I believe needs attention from the maintainers.

Problem

During our latest scan, CodeQL flagged an issue in file Vault/Pods/Elephant/Sources/SVGView.swift at line number 37 with the following reason & description :

CodeQL

Vault/Pods/Elephant/Sources/SVGView.swift:37
Unsafe WebView fetch
Tainted data is used in a WebView fetch without restricting the base URL.

Fetching data in a web view without restricting the base URL may allow an attacker to access sensitive local data, for example using file://. Data can then be extracted from the software using the URL of a machine under the attacker's control. More generally, an attacker may use a URL under their control as part of a cross-site scripting attack.

Recommendation

When loading HTML into a web view, always set the baseURL to an appropriate URL that you control, or to about:blank. Do not use nil, as this does not restrict URLs that can be resolved. Also do not use a baseURL that could itself be controlled by an attacker.

Example

In the following example, a call to UIWebView.loadHTMLString has the baseURL set to nil, which does not restrict URLs that can be resolved from within the web page.

 let webview = UIWebView()
 ... 
 webview.loadHTMLString(htmlData, baseURL: nil) // BAD

To fix the problem, we set the baseURL to about:blank. This ensures that an attacker cannot resolve URLs that point to the local file system, or to web servers under their control.

 let webview = UIWebView()
 ...
 webview.loadHTMLString(htmlData, baseURL: URL(string: "about:blank")) // GOOD

References

iOS Bug Hunting - Web View XSS.
Common Weakness Enumeration: CWE-79.
Common Weakness Enumeration: CWE-95.
Common Weakness Enumeration: CWE-749.

This issue needs to be addressed to prevent it from being flagged in future scans.

Request:

Could the Team please review this issue. Our goal is to ensure that this particular CodeQL scan issue is resolved in upcoming scans to provide more security on the codebase.

Additional Information

We are using the cocoapod dependency manager for using Elephant with version-> 'Elephant', '0.1.0'

Thank you for your attention to this matter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant