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/issue 2768 #2845

Open
wants to merge 7 commits into
base: trunk
Choose a base branch
from
Open
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
14 changes: 10 additions & 4 deletions includes/class-sensei-frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,8 @@ public function sensei_login_form() {
<!-- Spam Trap -->
<div style="left:-999em; position:absolute;"><label for="trap"><?php esc_html_e( 'Anti-spam', 'sensei-lms' ); ?></label><input type="text" name="email_2" id="trap" tabindex="-1" /></div>

<input type="hidden" id="sensei_reg_http_referer" name="sensei_reg_http_referer" value="<?php echo wp_get_referer() ? esc_url( wp_get_referer() ) : ''; ?>">

<?php do_action( 'sensei_register_form_fields' ); ?>
<?php do_action( 'register_form' ); ?>

Expand Down Expand Up @@ -1705,6 +1707,10 @@ public function sensei_process_registration() {
$new_user_email = $_POST['sensei_reg_email'];
$new_user_password = $_POST['sensei_reg_password'];

if ( isset( $_POST['sensei_reg_http_referer'] ) && '' !== $_POST['sensei_reg_http_referer'] ) {
$new_user_http_referer = esc_url_raw( wp_unslash( $_POST['sensei_reg_http_referer'] ) );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is wp_unslash necessary?

The URL is also being double escaped. It's being escaped here and on line 1775. It's always better to escape late, so I would do the escaping further down.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to add wp_unslash and the escaping here to pass the Travis CI build. Those were the issues that blocked my first attempt...
I found this article that explains why we should use the wp_unslash for $_POST, so I think that's why the sniffer marked that as a violation.
So, what is your suggestion? Leave it like this? Add the sniffer ignore comment? Or something else?

}

// Check the username.
$username_error_notice = '';
if ( $new_user_name == '' ) {
Expand Down Expand Up @@ -1765,13 +1771,13 @@ public function sensei_process_registration() {

// Redirect.
global $wp;
if ( wp_get_referer() ) {
$redirect = esc_url( wp_get_referer() );
if ( ! empty( $new_user_http_referer ) ) {
$redirect = $new_user_http_referer;
} else {
$redirect = esc_url( home_url( $wp->request ) );
$redirect = home_url( $wp->request );
}

wp_redirect( apply_filters( 'sensei_registration_redirect', $redirect ) );
wp_safe_redirect( apply_filters( 'sensei_registration_redirect', esc_url_raw( $redirect ) ) );
exit;

} // end sensei_process_registration)()
Expand Down