# VNX-754: Class resource used without checking for null

Reports Java getResourceAsStream()/getResource() results, which are null when the resource is missing.

| Field | Value |
|---|---|
| Rule ID | `VNX-754` |
| Severity | Low |
| SARIF level | `note` |
| Kind | `sast` |
| Languages | Java |
| CWE | [CWE-754](https://cwe.mitre.org/data/definitions/754.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:L/AP:RU/AL:S/IC:N/FC:LT/RP:RU/RL:S/AV:L/AS:N/IN:A/SC:A/BI:L/DI:H/EX:L/EC:N/P:L` |
| Tags | `unchecked-conditions` `null-dereference` `cwe-754` |
| Source | [`internal/sast/rules/vnx-754.rego`](https://github.com/Vulnesis/cli/blob/main/internal/sast/rules/vnx-754.rego) |

## Overview

VNX-754 maps to [CWE-754: Improper Check for Unusual or Exceptional Conditions](https://cwe.mitre.org/data/definitions/754.html). When a resource is missing, `getResourceAsStream()` on a Class, ClassLoader or ServletContext returns `null` instead of throwing. `Class`/`ClassLoader.getResource()` does the same. The rule reports the result when it is:

- dereferenced in the same expression
- passed straight to a consumer that dereferences it: `Properties.load`, `new InputStreamReader(...)`, `IOUtils.toString`, `FileCopyUtils.copyToByteArray`, a parser, and so on. The consumer can also open on the line above.
- assigned to a variable that the next 15 lines use before any null check

## What gets flagged

```java
return Banner.class.getResourceAsStream("/banner.txt").readAllBytes();   // FLAGGED
props.load(Settings.class.getClassLoader().getResourceAsStream("app.properties")); // FLAGGED
InputStream in = Keystore.class.getResourceAsStream("/server.p12");      // FLAGGED
ks.load(in, pass);
```

Not reported:

- results checked with `== null`, `!= null`, `Objects.requireNonNull`, `Optional.ofNullable` or `checkNotNull` before use
- Spring `ResourceLoader.getResource()`, which never returns null
- test code and comments

## Remediation

Check the result before using it, and fail with a message that names the missing resource:

```java
InputStream in = Objects.requireNonNull(
    getClass().getResourceAsStream("/app.properties"), "app.properties missing from classpath");
```

## References

- [CWE-754: Improper Check for Unusual or Exceptional Conditions](https://cwe.mitre.org/data/definitions/754.html)

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

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