If bugs showed up inside your sealed glass jar it most likely means the eggs were already in the flour. Changing brands might be the first test. Freezing a couple days before storing might avoid the problem. In humid country keeping the flour in a tight contained with a small amount of heat, like a small light bulb, might keep the bugs away.
In my own dry country I just keep the stuff in it’s factory sack and bugs never show up even after years on the shelf. If I ever saw a bug I’d just burn the stuff and start over.
Cheap oxygen absorbers on Amazon: https://www.amazon.com/s?k=oxygen+absorbers