|
| 1 | +/** |
| 2 | + * @name Unsafe deserializer |
| 3 | + * @description Calling an unsafe deserializer with data controlled by an attacker |
| 4 | + * can lead to denial of service and other security problems. |
| 5 | + * @kind problem |
| 6 | + * @problem.severity error |
| 7 | + * @security-severity 8.8 |
| 8 | + * @precision high |
| 9 | + * @id powershell/microsoft/public/unsafe-deserialization |
| 10 | + * @tags correctness |
| 11 | + * security |
| 12 | + * external/cwe/cwe-502 |
| 13 | + */ |
| 14 | + |
| 15 | +import powershell |
| 16 | +import semmle.code.powershell.dataflow.flowsources.FlowSources |
| 17 | +import semmle.code.powershell.dataflow.DataFlow |
| 18 | +import semmle.code.powershell.dataflow.TaintTracking |
| 19 | + |
| 20 | +module DeserializationConfig implements DataFlow::ConfigSig { |
| 21 | + predicate isSource(DataFlow::Node source) { source instanceof SourceNode } |
| 22 | + |
| 23 | + predicate isSink(DataFlow::Node sink) { |
| 24 | + exists(DataFlow::ObjectCreationNode ocn, DataFlow::CallNode cn | |
| 25 | + cn.getQualifier().getALocalSource() = ocn and |
| 26 | + ocn.getExprNode().getExpr().(CallExpr).getAnArgument().getValue().asString() = "System.Runtime.Serialization.Formatters.Binary.BinaryFormatter" and |
| 27 | + cn.getLowerCaseName() = "deserialize" and |
| 28 | + cn.getAnArgument() = sink |
| 29 | + ) |
| 30 | + } |
| 31 | + predicate isAdditionalFlowStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo){ |
| 32 | + exists(InvokeMemberExpr ime | |
| 33 | + nodeTo.asExpr().getExpr() = ime and |
| 34 | + nodeFrom.asExpr().getExpr() = ime.getAnArgument() |
| 35 | + ) |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +module DeserializationFlow = TaintTracking::Global<DeserializationConfig>; |
| 40 | + |
| 41 | +from DataFlow::Node source, DataFlow::Node sink |
| 42 | +where DeserializationFlow::flow(source, sink) |
| 43 | +select sink, "Unsafe deserializer is used. Make sure the value being deserialized comes from a trusted source." |
0 commit comments