fix(admin): 13 個破壞性動作由 GET 改 POST + nonce(A1-A4)

nonce 走 query string 會經 Referer 外洩,且 GET 觸發的破壞性動作(刪快照、
cutover、promote aeav_only、清 postmeta)可被 prefetch/爬蟲觸發。對應 A v3.3.1 P1-6。

Handler 端(admin/class-tmdo-admin.php:300-700):13 個動作與其附屬參數
(post_type / count / mode / samples)全部改讀 $_POST。唯讀的 tab /
classify_type / wpdo_msg / wpdo_module 維持 GET。

渲染端改為 <form method=post> + wp_nonce_field():
- admin:重置速率統計、建立/清除快照、刪除快照、啟用 module
- dashboard-widget:跑健康檢查、建立快照、一鍵清理 postmeta
- post-migration-wizard:5 個步驟動作
- setup-wizard:建立 baseline snapshot
- post-stress-test:移除已無呼叫端的 legacy GET $cleanup_url

註:A 的 dashboard-widget 仍以 wp_nonce_url 產生 postmeta_cleanup 連結,
但其 handler 已只收 POST → 該按鈕在 A 是壞的;B 這邊一併改成 form。

unit 379 / integration 398 GREEN

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TbG1keQQ7XBa7qMQY16KCY
This commit is contained in:
2026-07-31 05:27:57 +08:00
parent 6e81dc51c5
commit 68f7f6871c
5 changed files with 119 additions and 130 deletions
+1 -7
View File
@@ -7,8 +7,7 @@
* 2. 即時進度(progress bar + processed/target/rate/ETA/peak memory
* 3. Benchmark 報告(write metrics + DB sizes + query performance
*
* Backward-compat: legacy GET ?wpdo_post_stress_create / cleanup / bench
* handlers in admin still work for bookmarked URLs; the new UI uses REST.
* The UI uses REST/AJAX exclusively; legacy admin action handlers now require POST.
*
* Variables in scope from render_post_stress_test():
* $test_post_count — int, posts matching TMDO_STRESS_TEST_ prefix
@@ -23,11 +22,6 @@ if ( ! defined( 'ABSPATH' ) ) {
$page_url = admin_url( 'tools.php?page=wp-data-optimizer&tab=post-stress-test' );
$cleanup_url = wp_nonce_url(
add_query_arg( array( 'wpdo_post_stress_cleanup' => '1' ), $page_url ),
'wpdo_post_stress_cleanup'
);
// Read-only display banner — server-set redirect message, no form processing.
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$msg_raw = isset( $_GET['wpdo_msg'] ) ? sanitize_text_field( wp_unslash( (string) $_GET['wpdo_msg'] ) ) : '';