Skip to content

Commit fb77e37

Browse files
committed
Swift: Add a test of SwiftUI secure fields as a sensitive data source.
1 parent 31af8b9 commit fb77e37

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
2+
// --- stubs ---
3+
4+
protocol View {
5+
}
6+
7+
struct Binding<Value> {
8+
}
9+
10+
@propertyWrapper
11+
struct State<Value> { // an @State
12+
var wrappedValue: Value
13+
var projectedValue: Binding<Value> { get { return 0 as! Binding<Value> } } // what you get with `$`
14+
}
15+
16+
struct LocalizedStringKey : ExpressibleByStringLiteral {
17+
typealias StringLiteralType = String
18+
19+
init(stringLiteral value: Self.StringLiteralType) {
20+
}
21+
}
22+
23+
struct Label<Title, Icon> : View where Title : View, Icon : View {
24+
}
25+
26+
struct Text : View {
27+
}
28+
29+
struct TextField<Label> : View where Label : View {
30+
init(_ titleKey: LocalizedStringKey, text: Binding<String>) where Label == Text { }
31+
}
32+
33+
struct SecureField<Label> : View where Label : View {
34+
init(_ titleKey: LocalizedStringKey, text: Binding<String>, prompt: Text?) where Label == Text { }
35+
}
36+
37+
struct SubmitTriggers {
38+
init(rawValue: UInt) {
39+
self.rawValue = rawValue
40+
}
41+
42+
var rawValue: UInt
43+
44+
static let text = SubmitTriggers(rawValue: 1)
45+
}
46+
47+
extension View {
48+
func onSubmit(
49+
of triggers: SubmitTriggers = .text,
50+
_ action: @escaping (() -> Void)
51+
) -> some View {
52+
return self
53+
}
54+
}
55+
56+
struct URL
57+
{
58+
init?(string: String) {}
59+
init?(string: String, relativeTo: URL?) {}
60+
}
61+
62+
// --- tests ---
63+
64+
func mkHarmlessBinding(text: Binding<String>) { }
65+
66+
struct MyStruct {
67+
@State var textInput: String = "default value"
68+
@State var secureInput: String = "default value"
69+
70+
var myView1: some View {
71+
TextField("title", text: $textInput)
72+
.onSubmit {
73+
_ = URL(string: "http://example.com/page?text=\(textInput)"); // GOOD (not sensitive)
74+
}
75+
}
76+
77+
var myView2: some View {
78+
SecureField("title", text: $secureInput, prompt: nil)
79+
.onSubmit {
80+
_ = URL(string: "http://example.com/login?key=\(secureInput)"); // BAD [NOT DETECTED]
81+
}
82+
}
83+
}

0 commit comments

Comments
 (0)