Skip to content

Commit 8544356

Browse files
Adding Membership.GeneratePassword() as a bad source of random data because of the bias.
1 parent 6a09a56 commit 8544356

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

csharp/ql/src/Security Features/InsecureRandomness.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ string GeneratePassword()
1515
password = "mypassword" + BitConverter.ToInt32(randomBytes);
1616
}
1717

18-
// GOOD: Password is generated using a cryptographically secure RNG
18+
// BAD: Membership.GeneratePassword is generates a password with a bias
1919
password = Membership.GeneratePassword(12, 3);
2020

2121
return password;

csharp/ql/src/Security Features/InsecureRandomness.ql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ module Random {
5959
this.getExpr() =
6060
any(MethodCall mc |
6161
mc.getQualifier().getType().(RefType).hasQualifiedName("System", "Random")
62+
or
63+
// by using `% 87` on a `byte`, this function has a bias
64+
mc.getQualifier()
65+
.getType()
66+
.(RefType)
67+
.hasQualifiedName("System.Web.Security", "GeneratePassword")
6268
)
6369
}
6470
}

0 commit comments

Comments
 (0)