Summary
The C# engine links a crypto object to its settings by comparing plain variable names. If the object is used through a second variable, the link breaks and the settings are lost.
In engine/src/main/java/com/ibm/engine/language/csharp/CSharpDetectionEngine.java:
:420 — return invocation.getObjectTypeName().equals(sym.getName());
:439 — return assignedId.equals(sym.getName());
This is the C# form of #8.
The fix from #390 cannot be ported here. That PR walks Symbol.declaration() in Java and Symbol.usages() in Python. C# has neither. CSharpSymbol holds only a name string, and its own javadoc says the ANTLR4 grammar gives no semantic resolution. So C# needs a different solution: track assignments while building the tree in CSharpTreeConverter, or build a small symbol table for the file.
Steps to reproduce
csharp/src/test/files/rules/detection/dotnet/ProbeCSharpAliasTestFile.cs:
using System.Security.Cryptography;
public class ProbeCSharpAlias
{
public void TestViaAlias()
{
var aes = Aes.Create();
var alias = aes;
alias.Mode = CipherMode.CBC;
alias.KeySize = 256;
}
}
Run it through the C# TestBase with CSharpVerifier.
Actual behaviour
finding=0
value=AES
children=3
node=AES
The three property stores are created, but they carry no detected values. Mode and key size never reach the model. The CBOM entry is a bare AES.
Expected behaviour
The same result as the direct form, which already works. DotNetAESPropertyTestFile.cs uses aes directly and DotNetAESPropertyTest asserts:
node.asString() == "AES-256-CBC-PKCS7"
With the alias, the expected result is AES-256-CBC.
Severity and frequency
Acceptance criteria
Notes
Related work:
Summary
The C# engine links a crypto object to its settings by comparing plain variable names. If the object is used through a second variable, the link breaks and the settings are lost.
In
engine/src/main/java/com/ibm/engine/language/csharp/CSharpDetectionEngine.java::420—return invocation.getObjectTypeName().equals(sym.getName());:439—return assignedId.equals(sym.getName());This is the C# form of #8.
The fix from #390 cannot be ported here. That PR walks
Symbol.declaration()in Java andSymbol.usages()in Python. C# has neither.CSharpSymbolholds only a name string, and its own javadoc says the ANTLR4 grammar gives no semantic resolution. So C# needs a different solution: track assignments while building the tree inCSharpTreeConverter, or build a small symbol table for the file.Steps to reproduce
csharp/src/test/files/rules/detection/dotnet/ProbeCSharpAliasTestFile.cs:Run it through the C#
TestBasewithCSharpVerifier.Actual behaviour
The three property stores are created, but they carry no detected values. Mode and key size never reach the model. The CBOM entry is a bare
AES.Expected behaviour
The same result as the direct form, which already works.
DotNetAESPropertyTestFile.csusesaesdirectly andDotNetAESPropertyTestasserts:With the alias, the expected result is
AES-256-CBC.Severity and frequency
using var x = y;.Acceptance criteria
AES-256-CBCcsharpmodule tests still passNotes
Related work: