CWE-939 Base Incomplet

Improper Authorization in Handler for Custom URL Scheme

This vulnerability occurs when an app implements a custom URL scheme handler but fails to properly verify which other apps or sources are allowed to trigger it.

Définition

What is CWE-939?

This vulnerability occurs when an app implements a custom URL scheme handler but fails to properly verify which other apps or sources are allowed to trigger it.
Modern mobile and desktop platforms use custom URL schemes (like myapp://) as a bridge for apps to communicate and pass data. However, if the receiving app doesn't enforce strict authorization checks, any malicious or untrusted app on the same device can invoke this handler. This effectively creates an unintended public interface into your app's internal functions. Without proper validation, attackers can exploit this open handler to trigger dangerous actions. For example, a vulnerable handler might allow unauthorized file deletion, data export, or changes to app settings, simply by crafting a malicious URL. The security of the entire mechanism depends entirely on the developer implementing explicit checks to verify the calling source's identity and permissions.
Impact réel

Real-world CVEs caused by CWE-939

  • URL scheme has action replace which requires no user prompt and allows remote attackers to perform undesired actions.

  • URL scheme has action follow and favorite which allows remote attackers to force user to perform undesired actions.

Comment les attaquants l'exploitent

Parcours de l'attaquant étape par étape

  1. 1

    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.

  2. 2

    External Application

  3. 3

    Application URL Handler

  4. 4

    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.

  5. 5

    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.

Exemple de code vulnérable

Vulnerable Objective-C

Application URL Handler

Vulnérable Objective-C
- (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;}
Charge utile de l'attaquant

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.

Charge utile de l'attaquant HTML
<iframe src="appscheme://replaceFileText?file=Bookmarks.dat&text=listOfMaliciousWebsites">
Exemple de code sécurisé

Secure Objective-C

External Application

Sécurisé Objective-C
NSString *stringURL = @"appscheme://replaceFileText?file=incomingMessage.txt&text=hello";
  NSURL *url = [NSURL URLWithString:stringURL];
  [[UIApplication sharedApplication] openURL:url];
What changed: the unsafe sink is replaced (or the input is validated/escaped) so the same payload no longer triggers the weakness.
Liste de contrôle de prévention

How to prevent CWE-939

  • Architecture and Design 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.
Signaux de détection

How to detect CWE-939

SAST High

Exécuter une analyse statique (SAST) sur le code source à la recherche du motif non sécurisé dans le flux de données.

DAST Moderate

Exécuter des tests de sécurité applicative dynamique (DAST) contre le point de terminaison en ligne.

Runtime Moderate

Surveiller les journaux runtime pour détecter des traces d'exception inhabituelles, des entrées malformées ou des tentatives de contournement d'autorisation.

Code review Moderate

Revue de code : signaler tout nouveau code qui traite les entrées de cette surface sans utiliser les helpers du framework validés.

Correction automatique Plexicus

Plexicus détecte automatiquement CWE-939 et ouvre une PR de correction en moins de 60 secondes.

Codex Remedium analyse chaque commit, identifie cette faiblesse précise et livre une pull request prête à être relue avec le correctif. Pas de tickets. Pas de transferts.

Questions fréquentes

Frequently asked questions

Qu'est-ce que CWE-939 ?

This vulnerability occurs when an app implements a custom URL scheme handler but fails to properly verify which other apps or sources are allowed to trigger it.

Quelle est la gravité de CWE-939 ?

MITRE n'a pas publié de note de probabilité d'exploitation pour cette faiblesse. Traitez-la comme un impact moyen jusqu'à ce que votre modèle de menace prouve le contraire.

Quels langages ou plateformes sont affectés par CWE-939 ?

MITRE lists the following affected platforms: Mobile.

Comment puis-je prévenir CWE-939 ?

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.

Comment Plexicus détecte et corrige CWE-939 ?

Le moteur SAST de Plexicus reconnaît la signature de flux de données de CWE-939 à chaque commit. Lorsqu'une correspondance est trouvée, notre agent Codex Remedium ouvre une PR de correction avec le code corrigé, les tests et un résumé d'une ligne pour le relecteur.

Où puis-je en savoir plus sur CWE-939 ?

MITRE publie la définition canonique à https://cwe.mitre.org/data/definitions/939.html. Vous pouvez également consulter la documentation OWASP et NIST pour des conseils adjacents.

Prêt quand vous l'êtes

Arrêtez de payer par développeur.
Commencez à fermer la boucle.

Plexicus est l'ASPM natif IA qui scanne, filtre, corrige, penteste et explique — de façon autonome. Développeurs illimités, dépôts illimités, actions IA à usage équitable. Vrai niveau gratuit, €269/mo annuel quand vous êtes prêt.