# VNX-493: Critical Public Variable Without Final Modifier

A public field that any code can overwrite holds security- or business-critical data.

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

## Overview

VNX-493 maps to [CWE-493: Critical Public Variable Without Final Modifier](https://cwe.mitre.org/data/definitions/493.html). It reports public, writable fields whose names mark them as critical: credentials, privilege flags and money.

## Why this matters

A public field without `final` (Java) or `readonly` (C#) can be reassigned by any code that can see the class. A static one is shared process-wide. If an authorization check reads `Settings.isAdmin`, or a checkout reads `product.price`, whoever can write the field decides the outcome.

## What gets flagged

```java
public static String DB_PASSWORD = System.getenv("DB_PW");   // FLAGGED
static public boolean isAdmin = false;                          // FLAGGED
public float price;                                              // FLAGGED
public static final String PASSWORD_PARAM = "password";         // not flagged
```

```csharp
public static string ConnectionPassword = "";   // FLAGGED
public decimal Price;                            // FLAGGED
public decimal Price { get; private set; }       // not flagged: property
public static readonly string ApiKeyName = "key"; // not flagged
```

## Remediation

1. Make the field `private` and expose a getter (and, only where needed, a validated setter).
2. If the value never changes after initialisation, declare it `final` / `readonly`.
3. Keep credentials out of fields altogether; read them from a secret store when needed.

## References

- [CWE-493: Critical Public Variable Without Final Modifier](https://cwe.mitre.org/data/definitions/493.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-493
// nosec vnx-493
```

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