A string literal is an IP address of a particular machine

tx0/ts:hardcoded-ip-addressstrictwarningsecurity

What it finds

An IP address written into the source ties the program to one network layout: moving a service means a code change, and the address reveals infrastructure to every reader. Configuration or a host name keeps it apart.

Reported are string literals that are an IPv4 address, optionally with a port, other than loopback, unspecified and broadcast addresses and those reserved for documentation (192.0.2.0/24, 198.51.100.0/24 and 203.0.113.0/24). Strings with four numbers that look like versions, such as "1.2.3.4", cannot be told apart, which is why this is a strict rule.

From the rule's source, hardcoded_ip_address.rs.

Example from the rule's tests
export const server = "10.20.30.40";tx0 reports: is the address of a particular machineexport const withPort = "172.16.0.5:8080";tx0 reports: is the address of a particular machineexport const local = "127.0.0.1";export const docs = "192.0.2.10";export const version = "1.2.3";export const notIp = "300.1.1.1";
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/ts: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/ts:hardcoded-ip-address] reason="..."

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