Skip to content

Commit 10b13f2

Browse files
author
dilanbhalla
committed
Merge branch 'main' of https://github.com/microsoft/codeql into auto/sync-main-pr
2 parents 95c7a7c + c9b45fd commit 10b13f2

File tree

2 files changed

+38
-89
lines changed

2 files changed

+38
-89
lines changed

csharp/ql/lib/semmle/code/csharp/security/dataflow/TaintedPathQuery.qll

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -217,23 +217,17 @@ class PathCheck extends Sanitizer {
217217
Guard g;
218218

219219
PathCheck() {
220-
<<<<<<< HEAD
221220
// This expression is structurally replicated in a dominating guard
222-
exists(AbstractValues::BooleanValue v | g = this.(GuardedDataFlowNode).getAGuard(_, v))
221+
exists(GuardValue v |
222+
g = this.(GuardedDataFlowNode).getAGuard(_, v) and
223+
exists(v.asBooleanValue())
224+
)
223225
}
224226

225227
override predicate isBarrier(TaintedPathConfig::FlowState state) {
226228
g.(WeakGuard).isBarrier(state)
227229
or
228230
not g instanceof WeakGuard
229-
=======
230-
// This expression is structurally replicated in a dominating guard which is not a "weak" check
231-
exists(Guard g, GuardValue v |
232-
g = this.(GuardedDataFlowNode).getAGuard(_, v) and
233-
exists(v.asBooleanValue()) and
234-
not g instanceof WeakGuard
235-
)
236-
>>>>>>> codeql-cli/latest
237231
}
238232
}
239233

csharp/ql/lib/semmle/code/csharp/security/dataflow/ZipSlipQuery.qll

Lines changed: 34 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,17 @@ class PathCombinerViaMethodCall extends UnsanitizedPathCombiner {
2020
}
2121
}
2222

23-
class PathCombinerViaStringInterpolation extends UnsanitizedPathCombiner instanceof InterpolatedStringExpr {}
23+
class PathCombinerViaStringInterpolation extends UnsanitizedPathCombiner instanceof InterpolatedStringExpr
24+
{ }
2425

2526
class PathCombinerViaStringConcatenation extends UnsanitizedPathCombiner instanceof AddExpr {
26-
PathCombinerViaStringConcatenation() {
27-
this.getAnOperand() instanceof StringLiteral
28-
}
27+
PathCombinerViaStringConcatenation() { this.getAnOperand() instanceof StringLiteral }
2928
}
3029

3130
class MethodCallGetFullPath extends MethodCall {
32-
MethodCallGetFullPath() { this.getTarget().hasFullyQualifiedName("System.IO.Path", "GetFullPath") }
31+
MethodCallGetFullPath() {
32+
this.getTarget().hasFullyQualifiedName("System.IO.Path", "GetFullPath")
33+
}
3334
}
3435

3536
/**
@@ -51,19 +52,17 @@ private module GetFullPathToQualifierTaintTrackingConfiguration implements DataF
5152
}
5253
}
5354

54-
class ZipArchiveEntryClass extends Class{
55-
ZipArchiveEntryClass(){
56-
this.hasFullyQualifiedName("System.IO.Compression", "ZipArchiveEntry")
57-
}
55+
class ZipArchiveEntryClass extends Class {
56+
ZipArchiveEntryClass() { this.hasFullyQualifiedName("System.IO.Compression", "ZipArchiveEntry") }
5857
}
5958

6059
/**
6160
* The `FullName` property of `System.IO.Compression.ZipArchiveEntry`.
6261
*/
63-
class ZipArchiveEntryFullNameAccess extends Property{
64-
ZipArchiveEntryFullNameAccess(){
65-
this.getDeclaringType() instanceof ZipArchiveEntryClass and
66-
this.getName() = "FullName"
62+
class ZipArchiveEntryFullNameAccess extends Property {
63+
ZipArchiveEntryFullNameAccess() {
64+
this.getDeclaringType() instanceof ZipArchiveEntryClass and
65+
this.getName() = "FullName"
6766
}
6867
}
6968

@@ -185,18 +184,17 @@ module SanitizedGuardTT = TaintTracking::Global<SanitizedGuardTaintTrackingConfi
185184
private module SanitizedGuardTaintTrackingConfiguration implements DataFlow::ConfigSig {
186185
predicate isSource(DataFlow::Node source) {
187186
source instanceof DataFlow::ParameterNode and
188-
exists(RootSanitizerMethodCall smc |
189-
smc.getEnclosingCallable() = source.getEnclosingCallable()
190-
)
187+
exists(RootSanitizerMethodCall smc | smc.getEnclosingCallable() = source.getEnclosingCallable())
191188
}
192189

193190
predicate isSink(DataFlow::Node sink) {
194191
exists(RootSanitizerMethodCall smc, Expr e |
195192
e = sink.asExpr() and
196-
e = [
197-
smc.getAnArgument(),
198-
smc.getQualifier()
199-
]
193+
e =
194+
[
195+
smc.getAnArgument(),
196+
smc.getQualifier()
197+
]
200198
)
201199
}
202200
}
@@ -205,25 +203,27 @@ private module SanitizedGuardTaintTrackingConfiguration implements DataFlow::Con
205203
* A Callable that successfully validates a path will resolve under a given directory,
206204
* and if it does not, throws an exception.
207205
*/
208-
private class ValidatingCallableThrowing extends Callable{
206+
private class ValidatingCallableThrowing extends Callable {
209207
Parameter paramFilename;
210-
ValidatingCallableThrowing(){
208+
209+
ValidatingCallableThrowing() {
211210
paramFilename = this.getAParameter() and
212211
// It passes the guard, contraining the function argument to the Guard argument.
213212
exists(ZipSlipGuard g, DataFlow::ParameterNode source, DataFlow::Node sink |
214213
g.getEnclosingCallable() = this and
215214
source = DataFlow::parameterNode(paramFilename) and
216215
sink = DataFlow::exprNode(g.getFilePathArgument()) and
217216
SanitizedGuardTT::flow(source, sink) and
218-
exists(AbstractValues::BooleanValue bv, ThrowStmt throw |
217+
exists(GuardValue bv, ThrowStmt throw |
219218
throw.getEnclosingCallable() = this and
220219
forall(TryStmt try | try.getEnclosingCallable() = this | not throw.getParent+() = try) and
221220
// If there exists a control block that guards against misuse
222-
bv.getValue() = false and
221+
bv.asBooleanValue() = false and
223222
g.controlsNode(throw.getAControlFlowNode(), bv)
224223
)
225224
)
226225
}
226+
227227
Parameter paramFilePath() { result = paramFilename }
228228
}
229229

@@ -283,9 +283,9 @@ class DirectWrapperSantizierMethod extends AbstractWrapperSanitizerMethod {
283283
sink = DataFlow::exprNode(g.getFilePathArgument()) and
284284
SanitizedGuardTT::flow(source, sink) and
285285
(
286-
exists(AbstractValues::BooleanValue bv |
286+
exists(GuardValue bv |
287287
// If there exists a control block that guards against misuse
288-
bv.getValue() = true and
288+
bv.asBooleanValue() = true and
289289
g.controlsNode(ret.getAControlFlowNode(), bv)
290290
)
291291
or
@@ -353,7 +353,6 @@ class WrapperSanitizerMethodCall extends SanitizerMethodCall {
353353
index = wrapperMethod.paramFilePath().getIndex()
354354
}
355355

356-
357356
override Expr getFilePathArgument() {
358357
exists(int index |
359358
this.paramFilePathIndex(index) and
@@ -362,11 +361,11 @@ class WrapperSanitizerMethodCall extends SanitizerMethodCall {
362361
}
363362
}
364363

365-
private predicate wrapperCheckGuard(Guard g, Expr e, AbstractValue v) {
364+
private predicate wrapperCheckGuard(Guard g, Expr e, GuardValue v) {
366365
// A given wrapper method call, with the filePathArgument as a sink, that returns 'true'
367366
g instanceof WrapperSanitizerMethodCall and
368367
g.(WrapperSanitizerMethodCall).getFilePathArgument() = e and
369-
v.(AbstractValues::BooleanValue).getValue() = true
368+
v.asBooleanValue() = true
370369
}
371370

372371
/**
@@ -388,8 +387,10 @@ class WrapperCheckSanitizer extends Sanitizer {
388387
* A Call to `ValidatingCallableThrowing` which acts as a barrier in a DataFlow
389388
*/
390389
class ValidatingCallableThrowingSanitizer extends Sanitizer {
391-
ValidatingCallableThrowingSanitizer(){
392-
exists(ValidatingCallableThrowing validator, Call validatorCall | validatorCall = validator.getACall() |
390+
ValidatingCallableThrowingSanitizer() {
391+
exists(ValidatingCallableThrowing validator, Call validatorCall |
392+
validatorCall = validator.getACall()
393+
|
393394
this = DataFlow::exprNode(validatorCall.getAnArgument())
394395
)
395396
}
@@ -418,7 +419,8 @@ class ArchiveEntryFullName extends Source {
418419
class SinkCompressionExtractToFileArgument extends Sink {
419420
SinkCompressionExtractToFileArgument() {
420421
exists(MethodCall mc |
421-
mc.getTarget().hasFullyQualifiedName("System.IO.Compression.ZipFileExtensions", "ExtractToFile") and
422+
mc.getTarget()
423+
.hasFullyQualifiedName("System.IO.Compression.ZipFileExtensions", "ExtractToFile") and
422424
this.asExpr() = mc.getArgumentForName("destinationFileName")
423425
)
424426
}
@@ -509,34 +511,8 @@ private module ZipSlipConfig implements DataFlow::ConfigSig {
509511
/**
510512
* A taint tracking module for Zip Slip.
511513
*/
512-
<<<<<<< HEAD
513-
module ZipSlip = TaintTracking::Global<ZipSlipConfig>;
514-
=======
515514
module ZipSlip = TaintTracking::Global<ZipSlipConfig>;
516515

517-
/** An access to the `FullName` property of a `ZipArchiveEntry`. */
518-
class ArchiveFullNameSource extends Source {
519-
ArchiveFullNameSource() {
520-
exists(PropertyAccess pa | this.asExpr() = pa |
521-
pa.getTarget()
522-
.getDeclaringType()
523-
.hasFullyQualifiedName("System.IO.Compression", "ZipArchiveEntry") and
524-
pa.getTarget().getName() = "FullName"
525-
)
526-
}
527-
}
528-
529-
/** An argument to the `ExtractToFile` extension method. */
530-
class ExtractToFileArgSink extends Sink {
531-
ExtractToFileArgSink() {
532-
exists(MethodCall mc |
533-
mc.getTarget()
534-
.hasFullyQualifiedName("System.IO.Compression", "ZipFileExtensions", "ExtractToFile") and
535-
this.asExpr() = mc.getArgumentForName("destinationFileName")
536-
)
537-
}
538-
}
539-
540516
/** A path argument to a `File.Open`, `File.OpenWrite`, or `File.Create` method call. */
541517
class FileOpenArgSink extends Sink {
542518
FileOpenArgSink() {
@@ -604,24 +580,3 @@ class SubstringSanitizer extends Sanitizer {
604580
)
605581
}
606582
}
607-
608-
private predicate stringCheckGuard(Guard g, Expr e, GuardValue v) {
609-
g.(MethodCall).getTarget().hasFullyQualifiedName("System", "String", "StartsWith") and
610-
g.(MethodCall).getQualifier() = e and
611-
// A StartsWith check against Path.Combine is not sufficient, because the ".." elements have
612-
// not yet been resolved.
613-
not exists(MethodCall combineCall |
614-
combineCall.getTarget().hasFullyQualifiedName("System.IO", "Path", "Combine") and
615-
DataFlow::localExprFlow(combineCall, e)
616-
) and
617-
v.asBooleanValue() = true
618-
}
619-
620-
/**
621-
* A call to `String.StartsWith()` that indicates that the tainted path value is being
622-
* validated to ensure that it occurs within a permitted output path.
623-
*/
624-
class StringCheckSanitizer extends Sanitizer {
625-
StringCheckSanitizer() { this = DataFlow::BarrierGuard<stringCheckGuard/3>::getABarrierNode() }
626-
}
627-
>>>>>>> codeql-cli/latest

0 commit comments

Comments
 (0)