Aller au contenu

Mutable static field (ARCH305)

Ce contenu n’est pas encore disponible dans votre langue.

Key dotnet.security.mutable-static-field · Severity warning · Category security · CWE CWE-362

Public mutable static fields can be changed by any code, causing cross-thread race conditions and corruption of security-relevant state.

public class Config
{
public static string ApiBaseUrl = "https://api.example.com";
}
public class Config
{
public static string ApiBaseUrl { get; } = "https://api.example.com";
}

Make the static field const/readonly or expose it through a read-only property; avoid public mutable static state.