'option', 'delete_option' => 'option', 'update_site_option' => 'option', 'delete_site_option' => 'option', 'update_network_option' => 'option', 'delete_network_option' => 'option', 'activate_plugin' => 'option', 'activate_plugins' => 'option', 'deactivate_plugins' => 'option', 'delete_plugins' => 'option', 'switch_theme' => 'option', 'delete_theme' => 'option', 'add_role' => 'role', 'remove_role' => 'role', 'grant_super_admin' => 'role', 'revoke_super_admin' => 'role', 'wp_update_user' => 'user', 'wp_set_password' => 'user', 'wp_insert_user' => 'new_user', 'wp_create_user' => 'new_user', 'update_user_meta' => 'usermeta', 'delete_user_meta' => 'usermeta', 'update_user_option' => 'usermeta', 'delete_user_option' => 'usermeta', 'update_post_meta' => 'postmeta', 'delete_post_meta' => 'postmeta', 'wp_update_post' => 'post', 'wp_publish_post' => 'post', 'wp_set_object_terms' => 'post', 'wp_set_post_terms' => 'post', 'wp_update_comment' => 'post', 'wp_delete_post' => 'delete', 'wp_trash_post' => 'delete', 'wp_delete_attachment' => 'delete', 'wp_delete_comment' => 'delete', 'wp_trash_comment' => 'delete', 'wp_delete_term' => 'delete', 'wp_delete_user' => 'delete', 'wpmu_delete_user' => 'delete', 'wp_delete_site' => 'delete', 'wp_delete_nav_menu' => 'delete', 'unlink' => 'file', 'wp_delete_file' => 'file', 'rmdir' => 'file', 'rename' => 'file', 'copy' => 'file', 'file_put_contents' => 'file', 'move_uploaded_file' => 'file', 'unzip_file' => 'file', ]; /** Method calls that change roles, and $wp_filesystem's writes. */ public const METHOD_CHANGES = [ 'set_role' => 'role', 'add_role' => 'role', 'remove_role' => 'role', 'add_cap' => 'role', 'remove_cap' => 'role', 'put_contents' => 'file', 'move' => 'file', 'rmdir' => 'file', ]; /** * What a public (nopriv) handler must not change without a permission check (CODE-001). Plain * inserts and post meta are left out: contact forms create posts, and view counters write meta. */ public const NOPRIV_KINDS = [ 'option', 'role', 'user', 'usermeta', 'post', 'delete', 'file' ]; /** What a logged-in handler must not change without a permission check (CODE-010, CODE-011). */ public const PRIV_KINDS = [ 'option', 'role', 'user', 'new_user', 'usermeta', 'postmeta', 'post', 'delete', 'file' ]; public const CAP_CHECKS = [ 'current_user_can', 'user_can', 'current_user_can_for_blog', 'current_user_can_for_site', 'is_super_admin', 'author_can' ]; public const NONCE_CHECKS = [ 'check_ajax_referer', 'wp_verify_nonce', 'check_admin_referer' ]; /** Calls that prove who someone is (CODE-016). */ public const PASSWORD_CHECKS = [ 'wp_check_password', 'hash_equals', 'wp_authenticate', 'wp_signon', 'password_verify', 'check_password_reset_key', 'wp_authenticate_username_password', 'wp_authenticate_email_password' ]; /** Calls that check an upload's type (CODE-006). */ public const TYPE_CHECKS = [ 'wp_check_filetype', 'wp_check_filetype_and_ext', 'pathinfo', 'getimagesize', 'exif_imagetype', 'finfo_open', 'finfo_file', 'mime_content_type', 'wp_get_image_mime', 'get_allowed_mime_types', 'wp_get_mime_types' ]; /** Calls that limit a value to known ones (accepted before CODE-005, -007, -012, -013, -014). */ public const VALIDATORS = [ 'in_array', 'array_key_exists', 'array_search', 'is_numeric', 'ctype_digit', 'ctype_alnum', 'ctype_alpha', 'is_int', 'wp_is_uuid', 'rest_is_integer', 'validate_file' ]; /** * The bits a function removes from request data passed through it, or null for a function this * list doesn't know (its result is treated as clean). */ public static function flow( string $callee ): ?int { if ( in_array( $callee, self::PASS, true ) ) { return 0; } if ( in_array( $callee, self::PAGE, true ) ) { return self::XSS | self::ATTR; } if ( in_array( $callee, self::ESCAPED, true ) ) { return self::XSS | self::ATTR | self::SQL; } if ( in_array( $callee, self::KEYS, true ) ) { return self::XSS | self::ATTR | self::SQL | self::SQLRAW | self::PATH | self::PATHLOW | self::URL | self::UNSER; } switch ( $callee ) { case 'sanitize_file_name': return self::XSS | self::ATTR | self::SQL | self::PATH | self::URL | self::UNSER; case 'basename': case 'wp_basename': return self::PATH; case 'esc_sql': case 'addslashes': return self::SQL; case 'sanitize_sql_orderby': return self::SQL | self::SQLRAW; case 'get_user_by': case 'get_userdata': case 'get_user_by_email': // Followed for CODE-016 only: the user found from the request is who gets logged in. return ( self::REQUEST & ~self::AUTH ) | self::ATTR; } return null; } /** * Whether a $_SERVER key carries what the client sent. */ public static function server_key( string $key ): bool { return in_array( $key, self::SERVER_KEYS, true ) || ( 0 === strpos( $key, 'HTTP_' ) && 'HTTP_HOST' !== $key ); } /** * Whether a URL literal fixes the host: scheme, host, then a path (CODE-014 accepts it). Without * the slash, what follows could still change the host ("@evil.example"). */ public static function fixed_host( string $literal ): bool { return 1 === preg_match( '#^(?:https?:)?//[^/?\#@\s]+[/?\#]#i', $literal ); } /** * SQL text that leaves what follows it outside quotes: a comparison, ORDER BY, GROUP BY, IN (, * LIMIT or OFFSET. Escaping can't protect a value there. */ public static function raw_sql_context( string $before ): bool { return 1 === preg_match( '/(?:[=<>]|\bORDER\s+BY|\bGROUP\s+BY|\bIN\s*\(|\bLIMIT|\bOFFSET|,)\s*$/i', $before ); } }