Skip to content

Commit 7251e90

Browse files
authored
Merge pull request github#12941 from geoffw0/textsource
Swift: Add taint sources for UITextField
2 parents fd62820 + f1893da commit 7251e90

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

swift/ql/lib/codeql/swift/frameworks/Frameworks.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* This file imports all models of frameworks and libraries.
33
*/
44

5+
private import Alamofire.Alamofire
56
private import StandardLibrary.StandardLibrary
7+
private import UIKit.UIKit
68
private import Xml.Xml
7-
private import Alamofire.Alamofire
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* This file imports all models of UIKit-related frameworks and libraries.
3+
*/
4+
5+
import UITextField
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Provides models for the `UITextField` Swift class.
3+
*/
4+
5+
import swift
6+
private import codeql.swift.dataflow.ExternalFlow
7+
8+
/**
9+
* A model for `UITextField` members that are flow sources.
10+
*/
11+
private class UITextFieldSource extends SourceModelCsv {
12+
override predicate row(string row) {
13+
row = [";UITextField;true;text;;;;local", ";UITextField;true;attributedText;;;;local"]
14+
}
15+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// --- stubs ---
2+
3+
class NSObject { }
4+
class NSAttributedString: NSObject {}
5+
class UIResponder: NSObject {}
6+
class UIView: UIResponder {}
7+
class UIControl: UIView {}
8+
class UITextField: UIControl {
9+
var text: String? {
10+
get { nil }
11+
set { }
12+
}
13+
var attributedText: NSAttributedString? {
14+
get { nil }
15+
set { }
16+
}
17+
var placeholder: String? {
18+
get { nil }
19+
set { }
20+
}
21+
}
22+
class UISearchTextField : UITextField {
23+
}
24+
25+
// --- tests ---
26+
27+
func testUITextField(textField: UITextField, searchTextField: UISearchTextField) {
28+
_ = textField.text // $ source=local
29+
_ = textField.attributedText // $ source=local
30+
_ = textField.placeholder // GOOD (not input)
31+
_ = textField.text?.uppercased() // $ source=local
32+
_ = searchTextField.text // $ source=local
33+
}

0 commit comments

Comments
 (0)