HEX
Server: nginx/1.18.0
System: Linux ip-172-31-28-230 6.8.0-1039-aws #41~22.04.1-Ubuntu SMP Thu Sep 11 10:54:48 UTC 2025 x86_64
User: ubuntu (1000)
PHP: 8.2.26
Disabled: NONE
Upload Files
File: /var/www/html/simplify.earth/wp-content/plugins/system-control/includes/class-sc-api-auth.php
<?php
/**
 * REST API Authentication
 */
class SC_Api_Auth {

    /**
     * Verify API key from request header
     */
    public static function verify($request) {
        $api_key = $request->get_header('X-Api-Key');
        $stored_key = get_option('sc_api_key');

        if (empty($api_key) || empty($stored_key) || !hash_equals($stored_key, $api_key)) {
            return new WP_Error('unauthorized', 'Invalid API key', ['status' => 403]);
        }

        return true;
    }

    /**
     * Verify both API key and Sec key (for sensitive operations)
     */
    public static function verify_secure($request) {
        $api_check = self::verify($request);
        if (is_wp_error($api_check)) {
            return $api_check;
        }

        $sec_key = $request->get_header('X-Sec-Key');
        $stored_sec = get_option('sc_sec_key');

        if (empty($sec_key) || empty($stored_sec) || !hash_equals($stored_sec, $sec_key)) {
            return new WP_Error('forbidden', 'Invalid Sec key', ['status' => 403]);
        }

        return true;
    }

    /**
     * Alias for verify_secure (used by update endpoint)
     */
    public static function verify_sec_key($request) {
        return self::verify_secure($request);
    }
}