@@ -51,13 +51,13 @@ public function process_admin() {
51
51
return ;
52
52
}
53
53
54
- if ( ! wp_verify_nonce ( $ _POST ['_wpnonce ' ], 'enable-mastodon-apps ' ) ) {
54
+ if ( ! isset ( $ _POST [ ' _wpnonce ' ] ) || ! wp_verify_nonce ( sanitize_key ( $ _POST ['_wpnonce ' ] ) , 'enable-mastodon-apps ' ) ) {
55
55
return ;
56
56
}
57
57
58
- $ tab = $ _GET ['tab ' ] ?? 'welcome ' ;
58
+ $ tab = isset ( $ _GET ['tab ' ] ) ? sanitize_key ( $ _GET [ ' tab ' ] ) : 'welcome ' ;
59
59
if ( isset ( $ _POST ['app ' ] ) ) {
60
- $ app = Mastodon_App::get_by_client_id ( $ _POST ['app ' ] );
60
+ $ app = Mastodon_App::get_by_client_id ( sanitize_text_field ( wp_unslash ( $ _POST ['app ' ] ) ) );
61
61
if ( $ app ) {
62
62
return $ this ->process_admin_app_page ( $ app );
63
63
}
@@ -78,14 +78,16 @@ public function process_admin() {
78
78
79
79
public function admin_page () {
80
80
$ this ->enable_debug = get_option ( 'mastodon_api_enable_debug ' );
81
- $ tab = $ _GET ['tab ' ] ?? 'welcome ' ;
81
+ // phpcs:disable WordPress.Security.NonceVerification.Recommended
82
+ $ tab = isset ( $ _GET ['tab ' ] ) ? sanitize_text_field ( wp_unslash ( $ _GET ['tab ' ] ) ) : 'welcome ' ;
82
83
if ( isset ( $ _GET ['app ' ] ) ) {
83
- $ app = Mastodon_App::get_by_client_id ( $ _GET ['app ' ] );
84
+ $ app = Mastodon_App::get_by_client_id ( sanitize_text_field ( wp_unslash ( $ _GET ['app ' ] ) ) );
84
85
if ( $ app ) {
85
86
return $ this ->admin_app_page ( $ app );
86
87
}
87
88
$ tab = 'registered-apps ' ;
88
89
}
90
+ // phpcs:enable
89
91
switch ( $ tab ) {
90
92
case 'welcome ' :
91
93
$ this ->admin_welcome_page ();
@@ -117,13 +119,13 @@ public function admin_welcome_page() {
117
119
}
118
120
119
121
public function process_admin_settings_page () {
120
- if ( isset ( $ _POST ['mastodon_api_enable_logins ' ] ) ) {
122
+ if ( isset ( $ _POST ['mastodon_api_enable_logins ' ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
121
123
delete_option ( 'mastodon_api_disable_logins ' );
122
124
} else {
123
125
update_option ( 'mastodon_api_disable_logins ' , true );
124
126
}
125
127
126
- if ( isset ( $ _POST ['mastodon_api_enable_debug ' ] ) ) {
128
+ if ( isset ( $ _POST ['mastodon_api_enable_debug ' ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
127
129
update_option ( 'mastodon_api_enable_debug ' , true );
128
130
} else {
129
131
delete_option ( 'mastodon_api_enable_debug ' );
@@ -141,12 +143,12 @@ public function admin_settings_page() {
141
143
}
142
144
143
145
public function process_admin_debug_page () {
144
- if ( isset ( $ _POST ['mastodon_api_debug_mode ' ] ) ) {
146
+ if ( isset ( $ _POST ['mastodon_api_debug_mode ' ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
145
147
update_option ( 'mastodon_api_debug_mode ' , time () + 5 * MINUTE_IN_SECONDS );
146
148
} else {
147
149
delete_option ( 'mastodon_api_debug_mode ' );
148
150
}
149
- if ( isset ( $ _POST ['mastodon_api_auto_app_reregister ' ] ) ) {
151
+ if ( isset ( $ _POST ['mastodon_api_auto_app_reregister ' ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
150
152
update_option ( 'mastodon_api_auto_app_reregister ' , true );
151
153
} else {
152
154
delete_option ( 'mastodon_api_auto_app_reregister ' );
@@ -162,8 +164,10 @@ public function admin_tester_page() {
162
164
}
163
165
164
166
public function process_admin_registered_apps_page () {
167
+ // phpcs:ignore WordPress.Security.NonceVerification.Missing
165
168
if ( isset ( $ _POST ['delete-code ' ] ) ) {
166
- $ deleted = $ this ->oauth ->get_code_storage ()->expireAuthorizationCode ( $ _POST ['delete-code ' ] );
169
+ // phpcs:ignore WordPress.Security.NonceVerification.Missing
170
+ $ deleted = $ this ->oauth ->get_code_storage ()->expireAuthorizationCode ( sanitize_text_field ( wp_unslash ( $ _POST ['delete-code ' ] ) ) );
167
171
add_settings_error (
168
172
'enable-mastodon-apps ' ,
169
173
'deleted-codes ' ,
@@ -177,8 +181,10 @@ public function process_admin_registered_apps_page() {
177
181
return ;
178
182
}
179
183
184
+ // phpcs:ignore WordPress.Security.NonceVerification.Missing
180
185
if ( isset ( $ _POST ['delete-token ' ] ) ) {
181
- $ deleted = $ this ->oauth ->get_token_storage ()->unsetAccessToken ( $ _POST ['delete-token ' ] );
186
+ // phpcs:ignore WordPress.Security.NonceVerification.Missing
187
+ $ deleted = $ this ->oauth ->get_token_storage ()->unsetAccessToken ( sanitize_text_field ( wp_unslash ( $ _POST ['delete-token ' ] ) ) );
182
188
add_settings_error (
183
189
'enable-mastodon-apps ' ,
184
190
'deleted-tokens ' ,
@@ -192,8 +198,10 @@ public function process_admin_registered_apps_page() {
192
198
return ;
193
199
}
194
200
201
+ // phpcs:ignore WordPress.Security.NonceVerification.Missing
195
202
if ( isset ( $ _POST ['delete-app ' ] ) ) {
196
- $ deleted = Mastodon_App::get_by_client_id ( $ _POST ['delete-app ' ] )->delete ();
203
+ // phpcs:ignore WordPress.Security.NonceVerification.Missing
204
+ $ deleted = Mastodon_App::get_by_client_id ( sanitize_text_field ( wp_unslash ( $ _POST ['delete-app ' ] ) ) )->delete ();
197
205
add_settings_error (
198
206
'enable-mastodon-apps ' ,
199
207
'deleted-apps ' ,
@@ -207,8 +215,10 @@ public function process_admin_registered_apps_page() {
207
215
return ;
208
216
}
209
217
218
+ // phpcs:ignore WordPress.Security.NonceVerification.Missing
210
219
if ( isset ( $ _POST ['clear-app-logs ' ] ) ) {
211
- $ deleted = Mastodon_App::get_by_client_id ( $ _POST ['clear-app-logs ' ] )->delete_last_requests ();
220
+ // phpcs:ignore WordPress.Security.NonceVerification.Missing
221
+ $ deleted = Mastodon_App::get_by_client_id ( sanitize_text_field ( wp_unslash ( $ _POST ['clear-app-logs ' ] ) ) )->delete_last_requests ();
212
222
if ( $ deleted ) {
213
223
add_settings_error (
214
224
'enable-mastodon-apps ' ,
@@ -226,12 +236,13 @@ public function process_admin_registered_apps_page() {
226
236
}
227
237
return ;
228
238
}
239
+ // phpcs:ignore WordPress.Security.NonceVerification.Missing
229
240
if ( isset ( $ _POST ['clear-all-app-logs ' ] ) ) {
230
241
$ total_deleted = 0 ;
231
242
foreach ( Mastodon_App::get_all () as $ app ) {
232
243
$ deleted = $ app ->delete_last_requests ();
233
244
if ( $ deleted ) {
234
- $ total_deleted += 1 ;
245
+ ++ $ total_deleted ;
235
246
}
236
247
}
237
248
if ( $ total_deleted ) {
@@ -256,15 +267,16 @@ public function process_admin_registered_apps_page() {
256
267
return ;
257
268
}
258
269
270
+ // phpcs:ignore WordPress.Security.NonceVerification.Missing
259
271
if ( isset ( $ _POST ['delete-outdated ' ] ) ) {
260
- $ apps = Mastodon_App::get_all ();
272
+ $ apps = Mastodon_App::get_all ();
261
273
$ deleted = OAuth2 \Access_Token_Storage::cleanupOldTokens ();
262
274
if ( ! $ deleted ) {
263
275
$ deleted = 0 ;
264
276
}
265
277
foreach ( OAuth2 \Access_Token_Storage::getAll () as $ token => $ data ) {
266
278
if ( ! isset ( $ apps [ $ data ['client_id ' ] ] ) ) {
267
- $ deleted += 1 ;
279
+ ++ $ deleted ;
268
280
$ this ->oauth ->get_token_storage ()->unsetAccessToken ( $ token );
269
281
}
270
282
}
@@ -287,7 +299,7 @@ public function process_admin_registered_apps_page() {
287
299
}
288
300
foreach ( OAuth2 \Authorization_Code_Storage::getAll () as $ code => $ data ) {
289
301
if ( ! isset ( $ apps [ $ data ['client_id ' ] ] ) ) {
290
- $ deleted += 1 ;
302
+ ++ $ deleted ;
291
303
$ this ->oauth ->get_code_storage ()->expireAuthorizationCode ( $ code );
292
304
}
293
305
}
@@ -321,11 +333,12 @@ public function process_admin_registered_apps_page() {
321
333
return ;
322
334
}
323
335
336
+ // phpcs:ignore WordPress.Security.NonceVerification.Missing
324
337
if ( isset ( $ _POST ['delete-never-used ' ] ) ) {
325
338
$ deleted = 0 ;
326
339
foreach ( Mastodon_App::get_all () as $ app ) {
327
340
if ( ! $ app ->get_last_used () ) {
328
- $ deleted += 1 ;
341
+ ++ $ deleted ;
329
342
$ app ->delete ();
330
343
}
331
344
}
@@ -345,7 +358,7 @@ public function process_admin_registered_apps_page() {
345
358
foreach ( OAuth2 \Access_Token_Storage::getAll () as $ token => $ data ) {
346
359
if ( empty ( $ data ['last_used ' ] ) ) {
347
360
if ( $ this ->oauth ->get_token_storage ()->unsetAccessToken ( $ token ) ) {
348
- $ deleted += 1 ;
361
+ ++ $ deleted ;
349
362
}
350
363
}
351
364
}
@@ -363,6 +376,7 @@ public function process_admin_registered_apps_page() {
363
376
return ;
364
377
}
365
378
379
+ // phpcs:ignore WordPress.Security.NonceVerification.Missing
366
380
if ( isset ( $ _POST ['delete-apps-without-tokens ' ] ) ) {
367
381
$ app_tokens = array ();
368
382
foreach ( OAuth2 \Access_Token_Storage::getAll () as $ token => $ data ) {
@@ -374,7 +388,7 @@ public function process_admin_registered_apps_page() {
374
388
$ deleted = 0 ;
375
389
foreach ( Mastodon_App::get_all () as $ app ) {
376
390
if ( empty ( $ app_tokens [ $ app ->get_client_id () ] ) ) {
377
- $ deleted += 1 ;
391
+ ++ $ deleted ;
378
392
$ app ->delete ();
379
393
}
380
394
}
@@ -391,8 +405,10 @@ public function process_admin_registered_apps_page() {
391
405
);
392
406
return ;
393
407
}
408
+ // phpcs:disable WordPress.Security.NonceVerification.Missing
394
409
if ( isset ( $ _POST ['app_post_formats ' ] ) && is_array ( $ _POST ['app_post_formats ' ] ) ) {
395
- foreach ( $ _POST ['app_post_formats ' ] as $ client_id => $ post_formats ) {
410
+ // phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
411
+ foreach ( wp_unslash ( $ _POST ['app_post_formats ' ] ) as $ client_id => $ post_formats ) {
396
412
$ post_formats = array_filter (
397
413
$ post_formats ,
398
414
function ( $ post_format ) {
@@ -464,7 +480,7 @@ function ( $a, $b ) {
464
480
public function process_admin_app_page ( Mastodon_App $ app ) {
465
481
466
482
if ( isset ( $ _POST ['delete-app ' ] ) && $ _POST ['delete-app ' ] === $ app ->get_client_id () ) {
467
- $ name = $ app ->get_client_name ();
483
+ $ name = $ app ->get_client_name ();
468
484
$ deleted = $ app ->delete ();
469
485
if ( $ deleted ) {
470
486
$ message = sprintf (
@@ -487,7 +503,7 @@ public function process_admin_app_page( Mastodon_App $app ) {
487
503
}
488
504
489
505
if ( isset ( $ _POST ['delete-token ' ] ) ) {
490
- $ deleted = $ this ->oauth ->get_token_storage ()->unsetAccessToken ( $ _POST ['delete-token ' ] );
506
+ $ deleted = $ this ->oauth ->get_token_storage ()->unsetAccessToken ( sanitize_text_field ( wp_unslash ( $ _POST ['delete-token ' ] ) ) );
491
507
add_settings_error (
492
508
'enable-mastodon-apps ' ,
493
509
'deleted-tokens ' ,
@@ -524,7 +540,7 @@ public function process_admin_app_page( Mastodon_App $app ) {
524
540
$ post_formats = array ();
525
541
if ( isset ( $ _POST ['post_formats ' ] ) && is_array ( $ _POST ['post_formats ' ] ) ) {
526
542
$ post_formats = array_filter (
527
- $ _POST ['post_formats ' ],
543
+ wp_unslash ( $ _POST ['post_formats ' ] ) ,
528
544
function ( $ post_format ) {
529
545
if ( ! in_array ( $ post_format , get_post_format_slugs (), true ) ) {
530
546
return false ;
@@ -545,15 +561,16 @@ function ( $post_type ) {
545
561
)
546
562
);
547
563
548
- if ( isset ( $ _POST ['create_post_type ' ] ) && $ _POST ['create_post_type ' ] ) {
549
- if ( isset ( $ post_types [ $ _POST ['create_post_type ' ] ] ) ) {
550
- $ app ->set_create_post_type ( $ _POST ['create_post_type ' ] );
564
+ if ( isset ( $ _POST ['create_post_type ' ] ) ) {
565
+ $ create_post_type = sanitize_text_field ( wp_unslash ( $ _POST ['create_post_type ' ] ) );
566
+ if ( isset ( $ post_types [ $ create_post_type ] ) ) {
567
+ $ app ->set_create_post_type ( $ create_post_type );
551
568
}
552
569
}
553
570
554
571
if ( isset ( $ _POST ['view_post_types ' ] ) && is_array ( $ _POST ['view_post_types ' ] ) ) {
555
572
$ view_post_types = array ();
556
- foreach ( $ _POST ['view_post_types ' ] as $ post_type ) {
573
+ foreach ( wp_unslash ( $ _POST ['view_post_types ' ] ) as $ post_type ) {
557
574
if ( isset ( $ post_types [ $ post_type ] ) ) {
558
575
$ view_post_types [ $ post_type ] = true ;
559
576
}
0 commit comments