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

tx0/go:hardcoded-ip-addressstrictwarningsecurity, maintainability

What it finds

conn, err := net.Dial("tcp", "10.20.0.7:5432"): an address written into the program ties it to one network layout. When the host moves, the program must be rebuilt, and an address that is reused later may reach a machine nobody intended. Addresses belong in configuration.

Reported are string literals that hold exactly an IPv4 address, optionally with a port, other than the loopback range 127.0.0.0/8, 0.0.0.0, 255.255.255.255 and the ranges reserved for documentation. Strings that look like version numbers, with a part that has a leading zero, are left alone. Addresses in tests, examples and defaults are common, so the rule is strict.

From the rule's source, hardcoded_ip_address.rs.

Example from the rule's tests
package p var (	db      = "10.20.0.7:5432"tx0 reports: the IP address 10.20.0.7 is written into the source	local   = "127.0.0.1:8080"	any     = "0.0.0.0"	doc     = "192.0.2.10"	version = "1.02.3.4"	dns     = "8.8.8.8"tx0 reports: the IP address 8.8.8.8 is written into the source)
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/go: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/go:hardcoded-ip-address] reason="..."

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