Skip to content

Commit 2b6726b

Browse files
chanel-yMathiasVP
andauthored
Move Inline Expectation comments to correct lines
Co-authored-by: Mathias Vorreiter Pedersen <mathiasvp@github.com>
1 parent 3cd00a9 commit 2b6726b

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

  • powershell/ql/test/query-tests/security/cwe-338/InsecureRandomness

powershell/ql/test/query-tests/security/cwe-338/InsecureRandomness/test.ps1

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,37 @@ $ivBytes = New-Object byte[] 16
99
$weak.NextBytes($keyBytes)
1010
$weak.NextBytes($ivBytes)
1111
$aes = [System.Security.Cryptography.Aes]::Create()
12-
$aes.Key = $keyBytes
13-
$aes.IV = $ivBytes
12+
$aes.Key = $keyBytes # BAD
13+
$aes.IV = $ivBytes # BAD
1414

1515
# --- Case 2: Weak RNG bytes flow into HMAC constructor ---
1616
$weak2 = New-Object System.Random # BAD
1717
$hmacKeyBytes = New-Object byte[] 64
1818
$weak2.NextBytes($hmacKeyBytes)
19-
$hmac = New-Object System.Security.Cryptography.HMACSHA256(,$hmacKeyBytes)
19+
$hmac = New-Object System.Security.Cryptography.HMACSHA256(,$hmacKeyBytes) # BAD
2020

2121
# --- Case 3: Weak RNG bytes used as KDF salt ---
2222
$weak3 = New-Object System.Random # BAD
2323
$saltBytes = New-Object byte[] 8
2424
$weak3.NextBytes($saltBytes)
25-
$kdf = New-Object System.Security.Cryptography.Rfc2898DeriveBytes("password", $saltBytes)
25+
$kdf = New-Object System.Security.Cryptography.Rfc2898DeriveBytes("password", $saltBytes) # BAD
2626

2727
# --- Case 4: Get-Random flows into ConvertTo-SecureString → PSCredential ---
28-
$tempPwd = (Get-Random -Maximum 999999999).ToString() # BAD
29-
$securePwd = ConvertTo-SecureString $tempPwd -AsPlainText -Force
28+
$tempPwd = (Get-Random -Maximum 999999999).ToString()
29+
$securePwd = ConvertTo-SecureString $tempPwd -AsPlainText -Force # BAD
3030
$cred = New-Object System.Management.Automation.PSCredential("admin", $securePwd)
3131

3232
# --- Case 5: Get-Random flows into HTTP Authorization header ---
33-
$tokenValue = Get-Random -Maximum 999999999 # BAD
33+
$tokenValue = Get-Random -Maximum 999999999
3434
Invoke-RestMethod -Uri "https://api.example.com/data" `
35-
-Headers @{ Authorization = "Bearer $tokenValue" }
35+
-Headers @{ Authorization = "Bearer $tokenValue" } # BAD
3636

3737
# --- Case 6: [System.Random]::new() bytes flow into AES .Key ---
3838
$rng3 = [System.Random]::new()
3939
$aesKey2 = New-Object byte[] 32
4040
$rng3.NextBytes($aesKey2)
4141
$aes2 = [System.Security.Cryptography.Aes]::Create()
42-
$aes2.Key = $aesKey2
42+
$aes2.Key = $aesKey2 # BAD
4343

4444
# ===================================================================
4545
# ========== TRUE NEGATIVES (should NOT trigger alert) ==============

0 commit comments

Comments
 (0)