Skip to content

Commit 39e53a2

Browse files
Updates based on PR feedback. 1 pending change
1 parent 0805b49 commit 39e53a2

File tree

5 files changed

+32
-65
lines changed

5 files changed

+32
-65
lines changed

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

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,14 @@ import csharp
22
import DataFlow
33

44
/**
5-
* An abstract PropertyWrite for `TokenValidationParameters`.
6-
* Not really necessary anymore, but keeping it in case we want to extend the queries to check on other properties.
5+
* A sensitive property for `TokenValidationParameters` that updates the underlying value.
76
*/
8-
abstract class TokenValidationParametersPropertyWrite extends PropertyWrite { }
9-
10-
/**
11-
* An access to a sensitive property for `TokenValidationParameters` that updates the underlying value.
12-
*/
13-
class TokenValidationParametersPropertyWriteToBypassSensitiveValidation extends TokenValidationParametersPropertyWrite {
14-
TokenValidationParametersPropertyWriteToBypassSensitiveValidation() {
7+
class TokenValidationParametersPropertySensitiveValidation extends Property {
8+
TokenValidationParametersPropertySensitiveValidation() {
159
exists(Property p, Class c |
1610
c.hasQualifiedName("Microsoft.IdentityModel.Tokens.TokenValidationParameters")
1711
|
18-
p.getAnAccess() = this and
12+
p = this and
1913
c.getAProperty() = p and
2014
p.getName() in [
2115
"ValidateIssuer", "ValidateAudience", "ValidateLifetime", "RequireExpirationTime",
@@ -28,7 +22,7 @@ class TokenValidationParametersPropertyWriteToBypassSensitiveValidation extends
2822
/**
2923
* A dataflow from a `false` value to a write sensitive property for `TokenValidationParameters`.
3024
*/
31-
class FalseValueFlowsToTokenValidationParametersPropertyWriteToBypassValidation extends TaintTracking::Configuration {
25+
class FalseValueFlowsToTokenValidationParametersPropertyWriteToBypassValidation extends DataFlow::Configuration {
3226
FalseValueFlowsToTokenValidationParametersPropertyWriteToBypassValidation() {
3327
this = "FlowsToTokenValidationResultIsValidCall"
3428
}
@@ -41,7 +35,7 @@ class FalseValueFlowsToTokenValidationParametersPropertyWriteToBypassValidation
4135
override predicate isSink(DataFlow::Node sink) {
4236
exists(Assignment a |
4337
sink.asExpr() = a.getRValue() and
44-
a.getLValue() instanceof TokenValidationParametersPropertyWrite
38+
a.getLValue().(PropertyAccess).getProperty() instanceof TokenValidationParametersPropertySensitiveValidation
4539
)
4640
}
4741
}
@@ -83,7 +77,7 @@ class JsonWebTokenHandlerValidateTokenCall extends MethodCall {
8377
/**
8478
* A read access for properties `IsValid` or `Exception` for `Microsoft.IdentityModel.JsonWebTokens.JsonWebTokenHandler.ValidateToken`
8579
*/
86-
class TokenValidationResultIsValidCall extends PropertyRead {
80+
private class TokenValidationResultIsValidCall extends PropertyRead {
8781
TokenValidationResultIsValidCall() {
8882
exists(Property p | p.getAnAccess().(PropertyRead) = this |
8983
p.hasName("IsValid") or
@@ -95,7 +89,7 @@ class TokenValidationResultIsValidCall extends PropertyRead {
9589
/**
9690
* Dataflow from the output of `Microsoft.IdentityModel.JsonWebTokens.JsonWebTokenHandler.ValidateToken` call to access the `IsValid` or `Exception` property
9791
*/
98-
private class FlowsToTokenValidationResultIsValidCall extends TaintTracking::Configuration {
92+
private class FlowsToTokenValidationResultIsValidCall extends DataFlow::Configuration {
9993
FlowsToTokenValidationResultIsValidCall() { this = "FlowsToTokenValidationResultIsValidCall" }
10094

10195
override predicate isSource(DataFlow::Node source) {
@@ -108,25 +102,14 @@ private class FlowsToTokenValidationResultIsValidCall extends TaintTracking::Con
108102
}
109103

110104
/**
111-
* Holds if the call to `Microsoft.IdentityModel.JsonWebTokens.JsonWebTokenHandler.ValidateToken` flows to any `IsValid` or `Exception` property access
105+
* A security-sensitive property for `Microsoft.IdentityModel.Tokens.TokenValidationParameters`
112106
*/
113-
predicate hasAFlowToTokenValidationResultIsValidCall(JsonWebTokenHandlerValidateTokenCall call) {
114-
exists(FlowsToTokenValidationResultIsValidCall config, DataFlow::Node source |
115-
call = source.asExpr()
116-
|
117-
config.hasFlow(source, _)
118-
)
119-
}
120-
121-
/**
122-
* A property write for security-sensitive properties for `Microsoft.IdentityModel.Tokens.TokenValidationParameters`
123-
*/
124-
class TokenValidationParametersPropertyWriteToValidationDelegated extends PropertyWrite {
125-
TokenValidationParametersPropertyWriteToValidationDelegated() {
107+
class TokenValidationParametersProperty extends Property {
108+
TokenValidationParametersProperty() {
126109
exists(Property p, Class c |
127110
c.hasQualifiedName("Microsoft.IdentityModel.Tokens.TokenValidationParameters")
128111
|
129-
p.getAnAccess() = this and
112+
p = this and
130113
c.getAProperty() = p and
131114
p.getName() in [
132115
"SignatureValidator", "TokenReplayValidator", "AlgorithmValidator", "AudienceValidator",
@@ -170,7 +153,7 @@ class CallableAlwaysReturnsTrue extends Callable {
170153
or
171154
lambdaExprReturnsOnlyLiteralTrue(this)
172155
or
173-
exists(AnonymousFunctionExpr le, Call call, CallableAlwaysReturnsTrue cat, Callable callable |
156+
exists(AnonymousFunctionExpr le, Call call, Callable callable |
174157
this = le
175158
|
176159
callable.getACall() = call and
@@ -216,21 +199,6 @@ class CallableAlwaysReturnsTrueHigherPrecision extends CallableAlwaysReturnsTrue
216199
}
217200
}
218201

219-
/**
220-
* A property Write for the `IssuerValidator` property for `Microsoft.IdentityModel.Tokens.TokenValidationParameters`
221-
*/
222-
class TokenValidationParametersPropertyWriteToValidationDelegatedIssuerValidator extends PropertyWrite {
223-
TokenValidationParametersPropertyWriteToValidationDelegatedIssuerValidator() {
224-
exists(Property p, Class c |
225-
c.hasQualifiedName("Microsoft.IdentityModel.Tokens.TokenValidationParameters")
226-
|
227-
p.getAnAccess() = this and
228-
c.getAProperty() = p and
229-
p.hasName("IssuerValidator")
230-
)
231-
}
232-
}
233-
234202
/**
235203
* A callable that returns a `string` and has a `string` as 1st argument
236204
*/

csharp/ql/src/experimental/Security Features/JsonWebTokenHandler/delegated-security-validations-always-return-true.ql

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ import DataFlow
1616
import JsonWebTokenHandlerLib
1717

1818
from
19-
TokenValidationParametersPropertyWriteToValidationDelegated tv, Assignment a,
20-
CallableAlwaysReturnsTrueHigherPrecision e
21-
where a.getLValue() = tv and a.getRValue().getAChild*() = e
22-
select tv, "JsonWebTokenHandler security-sensitive property $@ is being delegated to $@.", tv,
23-
tv.getTarget().toString(), e, "a callable that always returns \"true\""
19+
TokenValidationParametersProperty p , CallableAlwaysReturnsTrueHigherPrecision e
20+
where e = p.getAnAssignedValue()
21+
select e, "JsonWebTokenHandler security-sensitive property $@ is being delegated to $@.", p,
22+
p.getQualifiedName().toString(), e, "a callable that always returns \"true\""

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import JsonWebTokenHandlerLib
1616
from
1717
FalseValueFlowsToTokenValidationParametersPropertyWriteToBypassValidation config,
1818
DataFlow::Node source, DataFlow::Node sink,
19-
TokenValidationParametersPropertyWriteToBypassSensitiveValidation pw
19+
TokenValidationParametersPropertySensitiveValidation pw
2020
where
2121
config.hasFlow(source, sink) and
22-
exists(Assignment a | a.getLValue() = pw | sink.asExpr() = a.getRValue())
22+
sink.asExpr() = pw.getAnAssignedValue()
2323
select sink, "The security sensitive property $@ is being disabled by the following value: $@.", pw,
24-
pw.getTarget().toString(), source, "false"
24+
pw.getQualifiedName().toString(), source, "false"
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
| delegation-test.cs:101:13:101:59 | access to property LifetimeValidator | JsonWebTokenHandler security-sensitive property $@ is being delegated to $@. | delegation-test.cs:101:13:101:59 | access to property LifetimeValidator | LifetimeValidator | delegation-test.cs:101:63:101:186 | (...) => ... | a callable that always returns "true" |
2-
| delegation-test.cs:102:13:102:59 | access to property AudienceValidator | JsonWebTokenHandler security-sensitive property $@ is being delegated to $@. | delegation-test.cs:102:13:102:59 | access to property AudienceValidator | AudienceValidator | delegation-test.cs:102:63:102:178 | (...) => ... | a callable that always returns "true" |
3-
| delegation-test.cs:115:13:115:59 | access to property AudienceValidator | JsonWebTokenHandler security-sensitive property $@ is being delegated to $@. | delegation-test.cs:115:13:115:59 | access to property AudienceValidator | AudienceValidator | delegation-test.cs:115:63:115:190 | (...) => ... | a callable that always returns "true" |
4-
| delegation-test.cs:116:13:116:59 | access to property AudienceValidator | JsonWebTokenHandler security-sensitive property $@ is being delegated to $@. | delegation-test.cs:116:13:116:59 | access to property AudienceValidator | AudienceValidator | delegation-test.cs:116:63:116:180 | (...) => ... | a callable that always returns "true" |
5-
| delegation-test.cs:117:13:117:59 | access to property AudienceValidator | JsonWebTokenHandler security-sensitive property $@ is being delegated to $@. | delegation-test.cs:117:13:117:59 | access to property AudienceValidator | AudienceValidator | delegation-test.cs:117:63:117:217 | (...) => ... | a callable that always returns "true" |
6-
| delegation-test.cs:118:13:118:59 | access to property AudienceValidator | JsonWebTokenHandler security-sensitive property $@ is being delegated to $@. | delegation-test.cs:118:13:118:59 | access to property AudienceValidator | AudienceValidator | delegation-test.cs:118:63:118:248 | (...) => ... | a callable that always returns "true" |
7-
| delegation-test.cs:119:13:119:59 | access to property AudienceValidator | JsonWebTokenHandler security-sensitive property $@ is being delegated to $@. | delegation-test.cs:119:13:119:59 | access to property AudienceValidator | AudienceValidator | delegation-test.cs:119:63:119:177 | (...) => ... | a callable that always returns "true" |
1+
| delegation-test.cs:101:63:101:186 | (...) => ... | JsonWebTokenHandler security-sensitive property $@ is being delegated to $@. | stubs.cs:54:34:54:50 | LifetimeValidator | Microsoft.IdentityModel.Tokens.TokenValidationParameters.LifetimeValidator | delegation-test.cs:101:63:101:186 | (...) => ... | a callable that always returns "true" |
2+
| delegation-test.cs:102:63:102:178 | (...) => ... | JsonWebTokenHandler security-sensitive property $@ is being delegated to $@. | stubs.cs:55:34:55:50 | AudienceValidator | Microsoft.IdentityModel.Tokens.TokenValidationParameters.AudienceValidator | delegation-test.cs:102:63:102:178 | (...) => ... | a callable that always returns "true" |
3+
| delegation-test.cs:115:63:115:190 | (...) => ... | JsonWebTokenHandler security-sensitive property $@ is being delegated to $@. | stubs.cs:55:34:55:50 | AudienceValidator | Microsoft.IdentityModel.Tokens.TokenValidationParameters.AudienceValidator | delegation-test.cs:115:63:115:190 | (...) => ... | a callable that always returns "true" |
4+
| delegation-test.cs:116:63:116:180 | (...) => ... | JsonWebTokenHandler security-sensitive property $@ is being delegated to $@. | stubs.cs:55:34:55:50 | AudienceValidator | Microsoft.IdentityModel.Tokens.TokenValidationParameters.AudienceValidator | delegation-test.cs:116:63:116:180 | (...) => ... | a callable that always returns "true" |
5+
| delegation-test.cs:117:63:117:217 | (...) => ... | JsonWebTokenHandler security-sensitive property $@ is being delegated to $@. | stubs.cs:55:34:55:50 | AudienceValidator | Microsoft.IdentityModel.Tokens.TokenValidationParameters.AudienceValidator | delegation-test.cs:117:63:117:217 | (...) => ... | a callable that always returns "true" |
6+
| delegation-test.cs:118:63:118:248 | (...) => ... | JsonWebTokenHandler security-sensitive property $@ is being delegated to $@. | stubs.cs:55:34:55:50 | AudienceValidator | Microsoft.IdentityModel.Tokens.TokenValidationParameters.AudienceValidator | delegation-test.cs:118:63:118:248 | (...) => ... | a callable that always returns "true" |
7+
| delegation-test.cs:119:63:119:177 | (...) => ... | JsonWebTokenHandler security-sensitive property $@ is being delegated to $@. | stubs.cs:55:34:55:50 | AudienceValidator | Microsoft.IdentityModel.Tokens.TokenValidationParameters.AudienceValidator | delegation-test.cs:119:63:119:177 | (...) => ... | a callable that always returns "true" |
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
| security-validation-disabled-test.cs:31:34:31:38 | false | The security sensitive property $@ is being disabled by the following value: $@. | security-validation-disabled-test.cs:31:17:31:30 | access to property ValidateIssuer | ValidateIssuer | security-validation-disabled-test.cs:31:34:31:38 | false | false |
2-
| security-validation-disabled-test.cs:32:36:32:40 | false | The security sensitive property $@ is being disabled by the following 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 |
3-
| security-validation-disabled-test.cs:33:36:33:40 | false | The security sensitive property $@ is being disabled by the following 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 |
4-
| security-validation-disabled-test.cs:34:41:34:45 | false | The security sensitive property $@ is being disabled by the following 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 following 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 |
1+
| security-validation-disabled-test.cs:31:34:31:38 | false | The security sensitive property $@ is being disabled by the following value: $@. | stubs.cs:43:21:43:34 | ValidateIssuer | Microsoft.IdentityModel.Tokens.TokenValidationParameters.ValidateIssuer | security-validation-disabled-test.cs:31:34:31:38 | false | false |
2+
| security-validation-disabled-test.cs:32:36:32:40 | false | The security sensitive property $@ is being disabled by the following value: $@. | stubs.cs:44:21:44:36 | ValidateAudience | Microsoft.IdentityModel.Tokens.TokenValidationParameters.ValidateAudience | security-validation-disabled-test.cs:32:36:32:40 | false | false |
3+
| security-validation-disabled-test.cs:33:36:33:40 | false | The security sensitive property $@ is being disabled by the following value: $@. | stubs.cs:45:21:45:36 | ValidateLifetime | Microsoft.IdentityModel.Tokens.TokenValidationParameters.ValidateLifetime | security-validation-disabled-test.cs:33:36:33:40 | false | false |
4+
| security-validation-disabled-test.cs:34:41:34:45 | false | The security sensitive property $@ is being disabled by the following value: $@. | stubs.cs:51:21:51:41 | RequireExpirationTime | Microsoft.IdentityModel.Tokens.TokenValidationParameters.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 following value: $@. | stubs.cs:50:21:50:35 | RequireAudience | Microsoft.IdentityModel.Tokens.TokenValidationParameters.RequireAudience | security-validation-disabled-test.cs:37:35:37:39 | false | false |

0 commit comments

Comments
 (0)