I draw a distinction between when the boss is a glory hog versus when there is a larger business reason for why it’s good for the employee. My whole point is that there is nuance to this.
And yes, I know that men frequently take credit for women’s work. It’s happened to me (and probably to you, too) a million times. But again, that falls for me into the bucket of unfair credit taking.
As for HR, while I agree you have to be careful in what you tell them (eg how to navigate something that puts the company at liability), I think good HR people absolutely would help navigate an issue like this.