-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Swift: Add taint models for the Data class #11345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2284127
Add MaD rows for the Data class
atorralba d6b14a1
Update test expectations
atorralba 6a8b9fd
Add data flowsources test
atorralba 25354d2
Apply code review suggestions
atorralba e67b72d
Update test expectations
atorralba fc7c66d
Remove now unnecessary additional taint step in UnsafeJsEval
atorralba e4e5291
Fix more test expectations after rebase
atorralba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
47 changes: 46 additions & 1 deletion
47
swift/ql/lib/codeql/swift/frameworks/StandardLibrary/Data.qll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,51 @@ | ||
import swift | ||
private import codeql.swift.dataflow.ExternalFlow | ||
|
||
private class DataSources extends SourceModelCsv { | ||
override predicate row(string row) { | ||
row = ";Data;true;init(contentsOf:options:);;;ReturnValue;remote" | ||
} | ||
} | ||
|
||
private class DataSummaries extends SummaryModelCsv { | ||
override predicate row(string row) { row = ";Data;true;init(_:);;;Argument[0];ReturnValue;taint" } | ||
override predicate row(string row) { | ||
row = | ||
[ | ||
";Data;true;init(_:);;;Argument[0];ReturnValue;taint", | ||
";Data;true;init(base64Encoded:options:);;;Argument[0];ReturnValue;taint", | ||
";Data;true;init(buffer:);;;Argument[0];ReturnValue;taint", | ||
";Data;true;init(bytes:count:);;;Argument[0];ReturnValue;taint", | ||
";Data;true;init(contentsOf:options:);;;Argument[0];ReturnValue;taint", | ||
";Data;true;init(bytesNoCopy:count:deallocator:);;;Argument[0];ReturnValue;taint", | ||
";Data;true;init(referencing:);;;Argument[0];ReturnValue;taint", | ||
";Data;true;append(_:);;;Argument[0];Argument[-1];taint", | ||
";Data;true;append(_:count:);;;Argument[0];Argument[-1];taint", | ||
";Data;true;append(contentsOf:);;;Argument[0];Argument[-1];taint", | ||
";Data;true;base64EncodedData(options:);;;Argument[-1];ReturnValue;taint", | ||
";Data;true;base64EncodedString(options:);;;Argument[-1];ReturnValue;taint", | ||
";Data;true;compactMap(_:);;;Argument[-1];ReturnValue;taint", | ||
";Data;true;copyBytes(to:);;;Argument[-1];Argument[0];taint", | ||
";Data;true;copyBytes(to:count:);;;Argument[-1];Argument[0];taint", | ||
";Data;true;copyBytes(to:from:);;;Argument[-1];Argument[0];taint", | ||
";Data;true;flatMap(_:);;;Argument[-1];ReturnValue;taint", | ||
";Data;true;insert(_:at:);;;Argument[0];Argument[-1];taint", | ||
";Data;true;insert(contentsOf:at:);;;Argument[0];Argument[-1];taint", | ||
";Data;true;map(_:);;;Argument[-1];ReturnValue;taint", | ||
";Data;true;reduce(into:_:);;;Argument[-1];ReturnValue;taint", | ||
";Data;true;replace(_:with:maxReplacements:);;;Argument[1];Argument[-1];taint", | ||
";Data;true;replaceSubrange(_:with:);;;Argument[1];Argument[-1];taint", | ||
";Data;true;replaceSubrange(_:with:count:);;;Argument[1];Argument[-1];taint", | ||
";Data;true;replacing(_:with:maxReplacements:);;;Argument[1];Argument[-1];taint", | ||
";Data;true;replacing(_:with:subrange:maxReplacements:);;;Argument[1];Argument[-1];taint", | ||
// TODO: this should be implemented by a model of BidirectionalCollection | ||
// ";Data;true;reversed();;;Argument[-1];ReturnValue;taint", | ||
";Data;true;sorted();;;Argument[-1];ReturnValue;taint", | ||
";Data;true;sorted(by:);;;Argument[-1];ReturnValue;taint", | ||
";Data;true;sorted(using:);;;Argument[-1];ReturnValue;taint", | ||
";Data;true;shuffled();;;Argument[-1];ReturnValue;taint", | ||
";Data;true;shuffled(using:);;;Argument[-1];ReturnValue;taint", | ||
";Data;true;trimmingPrefix(_:);;;Argument[-1];ReturnValue;taint", | ||
";Data;true;trimmingPrefix(while:);;;Argument[-1];ReturnValue;taint" | ||
] | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
swift/ql/test/library-tests/dataflow/flowsources/data.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// --- stubs --- | ||
|
||
struct URL | ||
{ | ||
init?(string: String) {} | ||
} | ||
|
||
|
||
struct Data { | ||
struct ReadingOptions : OptionSet { let rawValue: Int } | ||
init(contentsOf: URL, options: ReadingOptions) {} | ||
} | ||
|
||
// --- tests --- | ||
|
||
func testData() { | ||
let url = URL(string: "http://example.com/") | ||
let data = try Data(contentsOf: url!, options: []) // SOURCE | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉