44
55class SensitiveBroadcast {
66
7- //Tests broadcast of access token with intent extra.
7+ // BAD - Tests broadcast of access token with intent extra.
88 public void sendBroadcast1 (Context context , String token , String refreshToken ) {
99 Intent intent = new Intent ();
1010 intent .setAction ("com.example.custom_action" );
@@ -13,33 +13,31 @@ public void sendBroadcast1(Context context, String token, String refreshToken) {
1313 context .sendBroadcast (intent );
1414 }
1515
16- //Tests broadcast of sensitive user information with intent extra.
16+ // BAD - Tests broadcast of sensitive user information with intent extra.
1717 public void sendBroadcast2 (Context context ) {
18- String username = "test123" ;
18+ String userName = "test123" ;
1919 String password = "abc12345" ;
2020
2121 Intent intent = new Intent ();
2222 intent .setAction ("com.example.custom_action" );
23- intent .putExtra ("name" , username );
23+ intent .putExtra ("name" , userName );
2424 intent .putExtra ("pwd" , password );
2525 context .sendBroadcast (intent );
2626 }
2727
28- //Tests broadcast of sensitive user information with extra bundle.
28+ // BAD - Tests broadcast of email information with extra bundle.
2929 public void sendBroadcast3 (Context context ) {
30- String username = "test123" ;
31- String password = "abc12345" ;
30+ String email =
"[email protected] " ;
3231
3332 Intent intent = new Intent ();
3433 intent .setAction ("com.example.custom_action" );
3534 Bundle bundle = new Bundle ();
36- bundle .putCharSequence ("name" , username );
37- bundle .putCharSequence ("pwd" , password );
35+ bundle .putCharSequence ("email" , email );
3836 intent .putExtras (bundle );
3937 context .sendBroadcast (intent );
4038 }
4139
42- //Tests broadcast of sensitive user information with permission using string literal .
40+ // BAD - Tests broadcast of sensitive user information with null permission .
4341 public void sendBroadcast4 (Context context ) {
4442 String username = "test123" ;
4543 String password = "abc12345" ;
@@ -48,10 +46,10 @@ public void sendBroadcast4(Context context) {
4846 intent .setAction ("com.example.custom_action" );
4947 intent .putExtra ("name" , username );
5048 intent .putExtra ("pwd" , password );
51- context .sendBroadcast (intent , "com.example.user_permission" );
49+ context .sendBroadcast (intent , null );
5250 }
5351
54- //Tests broadcast of sensitive user information with permission using string object .
52+ // GOOD - Tests broadcast of sensitive user information with permission using string literal .
5553 public void sendBroadcast5 (Context context ) {
5654 String username = "test123" ;
5755 String password = "abc12345" ;
@@ -60,12 +58,22 @@ public void sendBroadcast5(Context context) {
6058 intent .setAction ("com.example.custom_action" );
6159 intent .putExtra ("name" , username );
6260 intent .putExtra ("pwd" , password );
61+ context .sendBroadcast (intent , "com.example.user_permission" );
62+ }
63+
64+ // GOOD - Tests broadcast of access ticket with permission using string object.
65+ public void sendBroadcast6 (Context context ) {
66+ String ticket = "Tk9UIFNlY3VyZSBUaWNrZXQ=" ;
67+
68+ Intent intent = new Intent ();
69+ intent .setAction ("com.example.custom_action" );
70+ intent .putExtra ("ticket" , ticket );
6371 String perm = "com.example.user_permission" ;
6472 context .sendBroadcast (intent , perm );
6573 }
6674
67- //Tests broadcast of sensitive user information to a specific application.
68- public void sendBroadcast6 (Context context ) {
75+ // GOOD - Tests broadcast of sensitive user information to a specific application.
76+ public void sendBroadcast7 (Context context ) {
6977 String username = "test123" ;
7078 String password = "abc12345" ;
7179
@@ -77,20 +85,18 @@ public void sendBroadcast6(Context context) {
7785 context .sendBroadcast (intent );
7886 }
7987
80- //Tests broadcast of sensitive user information with multiple permissions using direct empty array initialization.
81- public void sendBroadcast7 (Context context ) {
82- String username = "test123" ;
83- String password = "abc12345" ;
88+ // BAD - Tests broadcast of access ticket with multiple permissions using direct empty array initialization.
89+ public void sendBroadcast8 (Context context ) {
90+ String ticket = "Tk9UIFNlY3VyZSBUaWNrZXQ=" ;
8491
8592 Intent intent = new Intent ();
8693 intent .setAction ("com.example.custom_action" );
87- intent .putExtra ("name" , username );
88- intent .putExtra ("pwd" , password );
94+ intent .putExtra ("ticket" , ticket );
8995 context .sendBroadcastWithMultiplePermissions (intent , new String []{});
9096 }
9197
92- //Tests broadcast of sensitive user information with multiple permissions using empty array initialization through a variable.
93- public void sendBroadcast8 (Context context ) {
98+ // BAD - Tests broadcast of sensitive user information with multiple permissions using empty array initialization through a variable.
99+ public void sendBroadcast9 (Context context ) {
94100 String username = "test123" ;
95101 String password = "abc12345" ;
96102
@@ -102,22 +108,39 @@ public void sendBroadcast8(Context context) {
102108 context .sendBroadcastWithMultiplePermissions (intent , perms );
103109 }
104110
105- // Tests broadcast of sensitive user information with multiple permissions using empty array initialization through two variables .
106- public void sendBroadcast9 (Context context ) {
111+ // GOOD - Tests broadcast of sensitive user information with multiple permissions.
112+ public void sendBroadcast10 (Context context ) {
107113 String username = "test123" ;
108114 String password = "abc12345" ;
109115
110116 Intent intent = new Intent ();
111117 intent .setAction ("com.example.custom_action" );
112- intent .putExtra ("name" , username );
113- intent .putExtra ("pwd" , password );
118+ Bundle bundle = new Bundle ();
119+ bundle .putCharSequence ("name" , username );
120+ bundle .putCharSequence ("pwd" , password );
121+ intent .putExtras (bundle );
122+ String [] perms = new String []{"com.example.custom_action" , "com.example.custom_action2" };
123+ context .sendBroadcastWithMultiplePermissions (intent , perms );
124+ }
125+
126+ // BAD - Tests broadcast of sensitive user information with multiple permissions using empty array initialization through two variables.
127+ public void sendBroadcast11 (Context context ) {
128+ String username = "test123" ;
129+ String password = "abc12345" ;
130+
131+ Intent intent = new Intent ();
132+ intent .setAction ("com.example.custom_action" );
133+ Bundle bundle = new Bundle ();
134+ bundle .putCharSequence ("name" , username );
135+ bundle .putCharSequence ("pwd" , password );
136+ intent .putExtras (bundle );
114137 String [] perms = new String [0 ];
115138 String [] perms2 = perms ;
116139 context .sendBroadcastWithMultiplePermissions (intent , perms2 );
117140 }
118141
119- //Tests broadcast of sensitive user information with ordered broadcast.
120- public void sendBroadcast10 (Context context ) {
142+ // GOOD - Tests broadcast of sensitive user information with ordered broadcast.
143+ public void sendBroadcast12 (Context context ) {
121144 String username = "test123" ;
122145 String password = "abc12345" ;
123146
0 commit comments