'AUTH_KEY', 'secure_auth_key' => 'SECURE_AUTH_KEY', 'logged_in_key' => 'LOGGED_IN_KEY', 'nonce_key' => 'NONCE_KEY', 'auth_salt' => 'AUTH_SALT', 'secure_auth_salt' => 'SECURE_AUTH_SALT', 'logged_in_salt' => 'LOGGED_IN_SALT', 'nonce_salt' => 'NONCE_SALT', ); private FindingFactory $findings; /** @var callable():array */ private $presence_source; /** * @param callable():array|null $presence_source Testable presence-only adapter. */ public function __construct( FindingFactory $findings, ?callable $presence_source = null ) { $this->findings = $findings; $this->presence_source = $presence_source ?? array( $this, 'wordpress_presence' ); } public function id(): string { // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledInText -- Stable registry machine ID. return 'wordpress.secrets_presence'; } /** * @return array */ public function execute( string $timestamp ): array { try { $presence = call_user_func( $this->presence_source ); } catch ( Throwable $exception ) { return $this->error_finding( $timestamp ); } if ( ! is_array( $presence ) ) { return $this->error_finding( $timestamp ); } $observations = array(); $missing = 0; foreach ( $presence as $type => $defined ) { if ( ! is_string( $type ) || ! array_key_exists( $type, self::SECRET_TYPES ) || ! is_bool( $defined ) ) { continue; } $observations[] = array( 'type' => $type, 'defined' => $defined, ); if ( ! $defined ) { ++$missing; } } $observed = count( $observations ); $total = count( self::SECRET_TYPES ); if ( 0 === $observed ) { $status = 'not_tested'; $coverage = 'none'; } elseif ( $missing > 0 ) { $status = 'fail'; $coverage = $observed === $total ? 'complete' : 'partial'; } elseif ( $observed < $total ) { $status = 'not_tested'; $coverage = 'partial'; } else { $status = 'pass'; $coverage = 'complete'; } return $this->findings->build( $this->id(), $status, array( 'observations' => $observations, 'method' => 'defined_constant_names_only', 'limitations' => array( 'Only whether each standard WordPress key/salt constant is defined was observed. Values and strength were not read or stored by this checker.' ), ), $observed, $total, $coverage, $timestamp ); } /** * @return array */ private function wordpress_presence(): array { $presence = array(); foreach ( self::SECRET_TYPES as $type => $constant_name ) { $presence[ $type ] = defined( $constant_name ); } return $presence; } /** * @return array */ private function error_finding( string $timestamp ): array { return $this->findings->build( $this->id(), 'error', array( 'observations' => array(), 'method' => 'defined_constant_names_only', 'limitations' => array( 'The presence-only adapter failed; no exception or secret value was stored.' ), ), 0, count( self::SECRET_TYPES ), 'error', $timestamp ); } }