@@ -4,10 +4,11 @@ template: splash
4
4
description : Explore our comprehensive collection of Android-specific rules designed to help you write better, more secure Android applications.
5
5
---
6
6
7
- import { Card , CardGrid , Icon } from ' @astrojs/starlight/components' ;
7
+ import { Card , CardGrid , Icon , Tabs , TabItem } from ' @astrojs/starlight/components' ;
8
8
import PostHogLayout from ' ../../../../layouts/PostHogLayout.astro' ;
9
9
import CollapsibleCode from ' ../../../../components/CollapsibleCode.astro' ;
10
10
import RuleSearch from ' ../../../../components/RuleSearch.astro' ;
11
+ import { ruleContent } from ' ../../../../components/CodeViewer.astro' ;
11
12
12
13
<PostHogLayout />
13
14
@@ -23,126 +24,168 @@ codepathfinder ci --project /src/project --ruleset cpf/android
23
24
24
25
#### Rules (5)
25
26
26
- <RuleSearch placeholder = " Search security rules..." owaspType = " mobile" />
27
+ Browse our collection of Android security rules. Each rule includes example code and the actual rule implementation.
28
+
29
+ <RuleSearch placeholder = " Search security rules and patterns..." />
27
30
28
31
<div class = " rule-cards-grid" >
29
32
<div class = " rule-card" data-severity = " medium" data-type = " security" data-owasp = " client-code-quality" >
30
33
<Card title = " WebView JavaScript Enabled" icon = " warning" >
31
34
<div class = " description" >
32
- ** Rule ID** : java/android/webview-javascript-enabled
33
- ** Severity: Medium** | ** CWE: 079**
35
+ ** Severity: Medium** | ** OWASP: Client Code Quality**
34
36
Enabling JavaScript execution in a WebView can result in cross-site scripting attacks.
35
37
</div >
36
38
<div class = " code-section" >
37
39
<CollapsibleCode
38
- code = { ` // ❌ Vulnerable: JavaScript enabled without safeguards
40
+ tabs = { [
41
+ {
42
+ label: " Example" ,
43
+ code: ` // ❌ Vulnerable: JavaScript enabled without safeguards
39
44
WebView webView = new WebView(context);
40
45
webView.getSettings().setJavaScriptEnabled(true);
41
46
42
47
// ✅ Safe: JavaScript disabled by default
43
48
WebView webView = new WebView(context);
44
49
// JavaScript remains disabled
45
- webView.loadUrl("https://trusted-domain.com"); ` }
46
- lang = " java"
47
- title = " WebView JavaScript Example"
48
- marks = { [' Vulnerable' , ' Safe' ]}
49
- />
50
+ webView.loadUrl("https://trusted-domain.com"); ` ,
51
+ lang: " text/x-java" ,
52
+ marks: [' Vulnerable' , ' Safe' ]
53
+ },
54
+ {
55
+ label: " Rule" ,
56
+ code: ruleContent .get (' /pathfinder-rules/android/WebViewJavaScriptEnabled.cql' ),
57
+ lang: " text/x-sql"
58
+ }
59
+ ]}
60
+ />
50
61
</div >
51
62
</Card >
52
63
</div >
53
64
54
65
<div class = " rule-card" data-severity = " medium" data-type = " security" data-owasp = " client-code-quality" >
55
66
<Card title = " WebView JavaScript Interface" icon = " warning" >
56
67
<div class = " description" >
57
- ** Rule ID** : java/android/webview-javascript-interface <br />
58
- ** Severity: Medium** | ** CWE: 079**
68
+ ** Severity: Medium** | ** OWASP: Client Code Quality**
59
69
Enabling addJavascriptInterface exposes java methods to JavaScript.
60
70
</div >
61
71
<div class = " code-section" >
62
72
<CollapsibleCode
63
- code = { ` // ❌ Vulnerable: Exposing Java interface to JavaScript
73
+ tabs = { [
74
+ {
75
+ label: " Example" ,
76
+ code: ` // ❌ Vulnerable: Exposing Java interface to JavaScript
64
77
webView.addJavascriptInterface(new JavaScriptInterface(), "Android");
65
78
66
79
// ✅ Safe: Using modern API methods
67
80
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
68
81
webView.evaluateJavascript("javascript:processData()", null);
69
- } ` }
70
- lang = " java"
71
- title = " JavaScript Interface Example"
72
- marks = { [' Vulnerable' , ' Safe' ]}
73
- />
82
+ } ` ,
83
+ lang: " text/x-java" ,
84
+ marks: [' Vulnerable' , ' Safe' ]
85
+ },
86
+ {
87
+ label: " Rule" ,
88
+ code: ruleContent .get (' /pathfinder-rules/android/WebViewaddJavascriptInterface.cql' ),
89
+ lang: " text/x-sql"
90
+ }
91
+ ]}
92
+ />
74
93
</div >
75
94
</Card >
76
95
</div >
77
96
78
97
<div class = " rule-card" data-severity = " medium" data-type = " security" data-owasp = " improper-platform-usage" >
79
98
<Card title = " WebView Content Access" icon = " warning" >
80
99
<div class = " description" >
81
- ** Rule ID** : java/android/webview-set-allow-content-access <br />
82
- ** Severity: Medium** | ** CWE: 079**
100
+ ** Severity: Medium** | ** OWASP: Improper Platform Usage**
83
101
Enabling setAllowContentAccess enables content:// access from webpages.
84
102
</div >
85
103
<div class = " code-section" >
86
104
<CollapsibleCode
87
- code = { ` // ❌ Vulnerable: Enabling content access
105
+ tabs = { [
106
+ {
107
+ label: " Example" ,
108
+ code: ` // ❌ Vulnerable: Enabling content access
88
109
webView.getSettings().setAllowContentAccess(true);
89
110
90
111
// ✅ Safe: Content access disabled
91
112
WebView webView = new WebView(context);
92
113
webView.getSettings().setAllowContentAccess(false);
93
- // Only load trusted content ` }
94
- lang = " java"
95
- title = " Content Access Example"
96
- marks = { [' Vulnerable' , ' Safe' ]}
97
- />
114
+ // Only load trusted content ` ,
115
+ lang: " text/x-java" ,
116
+ marks: [' Vulnerable' , ' Safe' ]
117
+ },
118
+ {
119
+ label: " Rule" ,
120
+ code: ruleContent .get (' /pathfinder-rules/android/WebViewsetAllowContentAccess.cql' ),
121
+ lang: " text/x-sql"
122
+ }
123
+ ]}
124
+ />
98
125
</div >
99
126
</Card >
100
127
</div >
101
128
102
129
<div class = " rule-card" data-severity = " medium" data-type = " security" data-owasp = " improper-platform-usage" >
103
130
<Card title = " WebView File Access" icon = " warning" >
104
131
<div class = " description" >
105
- ** Rule ID** : java/android/webview-set-allow-file-access <br />
106
- ** Severity: Medium** | ** CWE: 079**
132
+ ** Severity: Medium** | ** OWASP: Improper Platform Usage**
107
133
Enabling setAllowFileAccess enables webview access to file:/// URLs.
108
134
</div >
109
135
<div class = " code-section" >
110
136
<CollapsibleCode
111
- code = { ` // ❌ Vulnerable: Enabling file access
137
+ tabs = { [
138
+ {
139
+ label: " Example" ,
140
+ code: ` // ❌ Vulnerable: Enabling file access
112
141
webView.getSettings().setAllowFileAccess(true);
113
142
114
143
// ✅ Safe: File access disabled
115
144
WebView webView = new WebView(context);
116
145
webView.getSettings().setAllowFileAccess(false);
117
- // Use content providers for controlled file access ` }
118
- lang = " java"
119
- title = " File Access Example"
120
- marks = { [' Vulnerable' , ' Safe' ]}
121
- />
146
+ // Use content providers for controlled file access ` ,
147
+ lang: " text/x-java" ,
148
+ marks: [' Vulnerable' , ' Safe' ]
149
+ },
150
+ {
151
+ label: " Rule" ,
152
+ code: ruleContent .get (' /pathfinder-rules/android/WebViewsetAllowFileAccess.cql' ),
153
+ lang: " text/x-sql"
154
+ }
155
+ ]}
156
+ />
122
157
</div >
123
158
</Card >
124
159
</div >
125
160
126
161
<div class = " rule-card" data-severity = " medium" data-type = " security" data-owasp = " improper-platform-usage" >
127
162
<Card title = " WebView File URL Access" icon = " warning" >
128
163
<div class = " description" >
129
- ** Rule ID** : java/android/webview-set-allow-file-access-from-file-urls <br />
130
- ** Severity: Medium** | ** CWE: 079**
164
+ ** Severity: Medium** | ** OWASP: Improper Platform Usage**
131
165
Enabling setAllowFileAccessFromFileURLs leaks sandbox access to file:/// URLs.
132
166
</div >
133
167
<div class = " code-section" >
134
168
<CollapsibleCode
135
- code = { ` // ❌ Vulnerable: Enabling file URL access
169
+ tabs = { [
170
+ {
171
+ label: " Example" ,
172
+ code: ` // ❌ Vulnerable: Enabling file URL access
136
173
webView.getSettings().setAllowFileAccessFromFileURLs(true);
137
174
138
175
// ✅ Safe: File URL access disabled
139
176
WebView webView = new WebView(context);
140
177
webView.getSettings().setAllowFileAccessFromFileURLs(false);
141
- // Implement proper file access controls ` }
142
- lang = " java"
143
- title = " File URL Access Example"
144
- marks = { [' Vulnerable' , ' Safe' ]}
145
- />
178
+ // Implement proper file access controls ` ,
179
+ lang: " text/x-java" ,
180
+ marks: [' Vulnerable' , ' Safe' ]
181
+ },
182
+ {
183
+ label: " Rule" ,
184
+ code: ruleContent .get (' /pathfinder-rules/android/WebViewsetAllowFileAccessFromFileURLs.cql' ),
185
+ lang: " text/x-sql"
186
+ }
187
+ ]}
188
+ />
146
189
</div >
147
190
</Card >
148
191
</div >
0 commit comments