Skip to content

Conversation

@Pathan-Amaankhan
Copy link
Member

@Pathan-Amaankhan Pathan-Amaankhan commented Aug 27, 2025

Description

  • This PR replaces nonce verification with a user-specific random password to prevent CSRF vulnerability.

Fixes/Covers

Copy link
Contributor

@rtBot rtBot left a comment

Choose a reason for hiding this comment

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

Code analysis identified issues

action-phpcs-code-review has identified potential problems in this pull request during automated scanning. We recommend reviewing the issues noted and that they are resolved.

phpcs scanning turned up:

⚠️ 1 warning


Powered by rtCamp's GitHub Actions Library

@Pathan-Amaankhan Pathan-Amaankhan self-assigned this Aug 28, 2025
@Pathan-Amaankhan Pathan-Amaankhan marked this pull request as ready for review August 28, 2025 08:26
@Pathan-Amaankhan Pathan-Amaankhan changed the title Fix: Nonce-based CSRF vulnerability [GH-259] Fix: Nonce-based CSRF vulnerability Aug 28, 2025
Copy link
Member

@mi5t4n mi5t4n left a comment

Choose a reason for hiding this comment

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

Left some comments, otherwise all looks good to me.

return $user;
}

delete_transient( 'google_oauth_state_' . $decoded_state['nonce'] ); // One-time use only.
Copy link
Member

Choose a reason for hiding this comment

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

Could we prefix the transient just as we do with hooks?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi @mi5t4n,
I went through the codebase and found that we are adding rtcamp. as a prefix, but if memcache/redis are not available, transients are stored in the DB. So, I will prefer not to add a special character, i.e. . in our transient key. Instead will be adding rtcamp_ as a prefix.

Please do let me know if there are any concerns about the above approach.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated in a4f9990

$state_data['provider'] = 'google';

// Store it in a transient keyed by the visitor.
set_transient( 'google_oauth_state_' . $state_data['nonce'], 1, 15 * MINUTE_IN_SECONDS );
Copy link
Member

Choose a reason for hiding this comment

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

Can we create a filter for the expiration, allowing developers to modify it as needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added filter in 4ffb514

Copy link
Contributor

@rtBot rtBot left a comment

Choose a reason for hiding this comment

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

Code analysis identified issues

action-phpcs-code-review has identified potential problems in this pull request during automated scanning. We recommend reviewing the issues noted and that they are resolved.

phpcs scanning turned up:

🚫 1 error


Powered by rtCamp's GitHub Actions Library

Copy link
Member

@mi5t4n mi5t4n left a comment

Choose a reason for hiding this comment

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

Left just 1 comment, rest looks good.

set_transient(
'rtcamp_google_oauth_state_' . $state_data['nonce'],
1,
apply_filters( 'rtcamp.google_login_oauth_state_expiration', 15 * MINUTE_IN_SECONDS )
Copy link
Member

Choose a reason for hiding this comment

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

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

Successfully merging this pull request may close these issues.

4 participants