The job market is hot right now. Working on messy code is a nightmare. Why should you suffer?
If you are a good developer, you should work with people like you. Not only will you learn from the others, but you will have an easier job as well. Well engineered code is just much easier to maintain. Learning from other talented developers actually helps with your future marketability and thus job security.
I would tell the boss how to improve upon it. If he does not listen, I would leave.
Your job security lies 70% in your technical strengths and 30% in your office politics skills.
If you do not want to move up the ladder, your office politics skills actually do not have to be well honed. As long as you avoid making enemies and you are technically strong, you should have no problems with job security. Easy Peasy!