Uh oh!
There was an error while loading. Please reload this page.
[csharp] need help with taint propagation #19911
Hi, I don't understand why my taint is not propagating. I have 3 test cases that look similar, but it only works for one. Here is my C# code: protectedFullyInstrumentedType(SerializationInfo info,StreamingContext context){Console.WriteLine("Deserialization constructor");Data=info.GetString("Data");//1BinaryFormatterbinaryFormatter=newBinaryFormatter();using(MemoryStreammemoryStream=newMemoryStream(Convert.FromBase64String(this.Data))){binaryFormatter.Deserialize(memoryStream);}//2byte[]a=Convert.FromBase64String(this.Data);MemoryStreamstream=null;stream=newMemoryStream(a);(newBinaryFormatter()).Deserialize(stream);//3byte[]b=Encoding.UTF8.GetBytes(this.Data);MemoryStreamms=null;ms=newMemoryStream(b);(newBinaryFormatter()).Deserialize(ms);In the first scenario, the taint halts at the /** * @name Forward Partial Dataflow * @description Forward Partial Dataflow * @kind path-problem * @precision low * @problem.severity error * @id githubsecuritylab/forward-partial-dataflow * @tags template */import csharp
import semmle.code.csharp.dataflow.TaintTracking
import semmle.code.csharp.serialization.Serialization
import PartialFlow::PartialPathGraph
import libs.Source
privatemodule MyConfig implements DataFlow::ConfigSig{predicateisSource(DataFlow::Nodemysrc){mysrc.asParameter().getCallable()instanceofSerializationConstructorand(mysrc.asParameter().getCallable().hasName("ClaimsPrincipal")ormysrc.asParameter().getCallable().hasName("FullyInstrumentedType"))}predicateisAdditionalFlowStep(DataFlow::Nodenode1, DataFlow::Nodenode2){any(SerializationInfoGetTaintSteps).step(node1,node2)}predicateisSink(DataFlow::Nodesink){none()}}/** * We want to propagate output of SerializationInfo: * * Data = info.GetString("Data"); */classSerializationInfoGetTaintStepextendsGadgetAdditionalTaintStep{overridepredicatestep(DataFlow::NodefromNode, DataFlow::NodetoNode){exists(MethodCallmc,Methodm|mc.getTarget()=mandm.getName().matches("Get%")andm.getDeclaringType().hasFullyQualifiedName("System.Runtime.Serialization","SerializationInfo")and// Taint flows from the qualifier (info) to the call resultfromNode.asExpr()=mc.getQualifier()andtoNode.asExpr()=mc)}}privatemodule MyFlow = TaintTracking::Global<MyConfig>; // or DataFlow::Global<..>intexplorationLimit(){result=10}privatemodule PartialFlow = MyFlow::FlowExplorationFwd<explorationLimit/0>;
from PartialFlow::PartialPathNodesource, PartialFlow::PartialPathNodesinkwhere PartialFlow::partialFlow(source,sink, _)selectsink.getNode(),source,sink,"This node receives taint from $@.",source.getNode(),"this source"Based on this it should propagate the taint. What am I missing here ? Thank you. |
Replies: 9 comments 28 replies
Using the same query on a different Codeql database yield the same problem on another method: And again there is a summary step for this method here. So the problem might be somewhere else, I don't understand |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Thank you very much for reporting this. It looks like the model for I will look into this. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
@Hug0Vincent : Will see if I can fix at least some of the modelling and get back to you. |
Related PR #19940 |
The related PR #19940 has been merged. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi @michaelnebel I've reopened the issue because I found a new variant of this bug this time with the newXmlTextReader(newStringReader(taintedString))As a workaround I've added this line in the yaml file and it works: - ["System.Xml", "XmlTextReader", False, "XmlTextReader", "(System.IO.TextReader)", "", "Argument[0]", "Argument[this]", "taint", "dfc-generated"]I'm unsure if certain constructors should be filtered out. How are those generated model packs created? |
I have one new here also, fixed with this: - ["System.Xml", "XmlDictionaryReader", True, "ReadContentAsBase64", "()", "", "Argument[this]", "ReturnValue", "taint", "manual"]Some other |
@Hug0Vincent : If you experience more gaps in the modelling - feel free to make a PR or open another issue with a request. The turnaround time is typically faster, if you open a PR 😄 |





Thank you very much for reporting this.
I suspect at least for some of the cases there are some issues with the Models as Data modelling of the library methods.
With the current modelling we have
It looks like the model for
MemoryStream.MemoryStream(byte[])is incorrect (it should beArgument[0].Element -> Argument[this]- this is also the case for the other overloads of the constructor). Also the model forEncoding.GetByteslooks incorrect as taint is propagated from the argument to the return value…