Office affairs are always among parties where at least one is married and not to another party to the affair. Otherwise, they would be office romances and while those can lead to problems or a better life, they don't break covenants so don't fall into all of the problems of the office affair.
The dynamics of office romances or affairs are such that in the beginning, the male is at the greatest risk because he typically initiates and until the female says yes, the male can always be gotten rid of with harassment charges. At the point at which the female says yes and the affair is consummated, the female assumes almost all of the risks. While both may have risks associated with their spouses, those are outcomes outside the office.
The unfair part of the office affair is that when concluded by consent or command, the most severe consequences usually are to the female. The worst that happens to males in the majority of cases is they are reassigned, warned, or can lose a security clearance, but little else economically or socially within the workplace unless the female is pregnant, and then the pregnancy is politely ascribed to the marriage. If all parties remain polite, life goes on.
When exposed, and the majority of office affairs are because these are transparent to colleagues, the female can lose her career and possibly her marriage. The male may lose the marriage but seldom if ever the career. There is something Western here, but it seems the modern opinion is that it is the female who is most at fault for accepting and loses the most trust among her colleagues and that is what devastates the career.
Men who are politically compromised may suffer a setback in upward career momentum, but it is typically short-lived if other skills are valued.
For a female to recover, she typically moves to another company and away from any social connections to the former company, often to a new town to ensure this. If there are spousal objections, the problem becomes much more complicated and often, the deceit, much deeper and difficult to manage. So the risks grow exponentially unless she and her spouse can cope with the infidelity openly or at least in private.
The male may have similar issues but they aren't as severe.
It is not uncommon for the male, having seen that the consequences are few, to engage in multiple office affairs serially or even in parallel. While the risks of parallel affairs are great, the risks for serial affairs are little as long as he can maintain the social arrangements of the marriage. In some networks and cultures, affairs by men are tolerated without approval, with little consequence to the marriage which is viewed socially as an economic and parenting arrangement. The primary mistake the male can make is to subject the spouse to social humiliation by publicly flaunting his other liaisons; so in these cultures, keeping the mistress or office girl at a distance from his social world is considered polite even if having her close at the office is not considered impolite but risky. Because a male gains status from risk taking and managing risk, the office affair can be a plus to his advancement.
This is never true for females.
None of this is fair. Fairness and justice are concepts of legitimacy and there is no framework in which the office affair is considered legitimate. They are part of the fabric of desire that drives the humans at the emotional and sometimes economic levels. That they are unbalanced as to consequences appears to be a cultural problem of perceptions, not a problem of right or morality. If they were right or moral, people wouldn't hide them, make up stories when confronted, or otherwise be 'keeping it on the side'. It is what it is: risky behavior.
How risk is managed and rewarded is the crux. Caveat emptor.