Description
The product uses a handler for a custom URL scheme, but it does not properly restrict which actors can invoke the handler using the scheme.
Mobile platforms and other architectures allow the use of custom URL schemes to facilitate communication between applications. In the case of iOS, this is the only method to do inter-application communication. The implementation is at the developer's discretion which may open security flaws in the application. An example could be potentially dangerous functionality such as modifying files through a custom URL scheme.
Potential Impact
Access Control, Other
Gain Privileges or Assume Identity, Varies by Context, Bypass Protection Mechanism
Demonstrative Examples
NSString *stringURL = @"appscheme://replaceFileText?file=incomingMessage.txt&text=hello";NSURL *url = [NSURL URLWithString:stringURL];[[UIApplication sharedApplication] openURL:url];- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {if (!url) {return NO;}NSString *action = [url host];if([action isEqualToString: @"replaceFileText"]) {NSDictionary *dict = [self parseQueryStringExampleFunction:[url query]];
//this function will write contents to a specified file
FileObject *objectFile = [self writeToFile:[dict objectForKey: @"file"] withText:[dict objectForKey: @"text"]];}return YES;}<iframe src="appscheme://replaceFileText?file=Bookmarks.dat&text=listOfMaliciousWebsites">// Android
@Overridepublic boolean shouldOverrideUrlLoading(WebView view, String url){
if (url.substring(0,14).equalsIgnoreCase("examplescheme:")){if(url.substring(14,25).equalsIgnoreCase("getUserInfo")){writeDataToView(view, UserData);return false;}else{return true;}}
}// iOS
-(BOOL) webView:(UIWebView *)exWebView shouldStartLoadWithRequest:(NSURLRequest *)exRequest navigationType:(UIWebViewNavigationType)exNavigationType{
NSURL *URL = [exRequest URL];if ([[URL scheme] isEqualToString:@"exampleScheme"]){
NSString *functionString = [URL resourceSpecifier];if ([functionString hasPrefix:@"specialFunction"]){
// Make data available back in webview.
UIWebView *webView = [self writeDataToView:[URL query]];
}return NO;
}return YES;
}window.location = examplescheme://method?parameter=valueMitigations & Prevention
Utilize a user prompt pop-up to authorize potentially harmful actions such as those modifying data or dealing with sensitive information. When designing functionality of actions in the URL scheme, consider whether the action should be accessible to all mobile applications, or if an allowlist of applications to interface with is appropriate.
Detection Methods
- Automated Static Analysis — Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then sea
Real-World CVE Examples
| CVE ID | Description |
|---|---|
| CVE-2013-5725 | URL scheme has action replace which requires no user prompt and allows remote attackers to perform undesired actions. |
| CVE-2013-5726 | URL scheme has action follow and favorite which allows remote attackers to force user to perform undesired actions. |
Related Weaknesses
Frequently Asked Questions
What is CWE-939?
CWE-939 (Improper Authorization in Handler for Custom URL Scheme) is a software weakness identified by MITRE's Common Weakness Enumeration. It is classified as a Base-level weakness. The product uses a handler for a custom URL scheme, but it does not properly restrict which actors can invoke the handler using the scheme.
How can CWE-939 be exploited?
Attackers can exploit CWE-939 (Improper Authorization in Handler for Custom URL Scheme) to gain privileges or assume identity, varies by context, bypass protection mechanism. This weakness is typically introduced during the Implementation phase of software development.
How do I prevent CWE-939?
Key mitigations include: Utilize a user prompt pop-up to authorize potentially harmful actions such as those modifying data or dealing with sensitive information. When designing functionality of actions in
What is the severity of CWE-939?
CWE-939 is classified as a Base-level weakness (Medium abstraction). It has been observed in 2 real-world CVEs.