[CSharp] - Set a constructor as a source for a DataFlow analysis · github/codeql · Discussion #18647 · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi there ! First of all, thanks for this awesome project !
I've been working on some basic C# queries in order to find issues in my codebase, which are working pretty well !
However, I'm struggling to create a "basic" DataFlow analysis, and coudn't find any documentation applying to C#.
I'm trying to get catch these kinds of patterns :
namespaceCodeQLTest{[Serializable]internalclassParent{publicstringparentprop{get;set;}publicvoidstep2(){// Some sink that is hit by a tainted valueSink(this.parentprop);}}[Serializable]internalclassChild:Parent,ISerializable{publicstringbla{get;set;}// This is the source, weither it is called in the codebase or notpublicChild(SerializationInfoinfo,StreamingContextcontext){info.AddValue("bla",this.bla);this.step1()}publicvoidstep1(){this.step2();}publicvoidGetObjectData(SerializationInfoinfo,StreamingContextcontext){thrownewNotImplementedException();}}}
I don't really understand how am i supposed to create a proper isSource predicate of my DataFlow ?
Moreover, as during a deserialization process, all properties (except some special cases) can be controlled my goal would be to set all the object's properties as tainted. Do you happen to know if that is possible ?
For the isSink I would only need to create a predicate matching some Sink Method, which can be represented as so :
classProcessStartextendsMethod{ProcessStart(){hasFullyQualifiedName("System.Diagnostics.Process","Start")}}classDangerousMethodextendsCallable{DangerousMethod(){thisinstanceofProcessStart}}/* ... Within the DataFlow */predicateisSink(DataFlow::Nodesink){exists(MethodCallmc|mc.getTarget()instanceofDangerousMethodandmc.getArgument(0)=sink.asExpr())}
// This is the source, weither it is called in the codebase or not
Do you mean that any Child deserialization should be considered a source?
Some documentation about C# data flow analysis can be found here, but I'm guessing you already read through that, and it doesn't help your specific problem.
Thanks ! So I've added a isAdditionalFlowStep predicate to make it work, which is great !
However, what seams a bit odd is that the System.Runtime.Serialization.SerializationInfo.GetString should definitely be adding a taint flow by default ? In the C:\Users\Administrator\.codeql\packages\codeql\csharp-all\4.0.2\System.Runtime.Serialization.model.yaml, the following summaryModel can be found (line 52) :
Hmm, I have a hunch, that the model for GetString in SerializationInfo will make taint flow from the internal data carried by the SerializationInfo object to the return value, not from the SerializationInfo object itself. If that's the case, tainting info won't help here. Let me ask around.
@redsun82 is absolutely right, the crucial part is .SyntheticField[System.Runtime.Serialization.SerializationInfo._values].Element. If that is removed, it should work.
Hi @hvitved could you explain this : .SyntheticField[System.Runtime.Serialization.SerializationInfo._values].Element or link some documentation on this please :)
Suppose that a type T has field f which is a collection of some kind, and a function foo returns an element of that collection. To refer to that in a models-as-data model we would use argument[this].Field[T.f].Element. This allows us to track taint more precisely than making the whole class tainted when some element of some field of it is all that is tainted. Now, sometimes when we are writing models we want to do something like this, but there isn't a public field to refer to. Normally there is a private field. In this case we use SyntheticField instead of Field. Values stored in a synthetic field can only be read out by another model which refers to the synthetic field. Does that make sense?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.
Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.
🎥 Watch TMZ Live
TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi there ! First of all, thanks for this awesome project !
I've been working on some basic C# queries in order to find issues in my codebase, which are working pretty well !
However, I'm struggling to create a "basic" DataFlow analysis, and coudn't find any documentation applying to C#.
I'm trying to get catch these kinds of patterns :
I don't really understand how am i supposed to create a proper
isSource
predicate of my DataFlow ?Moreover, as during a deserialization process, all properties (except some special cases) can be controlled my goal would be to set all the object's properties as tainted. Do you happen to know if that is possible ?
For the
isSink
I would only need to create a predicate matching some Sink Method, which can be represented as so :Does this make any sense ?
Thanks ! :)
Beta Was this translation helpful? Give feedback.
All reactions