If a person serving a criminal sentence in a federal, state, local, or privately operated correctional facility seeks leave to proceed in state court without payment of filing fees in any civil action or appeal against the state, a state or local governmental agency or entity, or a state or local official, employee, or volunteer acting in such capacity, except an action that, if successful, would affect the duration of the person's confinement, the court shall deny the request for waiver of the court filing fees if the person has, on three or more occasions while incarcerated or detained in any such facility, brought an action or appeal that was dismissed by a state or federal court on grounds that it was frivolous or malicious. One of the three previous dismissals must have involved an action or appeal commenced after July 22, 2011. A court may permit the person to commence the action or appeal without payment of filing fees if the court determines the person is in imminent danger of serious physical injury.