# VNX-487: Reliance on Package-level Scope

A credential is held in a Java field with no access modifier, so the only thing protecting it is package scope.

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

## Overview

VNX-487 maps to [CWE-487: Reliance on Package-level Scope](https://cwe.mitre.org/data/definitions/487.html). It reports credentials kept in package-private (default access) fields, where package scope is the only barrier between the secret and other code.

## Why this matters

A Java package is not a security boundary. Any class that declares `package com.acme.auth;`, including one in another jar on the class path, can read a package-private field. A password or key left at default access is readable by far more code than its author intended.

## What gets flagged

```java
public class TokenStore {
    String apiToken;                          // FLAGGED
    char[] masterPassword;                    // FLAGGED
    static String adminPassword = System.getenv("ADMIN_PW");  // FLAGGED
    SecretKey sessionKey;                     // FLAGGED (key type, any name)
    private String hidden;                    // not flagged
    static final String PASSWORD_PARAM = "password";  // not flagged: names a parameter
}
```

## Remediation

1. Declare the field `private` and expose only the operation callers need (sign, verify), not the secret.
2. Clear `char[]`/`byte[]` secrets after use.
3. If the package must stay closed, seal it in the jar manifest (`Sealed: true`) or use JPMS modules that do not export it.

## References

- [CWE-487: Reliance on Package-level Scope](https://cwe.mitre.org/data/definitions/487.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-487
// nosec vnx-487
```

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