# VNX-582: Array declared public, final and static

Reports public static final array fields and interface array constants in Java and public static readonly arrays in C#.

| Field | Value |
|---|---|
| Rule ID | `VNX-582` |
| Severity | Medium |
| SARIF level | `warning` |
| Kind | `sast` |
| Languages | Java, C# |
| CWE | [CWE-582](https://cwe.mitre.org/data/definitions/582.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 | `array-public` `cwe-582` |
| Source | [`internal/sast/rules/vnx-582.rego`](https://github.com/Vulnesis/cli/blob/main/internal/sast/rules/vnx-582.rego) |

## Overview

VNX-582 maps to [CWE-582: Array Declared Public, Final, and Static](https://cwe.mitre.org/data/definitions/582.html). It reports a `public static final` array field in Java (any modifier order, `int[] X` or `String X[]`, initialised inline or in a static block), an array constant declared in a Java interface (implicitly `public static final`), and a `public static readonly` array in C#.

## Why this matters

`final` and `readonly` fix the reference, not the contents. Any class can write `Limits.ALLOWED_ROLES[0] = "guest"` and change what every other caller sees, which turns a constant allow-list, key table or limit into shared mutable state.

## What gets flagged

```java
public static final int[] RETRY_DELAYS = {100, 200, 400};
public final static String[] ALLOWED_ROLES = new String[] {"admin", "editor"};
public static final String ADMINS[] = {

public interface Scopes {
    String[] DEFAULT_SCOPES = {"read", "write"};
}
```

```csharp
public static readonly string[] TrustedHosts = { "api.example.com" };
```

Not flagged: `private static final int[]`, `public static final int[] EMPTY = new int[0];`, `public static final List<String> X = List.of(...)`, `public static readonly IReadOnlyList<string>`, `Array.Empty<int>()`, methods returning arrays, comments, strings and test files.

## Remediation

1. Make the array `private` and expose an unmodifiable view (`Collections.unmodifiableList(Arrays.asList(...))`, `List.of(...)`) or return a defensive copy (`ARRAY.clone()`).
2. In C#, expose `IReadOnlyList<T>` or `ImmutableArray<T>` instead of `T[]`.

## References

- [CWE-582: Array Declared Public, Final, and Static](https://cwe.mitre.org/data/definitions/582.html)
- [SEI CERT OBJ13-J: Ensure that references to mutable objects are not exposed](https://wiki.sei.cmu.edu/confluence/display/java/OBJ13-J.+Ensure+that+references+to+mutable+objects+are+not+exposed)

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

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