# VNX-491: Public cloneable() Method Without Final ('Object Hijack')

A Java class that is not final declares a public clone() that is not final.

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

## Overview

VNX-491 maps to [CWE-491: Public cloneable() Method Without Final ('Object Hijack')](https://cwe.mitre.org/data/definitions/491.html). It reports an overridable public `clone()` that copies with `super.clone()` in a class that is not final.

## Why this matters

`super.clone()` produces an object without running any constructor, so constructor validation never happens for the copy. When the method and the class are both open to extension, a subclass can override `clone()` to return an object in a state the original class would never allow, or one that shares its mutable internals.

## What gets flagged

```java
public class Account implements Cloneable {
    @Override
    public Object clone() throws CloneNotSupportedException {   // FLAGGED
        return super.clone();
    }
}
```

Not flagged: `public final Object clone()`, a `clone()` in a `final class`, and a `clone()` that returns `new Point(x, y)`.

## Remediation

1. Declare `clone()` `final`, or make the class `final`.
2. Prefer a copy constructor or static factory (`Account.copyOf(a)`), which runs the constructor's checks.
3. If the class must not be cloned, declare `public final Object clone() throws CloneNotSupportedException { throw new CloneNotSupportedException(); }`.

## References

- [CWE-491: Public cloneable() Method Without Final ('Object Hijack')](https://cwe.mitre.org/data/definitions/491.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-491
// nosec vnx-491
```

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