Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/*.testproj
**/*.actual
18 changes: 18 additions & 0 deletions tests/csharp-tests/CWE-760/HardcodedSalt.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
edges
| Test.cs:13:16:13:55 | call to method GetBytes : Byte[] | Test.cs:14:49:14:52 | access to local variable salt |
| Test.cs:13:39:13:54 | "Hardcoded Salt" : String | Test.cs:13:16:13:55 | call to method GetBytes : Byte[] |
| Test.cs:23:12:23:28 | "Hardcoded Salt2" : String | Test.cs:29:39:29:63 | call to method generateSalt : String |
| Test.cs:29:16:29:64 | call to method GetBytes : Byte[] | Test.cs:30:49:30:52 | access to local variable salt |
| Test.cs:29:39:29:63 | call to method generateSalt : String | Test.cs:29:16:29:64 | call to method GetBytes : Byte[] |
nodes
| Test.cs:13:16:13:55 | call to method GetBytes : Byte[] | semmle.label | call to method GetBytes : Byte[] |
| Test.cs:13:39:13:54 | "Hardcoded Salt" : String | semmle.label | "Hardcoded Salt" : String |
| Test.cs:14:49:14:52 | access to local variable salt | semmle.label | access to local variable salt |
| Test.cs:23:12:23:28 | "Hardcoded Salt2" : String | semmle.label | "Hardcoded Salt2" : String |
| Test.cs:29:16:29:64 | call to method GetBytes : Byte[] | semmle.label | call to method GetBytes : Byte[] |
| Test.cs:29:39:29:63 | call to method generateSalt : String | semmle.label | call to method generateSalt : String |
| Test.cs:30:49:30:52 | access to local variable salt | semmle.label | access to local variable salt |
subpaths
#select
| Test.cs:14:49:14:52 | access to local variable salt | Test.cs:13:39:13:54 | "Hardcoded Salt" : String | Test.cs:14:49:14:52 | access to local variable salt | Use of $@. | Test.cs:13:39:13:54 | "Hardcoded Salt" | hardcoded salt |
| Test.cs:30:49:30:52 | access to local variable salt | Test.cs:23:12:23:28 | "Hardcoded Salt2" : String | Test.cs:30:49:30:52 | access to local variable salt | Use of $@. | Test.cs:23:12:23:28 | "Hardcoded Salt2" | hardcoded salt |
1 change: 1 addition & 0 deletions tests/csharp-tests/CWE-760/HardcodedSalt.qlref
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CWE-760/HardcodedSalt.ql
32 changes: 32 additions & 0 deletions tests/csharp-tests/CWE-760/Test.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.IO;
using System.Text;
using System.Runtime.Serialization;
using System.Security.Cryptography;
using System.Security.Permissions;

public class StaticSalt {
public void Test1() {
string password = "TestPassword";

// BAD: Static String
var salt = Encoding.UTF8.GetBytes("Hardcoded Salt");
var hash = new Rfc2898DeriveBytes(password, salt);

// Good: Randomly generated byte array
var randonSalt = new byte[16];
RandomNumberGenerator.Create().GetBytes(randonSalt);
var hash_safe = new Rfc2898DeriveBytes(password, randonSalt);
}

public static string generateSalt() {
return "Hardcoded Salt2";
}
public void Test2() {
string password = "TestPassword2";

// BAD: Static String
var salt = Encoding.UTF8.GetBytes(StaticSalt.generateSalt());
var hash = new Rfc2898DeriveBytes(password, salt);
}
}
1 change: 1 addition & 0 deletions tests/csharp-tests/CWE-760/options
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
semmle-extractor-options: /r:System.Security.Cryptography.Csp.dll /r:System.Security.Cryptography.Algorithms.dll
26 changes: 26 additions & 0 deletions tests/csharp-tests/CWE-916/Test.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.IO;
using System.Text;
using System.Runtime.Serialization;
using System.Security.Cryptography;
using System.Security.Permissions;

public class StaticSalt {
public void Test1() {
string password = "TestPassword";
var randonSalt = new byte[16];
RandomNumberGenerator.Create().GetBytes(randonSalt);


// BAD: Default (1000)
var hash = new Rfc2898DeriveBytes(password, randonSalt);

// BAD: Static int
var hash2 = new Rfc2898DeriveBytes(password, randonSalt, 1000);



// Good: High interations
var hash_safe = new Rfc2898DeriveBytes(password, randonSalt, 100000);
}
}
6 changes: 6 additions & 0 deletions tests/csharp-tests/CWE-916/WeakIterations.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
edges
nodes
| Test.cs:19:62:19:65 | 1000 | semmle.label | 1000 |
subpaths
#select
| Test.cs:19:62:19:65 | 1000 | Test.cs:19:62:19:65 | 1000 | Test.cs:19:62:19:65 | 1000 | Use of $@. | Test.cs:19:62:19:65 | 1000 | hardcoded weak iterations |
1 change: 1 addition & 0 deletions tests/csharp-tests/CWE-916/WeakIterations.qlref
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CWE-916/WeakIterations.ql
1 change: 1 addition & 0 deletions tests/csharp-tests/CWE-916/options
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
semmle-extractor-options: /r:System.Security.Cryptography.Csp.dll /r:System.Security.Cryptography.Algorithms.dll
4 changes: 4 additions & 0 deletions tests/csharp-tests/qlpack.lock.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
dependencies: {}
compiled: false
lockVersion: 1.0.0
8 changes: 8 additions & 0 deletions tests/csharp-tests/qlpack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: github-queries-csharp-tests
groups: [csharp, test]
dependencies:
codeql/csharp-all: "*"
github-queries-csharp: "*"

extractor: csharp
tests: .