Skip to content

Commit f1cc7bb

Browse files
committed
C#: Consider FileStreams StoredFlowSources and propagate taint via StreamReader.
1 parent 2b51e03 commit f1cc7bb

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

csharp/ql/lib/semmle/code/csharp/dataflow/ExternalFlow.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ module CsvValidation {
383383
or
384384
exists(string row, string kind | sourceModel(row) |
385385
kind = row.splitAt(";", 7) and
386-
not kind = "local" and
386+
not kind = ["local", "file"] and
387387
msg = "Invalid kind \"" + kind + "\" in source model."
388388
)
389389
}

csharp/ql/lib/semmle/code/csharp/frameworks/system/IO.qll

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ class SystemIOMemoryStreamClass extends SystemIOClass {
179179
}
180180
}
181181

182+
/** Data flow for `System.IO.MemoryStream`. */
182183
private class SystemIOMemoryStreamFlowModelCsv extends SummaryModelCsv {
183184
override predicate row(string row) {
184185
row =
@@ -192,3 +193,17 @@ private class SystemIOMemoryStreamFlowModelCsv extends SummaryModelCsv {
192193
]
193194
}
194195
}
196+
197+
/** Sources for `System.IO.FileStream`. */
198+
private class SystemIOFileStreamSourceModelCsv extends SourceModelCsv {
199+
override predicate row(string row) {
200+
row = "System.IO;FileStream;false;FileStream;;;Argument[Qualifier];file;manual"
201+
}
202+
}
203+
204+
/** Data flow for `System.IO.StreamReader`. */
205+
private class SystemIOStreamSummaryModelCsv extends SummaryModelCsv {
206+
override predicate row(string row) {
207+
row = "System.IO;StreamReader;false;StreamReader;;;Argument[0];Argument[Qualifier];taint;manual"
208+
}
209+
}

csharp/ql/lib/semmle/code/csharp/security/dataflow/flowsources/Stored.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44

55
import csharp
6+
private import semmle.code.csharp.dataflow.ExternalFlow
67
private import semmle.code.csharp.frameworks.system.data.Common
78
private import semmle.code.csharp.frameworks.system.data.Entity
89
private import semmle.code.csharp.frameworks.EntityFramework
@@ -55,3 +56,8 @@ class ORMMappedProperty extends StoredFlowSource {
5556
this instanceof NHibernate::StoredFlowSource
5657
}
5758
}
59+
60+
/** A file stream source is considered a stored flow source. */
61+
class FileStreamStoredFlowSource extends StoredFlowSource {
62+
FileStreamStoredFlowSource() { sourceNode(this, "file") }
63+
}

0 commit comments

Comments
 (0)