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

Fix notice vulnerability issue. #350

Merged
merged 4 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion assets/js/admin-notice.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
$(document).on("click", '.wemail-connect-notice-flex-container .notice-dismiss', function() {
var url = new URL(location.href);
url.searchParams.append("dismiss_connect_notice", 1);
url.searchParams.append("wemail_dismiss_notice_nonce", wemail_notice_nonce.nonce);
location.href = url;
});
});
})(jQuery);
})(jQuery);
13 changes: 11 additions & 2 deletions includes/Admin/Notice.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public function enqueue_assets() {

wp_enqueue_style( 'wemail-admin-notice-style' );
wp_enqueue_script( 'wemail-admin-notice-script' );

wp_localize_script(
'wemail-admin-notice-script', 'wemail_notice_nonce', array(
'nonce' => wp_create_nonce( 'wemail_dismiss_notice_nonce' ),
)
);
}

/**
Expand All @@ -48,7 +54,7 @@ public function connect_notice_html() {
<p><?php echo __( 'You are one step closer to use weMail. Connect your site to get started with weMail. With weMail, you can send marketing and transactional emails to your audience.', 'wemail' ); ?></p>
</div>
<div class="wemail-connect-notice-connect-button">
<a class="button" href="<?php echo wemail()->wemail_app . '/connect?email=' . urlencode( wp_get_current_user()->user_email ) . '&site_name=' . urlencode( get_bloginfo( 'name' ) ) . '&site_url=' . urlencode( site_url( '/' ) ) . '&redirect_url=' . urlencode( admin_url( 'admin.php?page=wemail' ) ); ?>">Connect</a>
<a class="button" href="<?php echo wemail()->wemail_app . '/connect?email=' . rawurlencode( wp_get_current_user()->user_email ) . '&site_name=' . rawurlencode( get_bloginfo( 'name' ) ) . '&site_url=' . rawurlencode( site_url( '/' ) ) . '&redirect_url=' . rawurlencode( admin_url( 'admin.php?page=wemail' ) ); ?>">Connect</a>
</div>
</div>
<?php
Expand All @@ -61,11 +67,14 @@ public function connect_notice_html() {
*/
public function connect_notice() {
if ( isset( $_GET['dismiss_connect_notice'] ) && (int) $_GET['dismiss_connect_notice'] === 1 ) {
update_option( 'wemail_site_connection_notice', 1 );
if ( isset( $_GET['wemail_dismiss_notice_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['wemail_dismiss_notice_nonce'] ) ), 'wemail_dismiss_notice_nonce' ) ) {
update_option( 'wemail_site_connection_notice', 1 );
}
}
if ( ! get_user_meta( get_current_user_id(), 'wemail_api_key', true ) && (int) get_option( 'wemail_site_connection_notice' ) !== 1 && ! ( isset( $_GET['page'] ) && $_GET['page'] === 'wemail' ) ) {
add_action( 'admin_notices', [ $this, 'connect_notice_html' ] );
}
}

}

Loading