# VNX-1072: Data Resource Access without Use of Connection Pooling

Java production code that opens database connections without a pool.

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

## Overview

VNX-1072 maps to [CWE-1072: Data Resource Access without Use of Connection Pooling](https://cwe.mitre.org/data/definitions/1072.html). It reports a call to `java.sql.DriverManager.getConnection(...)` and the construction of Spring's non-pooling DataSources (`new DriverManagerDataSource`, `new SimpleDriverDataSource`), each of which opens a new physical connection for every request. The call is also found split across lines (`DriverManager` / `.getConnection(...)`) and as a bare `getConnection(...)` after `import static java.sql.DriverManager.getConnection`. A vendor non-pooling DataSource (`PGSimpleDataSource`, `MysqlDataSource`, `MariaDbDataSource`, `SQLServerDataSource`, `OracleDataSource`, H2 `JdbcDataSource`) is reported when the file configures no pool.

It does not report `getConnection()` on a pooled DataSource (HikariCP, DBCP, c3p0, a container JNDI DataSource), a vendor DataSource handed to a pool (`HikariConfig.setDataSource(...)`), other `DriverManager` calls (`registerDriver`, `getDriver`), other receivers named like a driver manager, test sources, comments (including a trailing comment on a code line) or string literals. A short-lived command-line tool that legitimately opens one connection is still reported; suppress it there.

## Why this matters

Under load, opening a connection per request exhausts the database's connection slots (a denial of service any client can trigger by sending traffic) and makes every request pay the TCP, TLS and authentication handshake.

## What gets flagged

```java
try (Connection c = DriverManager.getConnection(URL, "app", pw)) {     // FLAGGED
DriverManagerDataSource ds = new DriverManagerDataSource();             // FLAGGED
return new SimpleDriverDataSource(new org.h2.Driver(), "jdbc:h2:mem:"); // FLAGGED
PGSimpleDataSource ds = new PGSimpleDataSource();                       // FLAGGED (no pool in the file)
```

Not flagged: `HikariDataSource ds = new HikariDataSource(cfg); ds.getConnection();`

## Remediation

1. Obtain connections from a pooled DataSource (HikariCP, or the application server's JNDI pool).
2. Size the pool for the database's connection limit.

## References

- [CWE-1072: Data Resource Access without Use of Connection Pooling](https://cwe.mitre.org/data/definitions/1072.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-1072
// nosec vnx-1072
```

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