Rule Definition
Built-in remote addresses cause problems when the target is moved. Avoid hardcoded network resources (e.g., IP addresses, URLs, etc.)
Remediation
Utilize indirect access to network resources using underlying operating system calls and relative paths. In case hard coding is necessary, isolating hard coded data to installation scripts or configuration files can limit its potential negative impact.
Violation Code Sample
var ipv4 = "193.43.55.67";
...
ipv4 = "193.43.55.67";
...
var ipv6 = "2001:db8:0:85a3:0:0:ac1f:8001";
...
ipv6 = "2001:db8:0:85a3:0:0:ac1f:8001";
...
var ipAddress = IPAddress.Parse("193.43.55.67");
Fixed Code Sample
var ipv4 = ConfigurationManager.AppSettings["appIP"];
...
ipv4 = ConfigurationManager.AppSettings["appIP"];
...
var ipv6 = ConfigurationManager.AppSettings["appIP"];
...
ipv6 = ConfigurationManager.AppSettings["appIP"];
...
var ipAddress = ConfigurationManager.AppSettings["appIP"];
Reference
ASCRM 1.0, Automated Source Code Reliability Measure, Object Management Group.- ASCRM-RLB-18
Related Technologies
Technical Criterion
CWE-1051 - Initialization with Hard-Coded Network Resource Configuration Data
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.