# VNX-573: Remote URL read through an API that cannot set a timeout

Reports Java and Kotlin reads of a remote URL through openStream(), readText(), IOUtils/Resources helpers, ImageIO.read(url) or two-argument copyURLToFile.

| Field | Value |
|---|---|
| Rule ID | `VNX-573` |
| Severity | Medium |
| SARIF level | `warning` |
| Kind | `sast` |
| Languages | Java, Kotlin |
| CWE | [CWE-573](https://cwe.mitre.org/data/definitions/573.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:A/AL:A/IC:N/FC:LT/RP:N/RL:A/AV:I/AS:N/IN:A/SC:A/BI:M/DI:H/EX:M/EC:N/P:C` |
| Tags | `improper-spec-api` `timeout` `network` `cwe-573` |
| Source | [`internal/sast/rules/vnx-573.rego`](https://github.com/Vulnesis/cli/blob/main/internal/sast/rules/vnx-573.rego) |

## Overview

VNX-573 maps to [CWE-573: Improper Following of Specification by Caller](https://cwe.mitre.org/data/definitions/573.html). `URL.openStream()` and the helpers built on it open a `URLConnection` with the JDK default timeouts, which are zero: wait forever. A network call must be bounded by its caller, and these APIs give the caller no way to do it, so a slow or unresponsive server (or one an attacker controls, as in SSRF) holds the calling thread indefinitely and can exhaust a request pool.

## What gets flagged

```java
try (InputStream in = new URL(link).openStream()) { ... }

URL url = new URL(endpoint);
return url.openStream().available();

IOUtils.toString(remote, StandardCharsets.UTF_8);
FileUtils.copyURLToFile(remote, dest);
```

```kotlin
fun latest(): String = URL("$endpoint/latest").readText()
```

Reported receivers: `new URL(...)`, `URL(...)`, `uri.toURL()`, and names declared as a `URL` in the file. Guava `Resources.toString`/`toByteArray(url)` are reported too.

## What is not flagged

- Classpath and file URLs: `getResource(...)`, `file.toURI().toURL()`, `"file:"`/`"jar:"` literals.
- `openConnection()` followed by `setConnectTimeout`/`setReadTimeout`.
- The four-argument `FileUtils.copyURLToFile(url, file, connectTimeout, readTimeout)`.
- A file that sets `sun.net.client.defaultReadTimeout`.
- Kotlin `File.readText()` and reader `readText()`.
- The calls in comments or string literals.

## Remediation

1. Open a connection and bound it:
   ```java
   URLConnection c = url.openConnection();
   c.setConnectTimeout(5_000);
   c.setReadTimeout(10_000);
   try (InputStream in = c.getInputStream()) { ... }
   ```
2. Or use `java.net.http.HttpClient` with `connectTimeout(...)` and a per-request `timeout(...)`.
3. Use `FileUtils.copyURLToFile(url, file, connectTimeout, readTimeout)` in place of the two-argument form.

## References

- [CWE-573: Improper Following of Specification by Caller](https://cwe.mitre.org/data/definitions/573.html)
- [URLConnection.setReadTimeout](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/net/URLConnection.html#setReadTimeout(int))

## 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-573
// nosec vnx-573
```

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