Skip to content

Commit f439fa6

Browse files
authored
Merge pull request #70 from GitHubSecurityLab/csharp/refactortests
C#: Re-factor some of the existing tests.
2 parents c0f5c16 + 3210a96 commit f439fa6

File tree

116 files changed

+63517
-26
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+63517
-26
lines changed

csharp/src/library_sources/ExternalAPIsQuery.qll

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,21 @@ private import semmle.code.csharp.dataflow.FlowSummary
1111
// SECLAB: Import CSV utils
1212
private import semmle.code.csharp.dataflow.internal.ExternalFlow as ExternalFlow
1313

14-
// SECLAB: Import Csv::asPartialModel
15-
predicate asPartialModel = ExternalFlow::asPartialModel/1;
14+
/**
15+
* Computes the first 6 columns for MaD rows used for summaries, sources and sinks.
16+
*/
17+
private string asPartialModel(Callable api) {
18+
exists(string container, string type, string extensible, string name, string parameters |
19+
ExternalFlow::partialModel(api, container, type, extensible, name, parameters) and
20+
result =
21+
container + ";" //
22+
+ type + ";" //
23+
+ extensible + ";" //
24+
+ name + ";" //
25+
+ parameters + ";" //
26+
+ /* ext + */ ";" //
27+
)
28+
}
1629

1730
/**
1831
* A callable that is considered a "safe" external API from a security perspective.
@@ -100,7 +113,7 @@ deprecated class UntrustedDataToExternalApiConfig extends TaintTracking::Configu
100113

101114
/** A configuration for tracking flow from `ThreatModelFlowSource`s to `ExternalApiDataNode`s. */
102115
private module RemoteSourceToExternalApiConfig implements DataFlow::ConfigSig {
103-
predicate isSource(DataFlow::Node source) { source instanceof ThreatModelFlowSource }
116+
predicate isSource(DataFlow::Node source) { source instanceof ActiveThreatModelSource }
104117

105118
predicate isSink(DataFlow::Node sink) { sink instanceof ExternalApiDataNode }
106119
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* @kind test-postprocess
3+
*/
4+
5+
import semmle.code.csharp.dataflow.internal.ExternalFlow
6+
import codeql.dataflow.test.ProvenancePathGraph
7+
import codeql.dataflow.test.ProvenancePathGraph::TestPostProcessing::TranslateProvenanceResults<interpretModelForTest/2>
8+
9+
from string relation, int row, int column, string data
10+
where results(relation, row, column, data)
11+
select relation, row, column, data
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// This file contains auto-generated code.
2+
// Generated from `Microsoft.CSharp, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a`.
3+
namespace Microsoft
4+
{
5+
namespace CSharp
6+
{
7+
namespace RuntimeBinder
8+
{
9+
public static class Binder
10+
{
11+
public static System.Runtime.CompilerServices.CallSiteBinder BinaryOperation(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags flags, System.Linq.Expressions.ExpressionType operation, System.Type context, System.Collections.Generic.IEnumerable<Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo> argumentInfo) => throw null;
12+
public static System.Runtime.CompilerServices.CallSiteBinder Convert(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags flags, System.Type type, System.Type context) => throw null;
13+
public static System.Runtime.CompilerServices.CallSiteBinder GetIndex(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags flags, System.Type context, System.Collections.Generic.IEnumerable<Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo> argumentInfo) => throw null;
14+
public static System.Runtime.CompilerServices.CallSiteBinder GetMember(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags flags, string name, System.Type context, System.Collections.Generic.IEnumerable<Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo> argumentInfo) => throw null;
15+
public static System.Runtime.CompilerServices.CallSiteBinder Invoke(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags flags, System.Type context, System.Collections.Generic.IEnumerable<Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo> argumentInfo) => throw null;
16+
public static System.Runtime.CompilerServices.CallSiteBinder InvokeConstructor(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags flags, System.Type context, System.Collections.Generic.IEnumerable<Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo> argumentInfo) => throw null;
17+
public static System.Runtime.CompilerServices.CallSiteBinder InvokeMember(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags flags, string name, System.Collections.Generic.IEnumerable<System.Type> typeArguments, System.Type context, System.Collections.Generic.IEnumerable<Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo> argumentInfo) => throw null;
18+
public static System.Runtime.CompilerServices.CallSiteBinder IsEvent(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags flags, string name, System.Type context) => throw null;
19+
public static System.Runtime.CompilerServices.CallSiteBinder SetIndex(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags flags, System.Type context, System.Collections.Generic.IEnumerable<Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo> argumentInfo) => throw null;
20+
public static System.Runtime.CompilerServices.CallSiteBinder SetMember(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags flags, string name, System.Type context, System.Collections.Generic.IEnumerable<Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo> argumentInfo) => throw null;
21+
public static System.Runtime.CompilerServices.CallSiteBinder UnaryOperation(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags flags, System.Linq.Expressions.ExpressionType operation, System.Type context, System.Collections.Generic.IEnumerable<Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo> argumentInfo) => throw null;
22+
}
23+
public sealed class CSharpArgumentInfo
24+
{
25+
public static Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo Create(Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags flags, string name) => throw null;
26+
}
27+
[System.Flags]
28+
public enum CSharpArgumentInfoFlags
29+
{
30+
None = 0,
31+
UseCompileTimeType = 1,
32+
Constant = 2,
33+
NamedArgument = 4,
34+
IsRef = 8,
35+
IsOut = 16,
36+
IsStaticType = 32,
37+
}
38+
[System.Flags]
39+
public enum CSharpBinderFlags
40+
{
41+
None = 0,
42+
CheckedContext = 1,
43+
InvokeSimpleName = 2,
44+
InvokeSpecialName = 4,
45+
BinaryOperationLogical = 8,
46+
ConvertExplicit = 16,
47+
ConvertArrayIndex = 32,
48+
ResultIndexed = 64,
49+
ValueFromCompoundAssignment = 128,
50+
ResultDiscarded = 256,
51+
}
52+
public class RuntimeBinderException : System.Exception
53+
{
54+
public RuntimeBinderException() => throw null;
55+
protected RuntimeBinderException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) => throw null;
56+
public RuntimeBinderException(string message) => throw null;
57+
public RuntimeBinderException(string message, System.Exception innerException) => throw null;
58+
}
59+
public class RuntimeBinderInternalCompilerException : System.Exception
60+
{
61+
public RuntimeBinderInternalCompilerException() => throw null;
62+
protected RuntimeBinderInternalCompilerException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) => throw null;
63+
public RuntimeBinderInternalCompilerException(string message) => throw null;
64+
public RuntimeBinderInternalCompilerException(string message, System.Exception innerException) => throw null;
65+
}
66+
}
67+
}
68+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net8.0</TargetFramework>
4+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
5+
<OutputPath>bin\</OutputPath>
6+
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
7+
</PropertyGroup>
8+
9+
</Project>

0 commit comments

Comments
 (0)