(a) When the plaintiff in an action or special proceeding resides out of the state, or is a foreign corporation, the defendant may at any time apply to the court by noticed motion for an order requiring the plaintiff to file an undertaking to secure an award of costs and attorney's fees which may be awarded in the action or special proceeding. For the purposes of this section, "attorney's fees" means reasonable attorney's fees a party may be authorized to recover by a statute apart from this section