roles ) ); } /* --------------------------------- REST ---------------------------------- */ public static function routes() { $ns = Softvolt_Ai_Bodyguard_Rest::NS; $self = function () { return is_user_logged_in(); }; $public = '__return_true'; foreach ( array( array( '/passkeys/register-options', 'rest_register_options', $self ), array( '/passkeys/register', 'rest_register', $self ), array( '/passkeys/remove', 'rest_remove', $self ), array( '/passkeys/login-options', 'rest_login_options', $public ), array( '/passkeys/login', 'rest_login', $public ), ) as $r ) { register_rest_route( $ns, $r[0], array( 'methods' => 'POST', 'callback' => array( __CLASS__, $r[1] ), 'permission_callback' => $r[2], ) ); } } private static function reply( $data, $status = 200 ) { if ( is_wp_error( $data ) ) { $data = array( 'ok' => false, 'error' => wp_strip_all_tags( $data->get_error_message() ), 'code' => $data->get_error_code() ); $status = 200 === $status ? 400 : $status; } $response = new WP_REST_Response( $data, $status ); $response->header( 'Cache-Control', 'no-store' ); return $response; } public static function rest_register_options( $request ) { $user = wp_get_current_user(); if ( ! self::allowed_for( $user ) ) { return self::reply( new WP_Error( 'svabg_passkey_role', __( 'Passkeys are not offered to your role on this site.', 'ai-guardwall' ) ), 403 ); } $options = self::register_options( $user->ID ); return self::reply( is_wp_error( $options ) ? $options : array( 'ok' => true, 'publicKey' => $options ) ); } public static function rest_register( $request ) { $user = wp_get_current_user(); if ( ! self::allowed_for( $user ) ) { return self::reply( new WP_Error( 'svabg_passkey_role', __( 'Passkeys are not offered to your role on this site.', 'ai-guardwall' ) ), 403 ); } $pk = self::register( $user->ID, (array) $request->get_json_params() ); return self::reply( is_wp_error( $pk ) ? $pk : array( 'ok' => true, 'passkey' => $pk ) ); } public static function rest_remove( $request ) { $user_id = (int) $request->get_param( 'user' ); $user_id = $user_id ? $user_id : get_current_user_id(); if ( get_current_user_id() !== $user_id && ! current_user_can( 'edit_user', $user_id ) ) { return self::reply( new WP_Error( 'svabg_passkey_forbidden', __( 'You cannot change this user.', 'ai-guardwall' ) ), 403 ); } $done = self::remove( $user_id, (string) $request->get_param( 'id' ) ); return self::reply( $done ? array( 'ok' => true ) : new WP_Error( 'svabg_passkey_unknown', __( 'Passkey not found.', 'ai-guardwall' ) ) ); } public static function rest_login_options( $request ) { $limit = self::rate_limited(); if ( $limit ) { return self::reply( $limit, 429 ); } return self::reply( array_merge( array( 'ok' => true ), self::login_options() ) ); } /** * Sign in: the same gates as the password form (lockouts, pending * approval), and the passkey counts as the second factor. */ public static function rest_login( $request ) { $limit = self::rate_limited(); if ( $limit ) { return self::reply( $limit, 429 ); } $ip = Softvolt_Ai_Bodyguard_Helpers::client_ip(); if ( Softvolt_Ai_Bodyguard_Lockouts::is_blocked( $ip ) ) { return self::reply( new WP_Error( 'svabg_locked', __( 'Too many failed logins from your address. Try again later.', 'ai-guardwall' ) ), 403 ); } $user = self::verify_login( (array) $request->get_json_params() ); if ( is_wp_error( $user ) ) { if ( ! in_array( $user->get_error_code(), array( 'svabg_passkey_expired' ), true ) ) { Softvolt_Ai_Bodyguard_Login_Security::failed( __( '(passkey)', 'ai-guardwall' ) ); } return self::reply( $user, 403 ); } if ( class_exists( 'Softvolt_Ai_Bodyguard_Access' ) ) { $pending = Softvolt_Ai_Bodyguard_Access::refuse_pending( $user ); if ( is_wp_error( $pending ) ) { return self::reply( $pending, 403 ); } } /** * Last chance to refuse a passkey sign-in (return a WP_Error). * * @since 1.4.0 * @param WP_User $user The user the passkey belongs to. */ $user = apply_filters( 'svabg_passkey_authenticate', $user ); if ( is_wp_error( $user ) ) { return self::reply( $user, 403 ); } Softvolt_Ai_Bodyguard_Two_Factor::passkey_login(); wp_set_auth_cookie( $user->ID, true, is_ssl() ); wp_set_current_user( $user->ID ); do_action( 'wp_login', $user->user_login, $user ); Softvolt_Ai_Bodyguard_Logger::log( 'info', 'login', sprintf( /* translators: %s: user login */ __( '"%s" signed in with a passkey.', 'ai-guardwall' ), $user->user_login ), array(), $user->ID ); $redirect = esc_url_raw( (string) $request->get_param( 'redirect' ) ); $redirect = wp_validate_redirect( $redirect, admin_url() ); $redirect = apply_filters( 'login_redirect', $redirect, $redirect, $user ); return self::reply( array( 'ok' => true, 'redirect' => wp_validate_redirect( $redirect, admin_url() ) ) ); } /** * At most 30 passkey requests per address in ten minutes. */ private static function rate_limited() { $count = Softvolt_Ai_Bodyguard_Firewall::count( 'svabg_pk_rl_' . md5( Softvolt_Ai_Bodyguard_Helpers::client_ip() ), 10 * MINUTE_IN_SECONDS ); return $count > 30 ? new WP_Error( 'svabg_passkey_rate', __( 'Too many passkey requests. Wait a few minutes.', 'ai-guardwall' ) ) : null; } /* ------------------------------- helpers ------------------------------- */ public static function b64u_encode( $bin ) { return rtrim( strtr( base64_encode( (string) $bin ), '+/', '-_' ), '=' ); } public static function b64u_decode( $text ) { $text = strtr( (string) $text, '-_', '+/' ); $pad = strlen( $text ) % 4; if ( $pad ) { $text .= str_repeat( '=', 4 - $pad ); } $out = base64_decode( $text, true ); return false === $out ? '' : $out; } /** * The relying party: the site's host name, and the exact origins allowed. */ public static function rp_id() { return (string) apply_filters( 'svabg_passkey_rp_id', strtolower( (string) wp_parse_url( home_url(), PHP_URL_HOST ) ) ); } public static function origins() { $out = array(); foreach ( array( home_url(), site_url(), admin_url() ) as $url ) { $p = wp_parse_url( $url ); if ( ! empty( $p['scheme'] ) && ! empty( $p['host'] ) ) { $out[] = strtolower( $p['scheme'] . '://' . $p['host'] . ( ! empty( $p['port'] ) ? ':' . $p['port'] : '' ) ); } } return array_values( array_unique( $out ) ); } /** * Passkeys work on HTTPS, and on localhost for development. */ public static function secure_context() { $host = self::rp_id(); return 'https' === wp_parse_url( home_url(), PHP_URL_SCHEME ) || 'localhost' === $host || '127.0.0.1' === $host || preg_match( '/\.localhost$/', $host ); } public static function user_passkeys( $user_id ) { $list = get_user_meta( $user_id, self::META, true ); return is_array( $list ) ? $list : array(); } private static function save_passkeys( $user_id, array $list ) { update_user_meta( $user_id, self::META, array_values( $list ) ); delete_user_meta( $user_id, self::META_ID ); foreach ( $list as $pk ) { add_user_meta( $user_id, self::META_ID, $pk['id'] ); } } private static function user_handle( $user_id ) { $handle = (string) get_user_meta( $user_id, 'svabg_passkey_handle', true ); if ( '' === $handle ) { $handle = self::b64u_encode( random_bytes( 16 ) ); update_user_meta( $user_id, 'svabg_passkey_handle', $handle ); } return $handle; } /* ------------------------------ registration ------------------------------ */ /** * Options for navigator.credentials.create(). */ public static function register_options( $user_id ) { $user = get_userdata( $user_id ); if ( ! $user ) { return new WP_Error( 'svabg_passkey_user', __( 'User not found.', 'ai-guardwall' ) ); } $challenge = random_bytes( 32 ); set_transient( 'svabg_pk_reg_' . $user_id, self::b64u_encode( $challenge ), 5 * MINUTE_IN_SECONDS ); $exclude = array(); foreach ( self::user_passkeys( $user_id ) as $pk ) { $exclude[] = array( 'type' => 'public-key', 'id' => $pk['id'] ); } return array( 'challenge' => self::b64u_encode( $challenge ), 'rp' => array( 'name' => wp_specialchars_decode( (string) get_option( 'blogname' ), ENT_QUOTES ), 'id' => self::rp_id() ), 'user' => array( 'id' => self::user_handle( $user_id ), 'name' => $user->user_login, 'displayName' => $user->display_name ), 'pubKeyCredParams' => array( array( 'type' => 'public-key', 'alg' => -7 ), array( 'type' => 'public-key', 'alg' => -257 ) ), 'timeout' => 120000, 'attestation' => 'none', 'excludeCredentials' => $exclude, 'authenticatorSelection' => array( 'residentKey' => 'required', 'requireResidentKey' => true, 'userVerification' => 'preferred' ), ); } /** * Check the browser's answer to create() and store the passkey. * * @param int $user_id User. * @param array $in id, clientDataJSON, attestationObject (base64url), name, transports. * @return array|WP_Error The stored passkey (without the key). */ public static function register( $user_id, array $in ) { $expected = get_transient( 'svabg_pk_reg_' . $user_id ); delete_transient( 'svabg_pk_reg_' . $user_id ); if ( ! $expected ) { return new WP_Error( 'svabg_passkey_expired', __( 'The request timed out. Please try again.', 'ai-guardwall' ) ); } $client = self::check_client_data( self::b64u_decode( $in['clientDataJSON'] ?? '' ), 'webauthn.create', $expected ); if ( is_wp_error( $client ) ) { return $client; } try { $att = self::cbor_decode( self::b64u_decode( $in['attestationObject'] ?? '' ) ); } catch ( Exception $e ) { return new WP_Error( 'svabg_passkey_cbor', __( 'The authenticator sent data that could not be read.', 'ai-guardwall' ) ); } if ( ! is_array( $att ) || ! isset( $att['authData'] ) || ! is_string( $att['authData'] ) ) { return new WP_Error( 'svabg_passkey_att', __( 'The authenticator sent no authenticator data.', 'ai-guardwall' ) ); } $auth = self::parse_auth_data( $att['authData'], true ); if ( is_wp_error( $auth ) ) { return $auth; } $pem = self::cose_to_pem( $auth['key'] ); if ( is_wp_error( $pem ) ) { return $pem; } $id = self::b64u_encode( $auth['cred_id'] ); if ( ( $in['id'] ?? '' ) !== $id ) { return new WP_Error( 'svabg_passkey_id', __( 'The credential ID does not match.', 'ai-guardwall' ) ); } if ( self::owner_of( $id ) ) { return new WP_Error( 'svabg_passkey_dup', __( 'This passkey is already registered.', 'ai-guardwall' ) ); } $list = self::user_passkeys( $user_id ); $name = trim( sanitize_text_field( (string) ( $in['name'] ?? '' ) ) ); $pk = array( 'id' => $id, 'pem' => $pem['pem'], 'alg' => $pem['alg'], 'count' => (int) $auth['count'], 'name' => '' !== $name ? mb_substr( $name, 0, 60 ) : sprintf( /* translators: %d: number */ __( 'Passkey %d', 'ai-guardwall' ), count( $list ) + 1 ), 'created' => time(), 'last_used' => 0, 'transports' => array_values( array_intersect( (array) ( $in['transports'] ?? array() ), array( 'usb', 'nfc', 'ble', 'internal', 'hybrid', 'smart-card' ) ) ), 'uv' => (bool) $auth['uv'], ); $list[] = $pk; self::save_passkeys( $user_id, $list ); Softvolt_Ai_Bodyguard_Logger::log( 'notice', 'passkey', sprintf( /* translators: %s: name */ __( 'Passkey "%s" added.', 'ai-guardwall' ), $pk['name'] ), array(), $user_id ); unset( $pk['pem'] ); return $pk; } public static function remove( $user_id, $id ) { $list = self::user_passkeys( $user_id ); $keep = array_values( array_filter( $list, function ( $pk ) use ( $id ) { return $pk['id'] !== $id; } ) ); if ( count( $keep ) === count( $list ) ) { return false; } self::save_passkeys( $user_id, $keep ); Softvolt_Ai_Bodyguard_Logger::log( 'notice', 'passkey', __( 'A passkey was removed.', 'ai-guardwall' ), array(), $user_id ); return true; } /* --------------------------------- sign-in -------------------------------- */ /** * Options for navigator.credentials.get() (usernameless: any passkey of this site). */ public static function login_options() { $challenge = random_bytes( 32 ); $token = wp_generate_password( 32, false, false ); set_transient( 'svabg_pk_login_' . hash( 'sha256', $token ), self::b64u_encode( $challenge ), 5 * MINUTE_IN_SECONDS ); return array( 'token' => $token, 'publicKey' => array( 'challenge' => self::b64u_encode( $challenge ), 'rpId' => self::rp_id(), 'timeout' => 120000, 'userVerification' => 'preferred', 'allowCredentials' => array(), ), ); } /** * Verify an assertion and return the user it signs in. * * @param array $in token, id, clientDataJSON, authenticatorData, signature, userHandle (base64url). * @return WP_User|WP_Error */ public static function verify_login( array $in ) { $key = 'svabg_pk_login_' . hash( 'sha256', (string) ( $in['token'] ?? '' ) ); $expected = get_transient( $key ); delete_transient( $key ); if ( ! $expected ) { return new WP_Error( 'svabg_passkey_expired', __( 'The sign-in request timed out. Please try again.', 'ai-guardwall' ) ); } $id = (string) ( $in['id'] ?? '' ); $user_id = self::owner_of( $id ); if ( ! $user_id ) { return new WP_Error( 'svabg_passkey_unknown', __( 'This passkey is not registered on this site.', 'ai-guardwall' ) ); } $list = self::user_passkeys( $user_id ); $idx = null; foreach ( $list as $i => $pk ) { if ( $pk['id'] === $id ) { $idx = $i; break; } } if ( null === $idx ) { return new WP_Error( 'svabg_passkey_unknown', __( 'This passkey is not registered on this site.', 'ai-guardwall' ) ); } $client_json = self::b64u_decode( $in['clientDataJSON'] ?? '' ); $client = self::check_client_data( $client_json, 'webauthn.get', $expected ); if ( is_wp_error( $client ) ) { return $client; } $auth_data = self::b64u_decode( $in['authenticatorData'] ?? '' ); $auth = self::parse_auth_data( $auth_data, false ); if ( is_wp_error( $auth ) ) { return $auth; } $signature = self::b64u_decode( $in['signature'] ?? '' ); $ok = function_exists( 'openssl_verify' ) ? openssl_verify( $auth_data . hash( 'sha256', $client_json, true ), $signature, $list[ $idx ]['pem'], OPENSSL_ALGO_SHA256 ) : -1; if ( 1 !== $ok ) { Softvolt_Ai_Bodyguard_Logger::log( 'warning', 'login_failed', __( 'A passkey sign-in had an invalid signature.', 'ai-guardwall' ), array(), $user_id ); return new WP_Error( 'svabg_passkey_signature', __( 'The passkey signature is not valid.', 'ai-guardwall' ) ); } // A counter that does not grow means the key may have been cloned. $old = (int) $list[ $idx ]['count']; if ( ( $auth['count'] > 0 || $old > 0 ) && $auth['count'] <= $old ) { Softvolt_Ai_Bodyguard_Logger::log( 'critical', 'login_failed', __( 'A passkey sign-in was refused: its counter went backwards (possible cloned key).', 'ai-guardwall' ), array(), $user_id ); return new WP_Error( 'svabg_passkey_counter', __( 'This passkey could not be verified. Remove it from your profile and add it again.', 'ai-guardwall' ) ); } $list[ $idx ]['count'] = (int) $auth['count']; $list[ $idx ]['last_used'] = time(); update_user_meta( $user_id, self::META, $list ); $user = get_userdata( $user_id ); return $user ? $user : new WP_Error( 'svabg_passkey_user', __( 'User not found.', 'ai-guardwall' ) ); } /** * The user a credential belongs to (0 when none). */ public static function owner_of( $id ) { global $wpdb; if ( '' === (string) $id ) { return 0; } return (int) $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = %s AND meta_value = %s LIMIT 1", self::META_ID, $id ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery } /* ------------------------------ verification ------------------------------ */ private static function check_client_data( $json, $type, $expected_challenge ) { $data = json_decode( (string) $json, true ); if ( ! is_array( $data ) ) { return new WP_Error( 'svabg_passkey_client', __( 'The browser sent no client data.', 'ai-guardwall' ) ); } if ( ( $data['type'] ?? '' ) !== $type ) { return new WP_Error( 'svabg_passkey_type', __( 'Wrong kind of passkey request.', 'ai-guardwall' ) ); } if ( ! hash_equals( (string) $expected_challenge, (string) ( $data['challenge'] ?? '' ) ) ) { return new WP_Error( 'svabg_passkey_challenge', __( 'The passkey answered a different request.', 'ai-guardwall' ) ); } if ( ! in_array( strtolower( (string) ( $data['origin'] ?? '' ) ), self::origins(), true ) ) { return new WP_Error( 'svabg_passkey_origin', __( 'The passkey was used on a different website address.', 'ai-guardwall' ) ); } return $data; } /** * rpIdHash(32) flags(1) signCount(4) [aaguid(16) idLen(2) id key(CBOR)]. */ private static function parse_auth_data( $bin, $with_credential ) { if ( strlen( $bin ) < 37 ) { return new WP_Error( 'svabg_passkey_auth', __( 'The authenticator data is too short.', 'ai-guardwall' ) ); } if ( ! hash_equals( hash( 'sha256', self::rp_id(), true ), substr( $bin, 0, 32 ) ) ) { return new WP_Error( 'svabg_passkey_rp', __( 'The passkey belongs to a different website.', 'ai-guardwall' ) ); } $flags = ord( $bin[32] ); if ( ! ( $flags & 0x01 ) ) { return new WP_Error( 'svabg_passkey_presence', __( 'The authenticator did not confirm that a person was present.', 'ai-guardwall' ) ); } $out = array( 'uv' => (bool) ( $flags & 0x04 ), 'count' => unpack( 'N', substr( $bin, 33, 4 ) )[1], ); if ( ! $with_credential ) { return $out; } if ( ! ( $flags & 0x40 ) || strlen( $bin ) < 55 ) { return new WP_Error( 'svabg_passkey_nocred', __( 'The authenticator sent no new credential.', 'ai-guardwall' ) ); } $len = unpack( 'n', substr( $bin, 53, 2 ) )[1]; $out['cred_id'] = substr( $bin, 55, $len ); try { $offset = 55 + $len; $out['key'] = self::cbor_decode( $bin, $offset ); } catch ( Exception $e ) { return new WP_Error( 'svabg_passkey_key', __( 'The public key could not be read.', 'ai-guardwall' ) ); } return $out; } /** * COSE key → PEM (ES256 on P-256, RS256). */ public static function cose_to_pem( $key ) { if ( ! is_array( $key ) || ! isset( $key[1], $key[3] ) ) { return new WP_Error( 'svabg_passkey_cose', __( 'Unsupported key format.', 'ai-guardwall' ) ); } if ( 2 === $key[1] && -7 === $key[3] && 1 === ( $key[-1] ?? 0 ) && isset( $key[-2], $key[-3] ) && is_string( $key[-2] ) && is_string( $key[-3] ) && 32 === strlen( $key[-2] ) && 32 === strlen( $key[-3] ) ) { $der = hex2bin( '3059301306072a8648ce3d020106082a8648ce3d030107034200' ) . "\x04" . $key[-2] . $key[-3]; return array( 'alg' => -7, 'pem' => self::pem( $der ) ); } if ( 3 === $key[1] && -257 === $key[3] && isset( $key[-1], $key[-2] ) && is_string( $key[-1] ) && is_string( $key[-2] ) && strlen( $key[-1] ) >= 256 ) { $n = self::der_int( $key[-1] ); $e = self::der_int( $key[-2] ); $rsa = self::der( 0x30, $n . $e ); $alg = self::der( 0x30, hex2bin( '06092a864886f70d0101010500' ) ); $der = self::der( 0x30, $alg . self::der( 0x03, "\x00" . $rsa ) ); return array( 'alg' => -257, 'pem' => self::pem( $der ) ); } return new WP_Error( 'svabg_passkey_alg', __( 'This passkey uses a key type this site does not accept (use ES256 or RS256).', 'ai-guardwall' ) ); } private static function pem( $der ) { return "-----BEGIN PUBLIC KEY-----\n" . chunk_split( base64_encode( $der ), 64, "\n" ) . "-----END PUBLIC KEY-----\n"; } private static function der_len( $n ) { if ( $n < 0x80 ) { return chr( $n ); } $bytes = ltrim( pack( 'N', $n ), "\x00" ); return chr( 0x80 | strlen( $bytes ) ) . $bytes; } private static function der( $tag, $content ) { return chr( $tag ) . self::der_len( strlen( $content ) ) . $content; } private static function der_int( $bin ) { $bin = ltrim( $bin, "\x00" ); if ( '' === $bin || ord( $bin[0] ) & 0x80 ) { $bin = "\x00" . $bin; } return self::der( 0x02, $bin ); } /** * A small CBOR decoder (RFC 8949): integers, byte and text strings, arrays, maps, simple values. * * @param string $bin Data. * @param int $offset Start; advanced past the item. * @return mixed * @throws Exception On malformed input. */ public static function cbor_decode( $bin, &$offset = 0 ) { $len = strlen( $bin ); if ( $offset >= $len ) { throw new Exception( 'cbor: end of data' ); } $byte = ord( $bin[ $offset++ ] ); $major = $byte >> 5; $info = $byte & 0x1f; $val = self::cbor_arg( $bin, $offset, $info ); switch ( $major ) { case 0: return $val; case 1: return -1 - $val; case 2: case 3: if ( $offset + $val > $len ) { throw new Exception( 'cbor: string past the end' ); } $s = substr( $bin, $offset, $val ); $offset += $val; return $s; case 4: $out = array(); for ( $i = 0; $i < $val; $i++ ) { $out[] = self::cbor_decode( $bin, $offset ); } return $out; case 5: $out = array(); for ( $i = 0; $i < $val; $i++ ) { $k = self::cbor_decode( $bin, $offset ); $out[ $k ] = self::cbor_decode( $bin, $offset ); } return $out; case 6: return self::cbor_decode( $bin, $offset ); // A tag: the value that follows. case 7: if ( 20 === $info ) { return false; } if ( 21 === $info ) { return true; } return null; } throw new Exception( 'cbor: bad type' ); } private static function cbor_arg( $bin, &$offset, $info ) { if ( $info < 24 ) { return $info; } $sizes = array( 24 => 1, 25 => 2, 26 => 4, 27 => 8 ); if ( ! isset( $sizes[ $info ] ) || $offset + $sizes[ $info ] > strlen( $bin ) ) { throw new Exception( 'cbor: indefinite or bad length' ); } $raw = substr( $bin, $offset, $sizes[ $info ] ); $offset += $sizes[ $info ]; switch ( $sizes[ $info ] ) { case 1: return ord( $raw ); case 2: return unpack( 'n', $raw )[1]; case 4: return unpack( 'N', $raw )[1]; default: return unpack( 'J', $raw )[1]; } } /* ----------------------------------- UI ----------------------------------- */ public static function profile_section( $user ) { $own = get_current_user_id() === (int) $user->ID && self::allowed_for( $user ); $list = self::user_passkeys( $user->ID ); if ( ! $own && ! $list ) { return; } ?>

esc_url_raw( rest_url( Softvolt_Ai_Bodyguard_Rest::NS . '/passkeys' ) ), 'nonce' => wp_create_nonce( 'wp_rest' ), 'secure' => self::secure_context(), 'i18n' => array( 'adding' => __( 'Follow your browser\'s prompt…', 'ai-guardwall' ), 'added' => __( 'Passkey added.', 'ai-guardwall' ), 'confirm' => __( 'Remove this passkey? You can no longer sign in with it.', 'ai-guardwall' ), 'unsupported' => __( 'This browser cannot use passkeys.', 'ai-guardwall' ), 'signing' => __( 'Follow your browser\'s prompt…', 'ai-guardwall' ), 'cancelled' => __( 'The passkey prompt was closed.', 'ai-guardwall' ), 'failed' => __( 'Something went wrong.', 'ai-guardwall' ), ), ); } public static function profile_assets( $hook ) { if ( ! in_array( $hook, array( 'profile.php', 'user-edit.php' ), true ) ) { return; } wp_enqueue_script( 'svabg-passkeys', plugins_url( 'admin/js/softvolt-ai-bodyguard-passkeys.js', SOFTVOLT_AI_BODYGUARD_FILE ), array(), SOFTVOLT_AI_BODYGUARD_VERSION, true ); wp_add_inline_script( 'svabg-passkeys', 'window.svabgPasskeys = ' . wp_json_encode( self::script_data() ) . ';', 'before' ); wp_add_inline_style( 'common', '.svabg-pk-list{margin:6px 0 10px}.svabg-pk-list li{display:flex;gap:10px;align-items:baseline;margin:0 0 6px}.svabg-pk-result.is-error{color:#b32d2e}.svabg-pk-result.is-ok{color:#007017}' ); } public static function login_assets() { if ( ! self::secure_context() ) { return; } wp_enqueue_script( 'svabg-passkeys', plugins_url( 'admin/js/softvolt-ai-bodyguard-passkeys.js', SOFTVOLT_AI_BODYGUARD_FILE ), array(), SOFTVOLT_AI_BODYGUARD_VERSION, true ); $data = self::script_data(); $data['redirect'] = isset( $_REQUEST['redirect_to'] ) ? esc_url_raw( wp_unslash( $_REQUEST['redirect_to'] ) ) : admin_url(); // phpcs:ignore WordPress.Security.NonceVerification.Recommended unset( $data['nonce'] ); wp_add_inline_script( 'svabg-passkeys', 'window.svabgPasskeys = ' . wp_json_encode( $data ) . ';', 'before' ); } public static function login_button() { if ( ! self::secure_context() ) { return; } echo '

'; } }