Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSRF #33

Closed
technote-space opened this issue Jan 5, 2020 · 1 comment
Closed

CSRF #33

technote-space opened this issue Jan 5, 2020 · 1 comment

Comments

@technote-space
Copy link

technote-space commented Jan 5, 2020

概要

CSRFの脆弱性が存在します。

再現手順

POSTツールでログイン状態のクッキーとともに /wp-admin/plugins.php?page=wsgsf_settings に POST
api_key=任意の文字列

期待する動作

無関係のページ等から更新されないこと

スクリーンショット

202001052349
202001052350

発生した環境

  • WP v5.3.2
  • Chrome v79.0.3945.88
  • WP Simple Spreadsheet Fetcher for Google v0.3.6

補足

add_submenu_page は権限のチェックはありますが送信元のチェック等はありません。

form に token を埋め込み更新前にチェックするようにします。

$html .= '<form id="wp2s2fg_api_spreadsheetId_form" action="' . htmlspecialchars( $_SERVER["PHP_SELF"] . '?' . $_SERVER["QUERY_STRING"] ) . '" method="POST" >';
$html .= '<div class="wp2s2fg_api_spreadsheetId_form_label">' . __( "API Key : ", 'wp-simple-spreadsheet-fetcher-for-google' ) .'</div><input type="text" name="api_key" placeholder="API-Key" value="' . esc_html( $api_key ) . '" required />';
$html .= '<br>';
$html .= '<input type="submit" value="Set Configuration Info" />';
$html .= '</form >';

public function render_settings() {
if ( isset( $_POST['api_key'] )) {
wp2s2fg_set_api_key( sanitize_text_field( $_POST['api_key'] ) );
}

もしくはSettings APIを使用します。
https://developer.wordpress.org/plugins/settings/settings-api/
https://nskw-style.com/2014/wordpress/settings-api.html

@naogify naogify mentioned this issue Jan 5, 2020
@naogify
Copy link
Owner

naogify commented Jan 5, 2020

ご指摘ありがとうございます!
バージョン0.3.7で下のように修正しました。

$html .= '<form id="wp2s2fg_api_spreadsheetId_form" action="' . htmlspecialchars( $_SERVER["PHP_SELF"] . '?' . $_SERVER["QUERY_STRING"] ) . '" method="POST" >';
$html .= '<div class="wp2s2fg_api_spreadsheetId_form_label">' . __( "API Key : ", 'wp-simple-spreadsheet-fetcher-for-google' ) .'</div><input type="text" name="api_key" placeholder="API-Key" value="' . esc_html( $api_key ) . '" required />';
$html .= '<br>';
$html .= '<input type="submit" value="Set Configuration Info" />';
$html .= wp_nonce_field( wp_create_nonce( __FILE__ ), 'wp-simple-spreadsheet-fetcher-for-google-nonce' );
$html .= '</form >';

public function render_settings() {
if ( ! empty( $_POST['api_key'] ) && check_admin_referer( wp_create_nonce( __FILE__ ), 'wp-simple-spreadsheet-fetcher-for-google-nonce' ) ) {
wp2s2fg_set_api_key( sanitize_text_field( $_POST['api_key'] ) );
}

@naogify naogify closed this as completed Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants