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

Replace Woopay’s Development Environment Constants With Global Variables #9019

Merged
merged 9 commits into from
Jul 23, 2024
4 changes: 4 additions & 0 deletions changelog/fix-2740-woopay-remove-hard-coded-secrets
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Replace hard-coded development blog-token secret with DEV_BLOG_TOKEN_SECRET global variable.
25 changes: 23 additions & 2 deletions includes/woopay/class-woopay-utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,35 @@ public static function get_woopay_url() {
return defined( 'PLATFORM_CHECKOUT_HOST' ) ? PLATFORM_CHECKOUT_HOST : self::DEFAULT_WOOPAY_URL;
}

/**
* Get the store blog token.
*
* @return mixed|string the store blog token.
*/
public static function get_store_blog_token() {
if ( self::get_woopay_url() === self::DEFAULT_WOOPAY_URL ) {
// Using WooPay production: Use the blog token secret from the store blog.
return Jetpack_Options::get_option( 'blog_token' );
} elseif ( apply_filters( 'wcpay_woopay_use_blog_token', false ) ) {
// Requested to use the blog token secret from the store blog.
return Jetpack_Options::get_option( 'blog_token' );
} elseif ( defined( 'DEV_BLOG_TOKEN_SECRET' ) ) {
// Has a defined dev blog token secret: Use it.
return DEV_BLOG_TOKEN_SECRET;
} else {
// TODO: Should we log this?
cesarcosta99 marked this conversation as resolved.
Show resolved Hide resolved
return '';
}
}

/**
* Return an array with encrypted and signed data.
*
* @param array $data The data to be encrypted and signed.
* @return array The encrypted and signed data.
*/
public static function encrypt_and_sign_data( $data ) {
$store_blog_token = ( self::get_woopay_url() === self::DEFAULT_WOOPAY_URL ) ? Jetpack_Options::get_option( 'blog_token' ) : 'dev_mode';
$store_blog_token = self::get_store_blog_token();

if ( empty( $store_blog_token ) ) {
return [];
Expand Down Expand Up @@ -295,7 +316,7 @@ public static function encrypt_and_sign_data( $data ) {
* @return mixed The decoded data.
*/
public static function decrypt_signed_data( $data ) {
$store_blog_token = ( self::get_woopay_url() === self::DEFAULT_WOOPAY_URL ) ? Jetpack_Options::get_option( 'blog_token' ) : 'dev_mode';
$store_blog_token = self::get_store_blog_token();

if ( empty( $store_blog_token ) ) {
return null;
Expand Down
Loading