{"@ID": "939", "@Name": "Improper Authorization in Handler for Custom URL Scheme", "@Abstraction": "Base", "@Structure": "Simple", "@Status": "Incomplete", "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.", "Extended_Description": "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.", "Related_Weaknesses": {"Related_Weakness": [{"@Nature": "ChildOf", "@CWE_ID": "862", "@View_ID": "1000", "@Ordinal": "Primary"}, {"@Nature": "ChildOf", "@CWE_ID": "940", "@View_ID": "1000"}]}, "Weakness_Ordinalities": {"Weakness_Ordinality": {"Ordinality": "Primary"}}, "Applicable_Platforms": {"Technology": {"@Class": "Mobile", "@Prevalence": "Undetermined"}}, "Modes_Of_Introduction": {"Introduction": {"Phase": "Implementation", "Note": "REALIZATION: This weakness is caused during implementation of an architectural security tactic."}}, "Common_Consequences": {"Consequence": {"Scope": ["Access Control", "Other"], "Impact": ["Gain Privileges or Assume Identity", "Varies by Context", "Bypass Protection Mechanism"], "Note": "An attacker can access any functionality that is inadvertently accessible to the source."}}, "Detection_Methods": {"Detection_Method": {"@Detection_Method_ID": "DM-14", "Method": "Automated Static Analysis", "Description": "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 searching for potentially-vulnerable patterns that connect \"sources\" (origins of input) with \"sinks\" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)"}}, "Potential_Mitigations": {"Mitigation": {"Phase": "Architecture and Design", "Description": {"xhtml:p": ["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."]}}}, "Demonstrative_Examples": {"Demonstrative_Example": [{"Intro_Text": "This iOS application uses a custom URL scheme. The replaceFileText action in the URL scheme allows an external application to interface with the file incomingMessage.txt and replace the contents with the text field of the query string.", "Body_Text": ["External Application", "Application URL Handler", "The handler has no restriction on who can use its functionality. The handler can be invoked using any method that invokes the URL handler such as the following malicious iframe embedded on a web page opened by Safari.", "The attacker can host a malicious website containing the iframe and trick users into going to the site via a crafted phishing email. Since Safari automatically executes iframes, the user is not prompted when the handler executes the iframe code which automatically invokes the URL handler replacing the bookmarks file with a list of malicious websites. Since replaceFileText is a potentially dangerous action, an action that modifies data, there should be a sanity check before the writeToFile:withText: function."], "Example_Code": [{"@Nature": "Good", "@Language": "Objective-C", "xhtml:div": {"xhtml:br": [null, null], "#text": "NSString *stringURL = @\"appscheme://replaceFileText?file=incomingMessage.txt&text=hello\";NSURL *url = [NSURL URLWithString:stringURL];[[UIApplication sharedApplication] openURL:url];"}}, {"@Nature": "Bad", "@Language": "Objective-C", "xhtml:div": {"xhtml:br": null, "xhtml:div": {"@style": "margin-left:1em;", "xhtml:div": [{"@style": "margin-left:1em;", "#text": "return NO;"}, {"@style": "margin-left:1em;", "xhtml:br": [null, null], "xhtml:i": "//this function will write contents to a specified file", "#text": "NSDictionary *dict = [self parseQueryStringExampleFunction:[url query]];\n                           \n                           FileObject *objectFile = [self writeToFile:[dict objectForKey: @\"file\"] withText:[dict objectForKey: @\"text\"]];"}], "xhtml:br": [null, null, null], "#text": "if (!url) {}NSString *action = [url host];if([action isEqualToString: @\"replaceFileText\"]) {}return YES;"}, "#text": "- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {}"}}, {"@Nature": "Attack", "@Language": "HTML", "xhtml:div": "<iframe src=\"appscheme://replaceFileText?file=Bookmarks.dat&text=listOfMaliciousWebsites\">"}]}, {"@Demonstrative_Example_ID": "DX-109", "Intro_Text": "These Android and iOS applications intercept URL loading within a WebView and perform special actions if a particular URL scheme is used, thus allowing the Javascript within the WebView to communicate with the application:", "Example_Code": [{"@Nature": "Bad", "@Language": "Java", "xhtml:div": {"xhtml:i": "// Android", "xhtml:br": [null, null], "xhtml:div": {"@style": "margin-left:1em;", "xhtml:div": {"xhtml:div": {"@style": "margin-left:1em;", "xhtml:div": [{"@style": "margin-left:1em;", "xhtml:br": null, "#text": "writeDataToView(view, UserData);return false;"}, {"@style": "margin-left:1em;", "#text": "return true;"}], "xhtml:br": null, "#text": "if(url.substring(14,25).equalsIgnoreCase(\"getUserInfo\")){}else{}"}, "#text": "if (url.substring(0,14).equalsIgnoreCase(\"examplescheme:\")){}"}}, "#text": "@Overridepublic boolean shouldOverrideUrlLoading(WebView view, String url){}"}}, {"@Nature": "Bad", "@Language": "Objective-C", "xhtml:div": {"xhtml:i": "// iOS", "xhtml:br": [null, null], "xhtml:div": {"@style": "margin-left:1em;", "xhtml:div": {"xhtml:br": [null, null, null], "xhtml:div": {"@style": "margin-left:1em;", "xhtml:div": {"xhtml:br": [null, null, null], "xhtml:div": {"@style": "margin-left:1em;", "xhtml:div": {"xhtml:br": [null, null], "xhtml:i": "// Make data available back in webview.", "#text": "UIWebView *webView = [self writeDataToView:[URL query]];"}}, "#text": "NSString *functionString = [URL resourceSpecifier];if ([functionString hasPrefix:@\"specialFunction\"]){}return NO;"}}, "#text": "NSURL *URL = [exRequest URL];if ([[URL scheme] isEqualToString:@\"exampleScheme\"]){}return YES;"}}, "#text": "-(BOOL) webView:(UIWebView *)exWebView shouldStartLoadWithRequest:(NSURLRequest *)exRequest navigationType:(UIWebViewNavigationType)exNavigationType{}"}}, {"@Nature": "Attack", "@Language": "JavaScript", "xhtml:div": "window.location = examplescheme://method?parameter=value"}], "Body_Text": ["A call into native code can then be initiated by passing parameters within the URL:", "Because the application does not check the source, a malicious website loaded within this WebView has the same access to the API as a trusted site."]}]}, "Observed_Examples": {"Observed_Example": [{"Reference": "CVE-2013-5725", "Description": "URL scheme has action replace which requires no user prompt and allows remote attackers to perform undesired actions.", "Link": "https://www.cve.org/CVERecord?id=CVE-2013-5725"}, {"Reference": "CVE-2013-5726", "Description": "URL scheme has action follow and favorite which allows remote attackers to force user to perform undesired actions.", "Link": "https://www.cve.org/CVERecord?id=CVE-2013-5726"}]}, "References": {"Reference": {"@External_Reference_ID": "REF-938"}}, "Mapping_Notes": {"Usage": "Allowed", "Rationale": "This CWE entry is at the Base level of abstraction, which is a preferred level of abstraction for mapping to the root causes of vulnerabilities.", "Comments": "Carefully read both the name and description to ensure that this mapping is an appropriate fit. Do not try to 'force' a mapping to a lower-level Base/Variant simply to comply with this preferred level of abstraction.", "Reasons": {"Reason": {"@Type": "Acceptable-Use"}}}, "Content_History": {"Submission": {"Submission_Name": "CWE Content Team", "Submission_Organization": "MITRE", "Submission_Date": "2014-01-14", "Submission_Version": "2.6", "Submission_ReleaseDate": "2014-02-19"}, "Modification": [{"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2017-01-19", "Modification_Version": "2.10", "Modification_ReleaseDate": "2017-01-19", "Modification_Comment": "updated Relationships"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2017-11-08", "Modification_Version": "3.0", "Modification_ReleaseDate": "2017-11-08", "Modification_Comment": "updated Modes_of_Introduction, References, Relationships"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2020-02-24", "Modification_Version": "4.0", "Modification_ReleaseDate": "2020-02-24", "Modification_Comment": "updated Applicable_Platforms, Relationships"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2020-06-25", "Modification_Version": "4.1", "Modification_ReleaseDate": "2020-06-25", "Modification_Comment": "updated Potential_Mitigations"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2021-03-15", "Modification_Version": "4.4", "Modification_ReleaseDate": "2021-03-15", "Modification_Comment": "updated Demonstrative_Examples"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2023-01-31", "Modification_Version": "4.10", "Modification_ReleaseDate": "2023-01-31", "Modification_Comment": "updated Description"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2023-04-27", "Modification_Version": "4.11", "Modification_ReleaseDate": "2023-04-27", "Modification_Comment": "updated References, Relationships"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2023-06-29", "Modification_Version": "4.12", "Modification_ReleaseDate": "2023-06-29", "Modification_Comment": "updated Mapping_Notes"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2025-04-03", "Modification_Version": "4.17", "Modification_ReleaseDate": "2025-04-03", "Modification_Comment": "updated Demonstrative_Examples"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2025-12-11", "Modification_Version": "4.19", "Modification_ReleaseDate": "2025-12-11", "Modification_Comment": "updated Common_Consequences, Detection_Factors, Relationships, Weakness_Ordinalities"}]}}
