Afghanistan was bad, but they were almost forgiven internationally, especially as one could pretend "that was the Sovjet Union". But with the invasion of the Ukraine, that is all washed away, Russia is as ugly as the old SU.
The US & allied invasion of Afghanistan after 9/11 is a pretty non-controversial case of legitimate self defence amongst international law scholars. There are some contrarians who dispute it, but it's not a mainstream view.
That's quite different from the 2003 invasion of Iraq which was on much shakier grounds.