That is indeed one of the many hazards and risks which pre-modern states seemed to have grappled with, according to the linked blog series. You may find the series to be an interesting read to see one historian's overview on how pre-modern states were to varying degrees exposed to, managed, and suffered the consequences of, said risk!
> pre-modern
USA agreed to pay Iran to not attack just this month.
I do indeed find Brett's writing informative and fun.