# VNX-486: Comparison of Classes by Name

An object's type is decided by comparing its class name: in Java, getClass().getName().

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

## Overview

VNX-486 maps to [CWE-486: Comparison of Classes by Name](https://cwe.mitre.org/data/definitions/486.html). It reports code that decides what type an object is by comparing the class's name string instead of the class itself.

## Why this matters

A name is not an identity. Two classes loaded by different class loaders, a class in another package or module with the same simple name, or a plugin an attacker controls can all carry the name the check expects. When the comparison guards trust ("is this the trusted plugin?", "is this an admin principal?"), the wrong type passes.

## What gets flagged

```java
if (plugin.getClass().getName().equals("com.acme.plugins.TrustedPlugin")) { ... }  // FLAGGED
if ("AdminHandler".equals(h.getClass().getSimpleName())) { ... }                 // FLAGGED
```

```csharp
if (caller.GetType().Name == "TrustedCaller") return true;   // FLAGGED
```

```python
if type(principal).__name__ == "AdminUser":   # FLAGGED
    return True
```

Not flagged: `plugin instanceof TrustedPlugin`, `plugin.getClass() == CorePlugin.class`, `caller is TrustedCaller`, `isinstance(principal, AdminUser)`, and reading a class name for a log line.

## Remediation

1. Compare types, not strings: `instanceof` / `Class.isAssignableFrom` / `getClass() == Foo.class` in Java, `is` / `typeof(Foo)` in C#, `isinstance` or `type(x) is Foo` in Python.
2. Where a name must come from configuration, resolve it once through a trusted class loader and compare the resulting class object.

## References

- [CWE-486: Comparison of Classes by Name](https://cwe.mitre.org/data/definitions/486.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-486
// nosec vnx-486
```

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