# VNX-412: Unrestricted Externally Accessible Lock

Java locks other code can take and hold: synchronized on an interned string, a String constant, Boolean.TRUE/FALSE or a boxed valueOf cache.

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

## Overview

VNX-412 maps to [CWE-412: Unrestricted Externally Accessible Lock](https://cwe.mitre.org/data/definitions/412.html). The rule reports Java locks that code outside the class can acquire and hold, blocking the class indefinitely.

## Why this matters

String literals are interned and `Boolean.TRUE` or small boxed integers are shared JVM-wide, so any library that happens to synchronize on the same value contends with this class. A public lock field or getter lets any caller take the lock and never release it.

## What gets flagged

```java
synchronized ("refresh") { ... }                          // FLAGGED: interned literal
synchronized (user.intern()) { ... }                      // FLAGGED
synchronized (CACHE_LOCK) { ... }                         // FLAGGED when CACHE_LOCK = "token-cache"
public final Object lock = new Object();                  // FLAGGED when the class synchronizes on it
public static final ReentrantLock WRITE_LOCK = new ReentrantLock();  // FLAGGED
public ReadWriteLock getLock() { return rw; }             // FLAGGED
```

Not flagged: `synchronized (this)`, synchronized methods and `synchronized (Foo.class)` (an ordinary idiom), private or package-private lock fields, public fields that are never used as a lock, test files, comments and strings.

## Remediation

1. Lock on a `private final Object lock = new Object();` owned by the class.
2. Do not return lock objects from public methods; expose operations instead.
3. For confirmed false positives, add a `// vulnetix-ignore: VNX-412` comment on the line.

## References

- [CWE-412: Unrestricted Externally Accessible Lock](https://cwe.mitre.org/data/definitions/412.html)
- [SEI CERT LCK00-J: Use private final lock objects](https://wiki.sei.cmu.edu/confluence/display/java/LCK00-J.+Use+private+final+lock+objects+to+synchronize+classes+that+may+interact+with+untrusted+code)

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

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