Skip to content

Commit

Permalink
refactor getWpScanApiToken to only return if it's defined
Browse files Browse the repository at this point in the history
don't use PANTHEON_WPVULNDB_API_TOKEN as a fallback
  • Loading branch information
jazzsequence committed May 19, 2023
1 parent e10a8a8 commit 44f4581
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions php/pantheon/checks/plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,28 +122,23 @@ protected function getPluginVulnerability( $plugin_slug )


protected function getWpScanApiToken() {
if( !defined( 'PANTHEON_WPSCAN_ENVIRONMENTS' ) ) {
return false;
}

if ( ! is_array( PANTHEON_WPSCAN_ENVIRONMENTS ) ) {
$environments = explode( ',', PANTHEON_WPSCAN_ENVIRONMENTS );
} else {
$environments = PANTHEON_WPSCAN_ENVIRONMENTS;
}
if ( defined( 'WPSCAN_API_TOKEN' ) ) {
// Don't use WPSCAN if PANTHEON_WPSCAN_ENVIRONMENTS have not been specified.
if( ! defined( 'PANTHEON_WPSCAN_ENVIRONMENTS' ) ) {
return false;
}

if(
!in_array( getenv( 'PANTHEON_ENVIRONMENT' ), $environments )
&& !in_array( '*', $environments )
) {
return false;
}
$environments = ( ! is_array( PANTHEON_WPSCAN_ENVIRONMENTS ) ) ? explode( ',', PANTHEON_WPSCAN_ENVIRONMENTS ) : PANTHEON_WPSCAN_ENVIRONMENTS;

if( defined( 'WPSCAN_API_TOKEN' ) ) {
return WPSCAN_API_TOKEN;
// Only run WPSCAN on the specified environments unless it's been configured to run on all (*).
if ( in_array( getenv( 'PANTHEON_ENVIRONMENT' ), $environments, true ) || in_array( '*', $environments, true ) ) {
return WPSCAN_API_TOKEN;
}
}

return getenv( 'PANTHEON_WPVULNDB_API_TOKEN' );
// TODO: Replace this PANTHEON_WPVULNDB_API_TOKEN with a new Patchstack API token.
// return getenv( 'PANTHEON_WPVULNDB_API_TOKEN' );
return false;
}

/**
Expand Down

0 comments on commit 44f4581

Please sign in to comment.