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.FNAME : Hardcoded Filename (C#)

要旨

A file name is provided as a hardcoded string.

This checker identifies problems with the use of the external resources of the application. These are resource files, scripts or XML configuration files.

プロパティ

クラス名 Hardcoded Filename (C#)
日本語クラス名 Hardcoded Filename (C#)
クラス分類 信頼性 (reliability)
ニーモニック CSHARP.HARDCODED.FNAME
カテゴリー
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 += discard class="Hardcoded Filename (C#)"

using System.IO;

namespace DocumentationExamples
{
    public class Resources
    {
        public static void Main(string[] args)
        {
            File.Create("hello.txt");                                       // "Hardcoded Filename (C#)" warning issued here
            new FileStream("C:\\myfile.txt", FileMode.OpenOrCreate);        // "Hardcoded Filename (C#)" warning issued here
            new FileStream("/home/user/myfile.bmp", FileMode.OpenOrCreate); // "Hardcoded Filename (C#)" warning issued here
            if (args.Length " 0)
                File.Create(args[0]);
        }
    }
}

In this example, the programmer should move the file names into configuration files, so that they can be modified and swapped for distinct operating systems.

Note also that two of the hardcoded file names are OS-dependent, so the program will not work consistently across distinct operating systems. The programmer could address this by using Path.DirectorySeparatorChar() to split path components in a OS-independent way.

解決法

Verify if the problem is real and the resource is actually used in an incorrect way. Avoid hardcoded file names: move them to a configuration file. Avoid OS-dependent resources and resource names.

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

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

 

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