An IP address is written into the source as a string literal

tx0/c:hardcoded-ip-addressstrictwarningsecurity/configurationdepth fastsecurity, cwe-547

What it finds

connect_to("10.20.30.40", 443): an address written into the code cannot change without a new build, and often names a host of one environment, which then leaks into others. Addresses belong in configuration.

A string literal counts when it is a dotted IPv4 address, optionally with a port. Addresses that are fixed by definition are left alone: loopback, the unspecified and broadcast addresses, and the ranges reserved for documentation.

From the rule's source, hardcoded_ip_address.rs.

Example from the rule's tests
const char *servers[] = {  "10.20.30.40",tx0 reports: an IP address is written into the code  "172.16.0.1:8080",tx0 reports: an IP address  "127.0.0.1",  "192.0.2.10",  "1.2.3",  "version 1.2.3.4",};
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/c:hardcoded-ip-address" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/c:hardcoded-ip-address] reason="..."

tx0 explain tx0/c:hardcoded-ip-address shows the same in the terminal. Found a false positive? Report it.