# VNX-1051: Initialization with Hard-Coded Network Resource Configuration Data

Reports a literal IPv4 address written into Python, JavaScript/TypeScript, Java or Go source as a URL host, a host/address setting.

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

## Overview

VNX-1051 maps to [CWE-1051: Initialization with Hard-Coded Network Resource Configuration Data](https://cwe.mitre.org/data/definitions/1051.html). It reports a literal IPv4 address that a program initialises a network resource against:

- a URL or connection string whose host is an IP literal (`"http://10.0.4.12:8080/api"`, `"postgresql://app@10.0.4.12/db"`);
- an IP literal assigned to, or passed as, a host, address, server, endpoint, broker, proxy or URL name (`host="10.0.4.12"`, `DB_HOST = '10.0.4.12'`, `Addr: "10.0.4.12:6379"`, `factory.setHost("10.0.4.12")`);
- an IP literal given directly to a socket or dial API (`sock.connect(("10.0.4.12", 6379))`, `net.Dial("tcp", "10.0.4.12:6379")`, `new Socket("10.0.4.12", 80)`, `InetAddress.getByName`, `net.connect(port, host)`).

## Why this matters

An address in code ties the build to one network. When the service moves, fails over or is re-addressed, the code has to be changed and redeployed, and the old address may by then belong to someone else.

Not reported: loopback (`127.x`), `0.0.0.0`, broadcast, the documentation ranges `192.0.2.0/24`, `198.51.100.0/24` and `203.0.113.0/24`, the cloud metadata address `169.254.169.254`, CIDR blocks such as `10.0.0.0/8`, hostnames such as `localhost` or `api.example.com`, dotted version strings and OIDs, comments and test files.

## What gets flagged

```python
DB_HOST = "10.20.4.17"
CACHE = redis.Redis(host='172.16.8.3', port=6379, db=0)
sock.connect(("192.168.40.20", 9000))
```

```go
conn, err := net.Dial("tcp", "10.30.1.6:6379")
```

Not flagged:

```python
DB_HOST = os.environ.get("DB_HOST", "localhost")
ALLOWED_NETS = ["10.0.0.0/8", "172.16.0.0/12"]
```

## Remediation

1. Read hosts and URLs from configuration, environment variables or service discovery.
2. Prefer a DNS name over an address so the endpoint can move without a code change.

## References

- [CWE-1051: Initialization with Hard-Coded Network Resource Configuration Data](https://cwe.mitre.org/data/definitions/1051.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-1051
// nosec vnx-1051
```

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