A string literal holds a public network address
What it finds
An address written in the code has to be changed in the code when the server moves, and often ends up pointing test builds at production or the other way round. Loopback, the any-address, broadcast and private ranges are left out, and so are addresses that start with 1 or 2, which are mostly object identifiers.
From the rule's source, hardcoded_ip.rs.
val server = "203.0.113.7"tx0 reports: the address 203.0.113.7 is written in the codeval api = "http://198.51.100.20:8080/v1"tx0 reports: the address 198.51.100.20val local = "127.0.0.1"val lan = "192.168.1.10"val version = "1.2.3" 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:
[rules]
"tx0/kotlin: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/kotlin:hardcoded-ip-address] reason="..."tx0 explain tx0/kotlin:hardcoded-ip-address shows the same in the terminal. Found a false positive? Report it.