Good intentions good for paving.
Those ``home internet routers'' are pretty safe already, because of how NAT works. Indeed, the infection paths nowadays are of the ``drive by'' type. And having those edge things ``fix'' XSS and overflows and things in protocols layers above the layers they're supposed to operate in is a good recipe for making the whole thing even more unpredictable. Plus, deep packet inspection and acting on it is censorship. So if the state mandates the vendors puts that in... that goes beyond merely high proof utter technical stupidity.
The problem with this sort of government rule, as already implied by other commenters, is that it implies things that amount to a rehash of ``all the world is a vax'', or now ``all the world is a wintendo with a clueless moron behind it''. That sort of law gets really old, really fast, in several meanings of the word.
If you want to fix the OS, fine, force the OS vendor to finally get on with fixing their crap code. Don't force others to pay for it, either. Don't force essentially unrelated devices to patch up problems in crap OSes (or applications, or websites) either. Fix the OS instead, or ditch it and move on to something less resembling a rotten corpse. There are quite a few options even without counting anything with ``linux'' in it somewhere, though no need to discount it either.
If you want to fix the stupidity, you can go about it from two directions: Fixing the user by education is one. Fixing the OS to have less a confusing design is another. You can't do all from just one side.* The main culprit vendor tried to, failed, then as time went on and they kept adding more layers of the same, their stuff became ever more confusing. Then they asked others to pay for it with a ``bug tax''. Uhm, no. Not even if they didn't sell their crap for a 90% margin and weren't sitting on several humongous sacks of cash.
Point is: Yes, you can do a lot. No, requiring all computers to adhere to safety rules that only apply to a subset is not the way. Putting that in law is shooting yourself in the foot with a bigger cannon, so don't do it.
Same with people. Might as well forbid stick drive because granny can't use it. That's not how it works. You make granny use an automatic, and leave the rest alone. If you can't imagine how that works, you have no business making laws.
* This is the ``the only intuitive interface is the nipple; everything else is learned'' argument, and it's false. The nipple isn't intuitive either. You can go a long way with methaphors, but you can't go all the way, and besides, the methaphors only work because that something else you're using for a methaphor has already been learned.