# VNX-939: Improper Authorization in Handler for Custom URL Scheme

Reports an Android deep-link URI (or a query parameter or path segment read from it) passed to a WebView load.

| Field | Value |
|---|---|
| Rule ID | `VNX-939` |
| Severity | Medium |
| SARIF level | `warning` |
| Kind | `sast` |
| Languages | Java, Kotlin |
| CWE | [CWE-939](https://cwe.mitre.org/data/definitions/939.html) |
| CAPEC | [CAPEC-66](https://capec.mitre.org/data/definitions/66.html) |
| ATT&CK | [T1190](https://attack.mitre.org/techniques/T1190/) |
| CWSS vector | `CWSS:1.0/TI:M/AP:RU/AL:S/IC:N/FC:LT/RP:RU/RL:S/AV:L/AS:N/IN:A/SC:A/BI:M/DI:H/EX:M/EC:N/P:C` |
| Tags | `deeplink` `android` `cwe-939` |
| Source | [`internal/sast/rules/vnx-939.rego`](https://github.com/Vulnesis/cli/blob/main/internal/sast/rules/vnx-939.rego) |

## Overview

VNX-939 maps to [CWE-939: Improper Authorization in Handler for Custom URL Scheme](https://cwe.mitre.org/data/definitions/939.html). Any installed app or any web page can open a custom-scheme (`myapp://`) or app link, so the URI an Activity receives is chosen by an attacker. A handler that loads it into a WebView, turns it into an Intent, or picks the component to launch from it lets that attacker drive the app.

## What gets flagged

```java
webView.loadUrl(getIntent().getDataString());          // flagged

Uri data = getIntent().getData();
String cls = data.getQueryParameter("screen");
i.setClassName(this, cls);                              // flagged
```

```kotlin
val next = intent?.data?.getQueryParameter("next")
val launch = Intent.parseUri(next, Intent.URI_INTENT_SCHEME)   // flagged
```

Not flagged: a link whose scheme or host is checked first (`getHost()`, `link.host != ...`, `startsWith`, an allowlist or validator call), constant URLs and class names, intent string extras (VNX-ANDROID-002), test code, comments and string literals. Flows across methods or files are not followed, and the manifest's intent-filter is not read.

## Remediation

Check the scheme and host against an allowlist before acting on the link, and map path values to known screens rather than passing them to `setClassName` or `Intent.parseUri`:

```java
Uri uri = getIntent().getData();
if (uri == null || !"https".equals(uri.getScheme()) || !ALLOWED_HOSTS.contains(uri.getHost())) {
    finish();
    return;
}
webView.loadUrl(uri.toString());
```

## References

- [CWE-939: Improper Authorization in Handler for Custom URL Scheme](https://cwe.mitre.org/data/definitions/939.html)
- [Android: Verify Android App Links](https://developer.android.com/training/app-links/verify-android-applinks)

## Suppressing this rule

Put a `nosec` comment on the line, or on line 1 to cover the whole file. Use the comment marker of the file's language (`#`, `//`, `--` or `;`):

```text
# nosec vnx-939
// nosec vnx-939
```

Or record an ignore rule: `vulnetix ignore add --rule vnx-939 --reason "..."`. See [Suppressing findings](/sast/guides/suppressing-findings.md).
