JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.

If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.

If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.

CodeSonar® 9.2p0 CONFIDENTIAL CodeSecure Inc
C#


CSHARP.HARDCODED.IP : Hardcoded IP Address (C#)

要旨

An occurrence or use of a hardcoded IP address or URL/URI.

Warning locations for this warning class depend on the setting of CSHARP_ANALYSIS_PEDANTIC_MODE.

CSHARP_ANALYSIS_PEDANTIC_MODE=Yes A warning is issued when a method that takes a host/hostname parameter is passed a hardcoded value that matches IP address or URI/URL format.
A warning is not issued for a hardcoded string that matches IP address format unless there is evidence that the string is used as a host/hostname parameter.
CSHARP_ANALYSIS_PEDANTIC_MODE=No A warning is issued for each string literal that that matches IP address or URI/URL format.
There is no requirement that the string be used in a specific context, or even that it be used at all.

Having a hardcoded IP address is considered a bad practice. It can lead to several problems:

Some security protocols are now considered deprecated and unsafe and so, they must not be used.

プロパティ

クラス名 Hardcoded IP Address (C#)
日本語クラス名 Hardcoded IP Address (C#)
クラス分類 セキュリティ (security)
ニーモニック CSHARP.HARDCODED.IP
カテゴリー
CWE CWE:547 Use of Hard-coded, Security-relevant Constants
OWASP-2017 OWASP-2017:A6 Security misconfiguration
OWASP-2021 OWASP-2021:A5 Security misconfiguration
OWASP-2025 OWASP-2025:A02 Security Misconfiguration
対応言語 C# で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっています。チェックを有効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += allow class="Hardcoded IP Address (C#)"

using System;
using System.Net;


namespace HardCodedIPAddressExamples
{

  public class HardCodedIPAddress
  {

    public string http_IPv6;

    public void HardCoded_IP() {

      http_IPv6 = "http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html"; // "Hardcoded IP Address (C#)" warning always issued here

      string IPv6 = "[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]"; // "Hardcoded IP Address (C#)" warning issued here when CSHARP_ANALYSIS_PEDANTIC_MODE=Yes

      string broadcast = "255.255.255.255";                        // OK: broadcast IP

      string loopback = "127.0.0.1";                               // OK: loopback IP

      string software_version = "9.0.3.1";              // "Hardcoded IP Address (C#)" warning issued here when CSHARP_ANALYSIS_PEDANTIC_MODE=Yes
                                                        // - given the variable name, this is likely a false positive

      string IPv4 = "192.88.11.2";                      // "Hardcoded IP Address (C#)" warning issued here when CSHARP_ANALYSIS_PEDANTIC_MODE=Yes

      TcpClient client_tcp = new TcpClient(IPv4, 2222); // "Hardcoded IP Address (C#)" warning issued here when CSHARP_ANALYSIS_PEDANTIC_MODE=No

      UdpClient client_udp = new UdpClient(IPv4, 2223); // "Hardcoded IP Address (C#)" warning issued here when CSHARP_ANALYSIS_PEDANTIC_MODE=No

      string ftp_IPv4 = "ftp://192.88.11.3:3333";       // "Hardcoded IP Address (C#)" warning issued here when CSHARP_ANALYSIS_PEDANTIC_MODE=Yes

      Uri uri = new Uri(ftp_IPv4);                      // "Hardcoded IP Address (C#)" warning issued here when CSHARP_ANALYSIS_PEDANTIC_MODE=No

    }

  }
}

解決法

Parameterize it in a configuration file.

関連のある設定ファイルパラメータ

設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。

 

To report problems with this documentation, please visit https://support.codesecure.com/.