Skip to content

Commit 62c2857

Browse files
making changes based on feedback during PR
1 parent 13464e8 commit 62c2857

File tree

4 files changed

+28
-25
lines changed

4 files changed

+28
-25
lines changed

csharp/ql/src/experimental/Security Features/JsonWebTokenHandler/JsonWebTokenHandlerLib.qll

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import csharp
22
import DataFlow
33

44
/**
5-
* Abstract PropertyWrite for `TokenValidationParameters`.
5+
* An abstract PropertyWrite for `TokenValidationParameters`.
66
* Not really necessary anymore, but keeping it in case we want to extend the queries to check on other properties.
77
*/
88
abstract class TokenValidationParametersPropertyWrite extends PropertyWrite { }
@@ -18,27 +18,29 @@ class TokenValidationParametersPropertyWriteToBypassSensitiveValidation extends
1818
p.getAnAccess() = this and
1919
c.getAProperty() = p and
2020
p.getName() in [
21-
"ValidateIssuer", "ValidateAudience", "ValidateLifetime", "RequireExpirationTime"
21+
"ValidateIssuer", "ValidateAudience", "ValidateLifetime", "RequireExpirationTime", "RequireAudience"
2222
]
2323
)
2424
}
2525
}
2626

2727
/**
28-
* Dataflow from a `false` value to an to a write sensitive property for `TokenValidationParameters`.
28+
* A dataflow from a `false` value to a write sensitive property for `TokenValidationParameters`.
2929
*/
3030
class FalseValueFlowsToTokenValidationParametersPropertyWriteToBypassValidation extends TaintTracking::Configuration {
3131
FalseValueFlowsToTokenValidationParametersPropertyWriteToBypassValidation() {
3232
this = "FlowsToTokenValidationResultIsValidCall"
3333
}
3434

3535
override predicate isSource(DataFlow::Node source) {
36-
source.asExpr().(BoolLiteral).getValue() = "false"
36+
source.asExpr().getValue() = "false" and
37+
source.asExpr().getType() instanceof BoolType
3738
}
3839

3940
override predicate isSink(DataFlow::Node sink) {
40-
exists(TokenValidationParametersPropertyWrite pw, Assignment a | a.getLValue() = pw |
41+
exists(Assignment a |
4142
sink.asExpr() = a.getRValue()
43+
and a.getLValue() instanceof TokenValidationParametersPropertyWrite
4244
)
4345
}
4446
}
@@ -55,7 +57,7 @@ predicate isAssemblyOlderVersion(string assemblyName, string ver) {
5557
}
5658

5759
/**
58-
* Method `ValidateToken` for `Microsoft.IdentityModel.JsonWebTokens.JsonWebTokenHandler` or other Token handler that shares the same behavior characteristics
60+
* A method `ValidateToken` for `Microsoft.IdentityModel.JsonWebTokens.JsonWebTokenHandler` or other Token handler that shares the same behavior characteristics
5961
*/
6062
class JsonWebTokenHandlerValidateTokenMethod extends Method {
6163
JsonWebTokenHandlerValidateTokenMethod() {
@@ -78,7 +80,7 @@ class JsonWebTokenHandlerValidateTokenCall extends MethodCall {
7880
}
7981

8082
/**
81-
* Read access for properties `IsValid` or `Exception` for `Microsoft.IdentityModel.JsonWebTokens.JsonWebTokenHandler.ValidateToken`
83+
* A read access for properties `IsValid` or `Exception` for `Microsoft.IdentityModel.JsonWebTokens.JsonWebTokenHandler.ValidateToken`
8284
*/
8385
class TokenValidationResultIsValidCall extends PropertyRead {
8486
TokenValidationResultIsValidCall() {
@@ -116,7 +118,7 @@ predicate hasAFlowToTokenValidationResultIsValidCall(JsonWebTokenHandlerValidate
116118
}
117119

118120
/**
119-
* Property write for security-sensitive properties for `Microsoft.IdentityModel.Tokens.TokenValidationParameters`
121+
* A property write for security-sensitive properties for `Microsoft.IdentityModel.Tokens.TokenValidationParameters`
120122
*/
121123
class TokenValidationParametersPropertyWriteToValidationDelegated extends PropertyWrite {
122124
TokenValidationParametersPropertyWriteToValidationDelegated() {
@@ -136,7 +138,7 @@ class TokenValidationParametersPropertyWriteToValidationDelegated extends Proper
136138
/**
137139
* Holds if the callable has a return statement and it always returns true for all such statements
138140
*/
139-
predicate callableHasARetrunStmtAndAlwaysReturnsTrue(Callable c) {
141+
predicate callableHasAReturnStmtAndAlwaysReturnsTrue(Callable c) {
140142
c.getReturnType().toString() = "Boolean" and
141143
forall(ReturnStmt rs | rs.getEnclosingCallable() = c |
142144
rs.getChildExpr(0).(BoolLiteral).getBoolValue() = true
@@ -153,7 +155,7 @@ predicate lambdaExprReturnsOnlyLiteralTrue(LambdaExpr le) {
153155

154156
class CallableAlwaysReturnsTrue extends Callable {
155157
CallableAlwaysReturnsTrue() {
156-
callableHasARetrunStmtAndAlwaysReturnsTrue(this)
158+
callableHasAReturnStmtAndAlwaysReturnsTrue(this)
157159
or
158160
lambdaExprReturnsOnlyLiteralTrue(this)
159161
or
@@ -195,7 +197,7 @@ class CallableAlwaysReturnsTrueHigherPrecision extends CallableAlwaysReturnsTrue
195197
}
196198

197199
/**
198-
* Property Write for the `IssuerValidator` property for `Microsoft.IdentityModel.Tokens.TokenValidationParameters`
200+
* A property Write for the `IssuerValidator` property for `Microsoft.IdentityModel.Tokens.TokenValidationParameters`
199201
*/
200202
class TokenValidationParametersPropertyWriteToValidationDelegatedIssuerValidator extends PropertyWrite {
201203
TokenValidationParametersPropertyWriteToValidationDelegatedIssuerValidator() {
@@ -204,7 +206,7 @@ class TokenValidationParametersPropertyWriteToValidationDelegatedIssuerValidator
204206
|
205207
p.getAnAccess() = this and
206208
c.getAProperty() = p and
207-
p.getName() in ["IssuerValidator"]
209+
p.hasName("IssuerValidator")
208210
)
209211
}
210212
}
@@ -214,22 +216,22 @@ class TokenValidationParametersPropertyWriteToValidationDelegatedIssuerValidator
214216
*/
215217
private class CallableReturnsStringAndArg0IsString extends Callable {
216218
CallableReturnsStringAndArg0IsString() {
217-
this.getReturnType().toString() = "String" and
219+
this.getReturnType() instanceof StringType and
218220
this.getParameter(0).getType().toString() = "String"
219221
}
220222
}
221223

222224
/**
223-
* A Callable that always retrun the 1st argument, both of `string` type
225+
* A Callable that always return the 1st argument, both of `string` type
224226
*/
225-
class CallableAlwatsReturnsParameter0 extends CallableReturnsStringAndArg0IsString {
226-
CallableAlwatsReturnsParameter0() {
227+
class CallableAlwaysReturnsParameter0 extends CallableReturnsStringAndArg0IsString {
228+
CallableAlwaysReturnsParameter0() {
227229
forall(ReturnStmt rs | rs.getEnclosingCallable() = this |
228230
rs.getChild(0) = this.getParameter(0).getAnAccess()
229231
) and
230232
exists(ReturnStmt rs | rs.getEnclosingCallable() = this)
231233
or
232-
exists(LambdaExpr le, Call call, CallableAlwatsReturnsParameter0 cat | this = le |
234+
exists(LambdaExpr le, Call call, CallableAlwaysReturnsParameter0 cat | this = le |
233235
call = le.getExpressionBody() and
234236
cat.getACall() = call
235237
)
@@ -239,17 +241,17 @@ class CallableAlwatsReturnsParameter0 extends CallableReturnsStringAndArg0IsStri
239241
}
240242

241243
/**
242-
* A Callable that always retrun the 1st argument, both of `string` type. Higher precision
244+
* A Callable that always return the 1st argument, both of `string` type. Higher precision
243245
*/
244-
class CallableAlwatsReturnsParameter0MayThrowExceptions extends CallableReturnsStringAndArg0IsString {
245-
CallableAlwatsReturnsParameter0MayThrowExceptions() {
246+
class CallableAlwaysReturnsParameter0MayThrowExceptions extends CallableReturnsStringAndArg0IsString {
247+
CallableAlwaysReturnsParameter0MayThrowExceptions() {
246248
callableOnlyThrowsArgumentNullException(this) and
247249
forall(ReturnStmt rs | rs.getEnclosingCallable() = this |
248250
rs.getChild(0) = this.getParameter(0).getAnAccess()
249251
) and
250252
exists(ReturnStmt rs | rs.getEnclosingCallable() = this)
251253
or
252-
exists(LambdaExpr le, Call call, CallableAlwatsReturnsParameter0MayThrowExceptions cat |
254+
exists(LambdaExpr le, Call call, CallableAlwaysReturnsParameter0MayThrowExceptions cat |
253255
this = le
254256
|
255257
call = le.getExpressionBody() and

csharp/ql/test/experimental/Security Features/JsonWebTokenHandler/delegation-test.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
using Microsoft.IdentityModel.Tokens;
44
using Microsoft.IdentityModel.JsonWebTokens;
55

6-
namespace WilsonTest
6+
namespace JsonWebTokenHandlerTest
77
{
8-
public class Wilson_03
8+
public class JsonWebTokenHandler_00
99
{
1010
public static object ThrowIfNull(string name, object value)
1111
{

csharp/ql/test/experimental/Security Features/JsonWebTokenHandler/security-validation-disabled-test.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
using System.Collections.Generic;
33
using Microsoft.IdentityModel.Tokens;
44

5-
namespace WilsonTest
5+
namespace JsonWebTokenHandlerTest
66
{
7-
public class Wilson_02
7+
public class JsonWebTokenHandler_class01
88
{
99
public void TestCase01()
1010
{

csharp/ql/test/experimental/Security Features/JsonWebTokenHandler/security-validation-disabled.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
| security-validation-disabled-test.cs:32:36:32:40 | false | The security sensitive property $@ is being disabled by the followign value: $@. | security-validation-disabled-test.cs:32:17:32:32 | access to property ValidateAudience | ValidateAudience | security-validation-disabled-test.cs:32:36:32:40 | false | false |
33
| security-validation-disabled-test.cs:33:36:33:40 | false | The security sensitive property $@ is being disabled by the followign value: $@. | security-validation-disabled-test.cs:33:17:33:32 | access to property ValidateLifetime | ValidateLifetime | security-validation-disabled-test.cs:33:36:33:40 | false | false |
44
| security-validation-disabled-test.cs:34:41:34:45 | false | The security sensitive property $@ is being disabled by the followign value: $@. | security-validation-disabled-test.cs:34:17:34:37 | access to property RequireExpirationTime | RequireExpirationTime | security-validation-disabled-test.cs:34:41:34:45 | false | false |
5+
| security-validation-disabled-test.cs:37:35:37:39 | false | The security sensitive property $@ is being disabled by the followign value: $@. | security-validation-disabled-test.cs:37:17:37:31 | access to property RequireAudience | RequireAudience | security-validation-disabled-test.cs:37:35:37:39 | false | false |

0 commit comments

Comments
 (0)