# VNX-500: Public Static Field Not Marked Final

Detects public static fields that are not final (Java) or not readonly/const (C#), which any code in the process can reassign.

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

## Overview

VNX-500 maps to [CWE-500: Public Static Field Not Marked Final](https://cwe.mitre.org/data/definitions/500.html). A `public static` field is global state. Without `final` (Java) or `readonly`/`const` (C#), any class, plugin or deserialised object in the process can replace it, so a configuration flag, a singleton, a trusted-host list or a connection string other code depends on can change underneath it.

The rule reports the declaration, in any modifier order (`static public`, `public volatile static`), with or without an annotation or initialiser.

## What gets flagged

```java
public static String adminEmail = "ops@example.com";   // FLAGGED
static public boolean debug = false;                    // FLAGGED
public static String[] trustedHosts = {"a.example.com"}; // FLAGGED
```

```csharp
public static string ConnectionString = "Server=db;Database=app"; // FLAGGED
```

## What is not flagged

- `public static final` (Java) and `public static readonly` / `public const` (C#) fields.
- Non-public statics, methods, nested classes and generic methods.
- C# properties (`{ get; set; }`), expression-bodied members (`=> "x"`) and events.
- Fields of a Java interface, which are implicitly `final`.
- Test code, comments and string literals.

A `final` field that refers to a mutable object (an array or a collection) can still be changed in place; that is a separate weakness (CWE-582).

## Remediation

1. Declare the field `final` (`readonly` in C#).
2. If it must change, make it private and expose controlled accessors.

## References

- [CWE-500](https://cwe.mitre.org/data/definitions/500.html)
- [SEI CERT OBJ10-J: Do not use public static nonfinal fields](https://wiki.sei.cmu.edu/confluence/display/java/OBJ10-J.+Do+not+use+public+static+nonfinal+fields)

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

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