I always thought the rules are you can’t castle if an enemy piece is watching the space between your king and the rook you want to castle with. But according to chess.com castling long is allowed in the following position
You can not castle if your king would start, move through or end in check. For short castling that amounts to the same, since the corresponding squares e1, f1 and g1 include all the squares between king and rook. (Note that you can short castle even if your rook is attacked.)
For long castling that makes a difference since b1 as in this example may be attacked but the White king never crosses that square.
For reference: https://www.fide.com/FIDE/handbook/LawsOfChess.pdf Article 3.8 b.2.a:
Castling is prevented temporarily:
[a] if the square on which the king stands, or the square which it must cross, or the square which it is to occupy, is attacked by one or more of the opponent's pieces
Basically, if there is none of the opponent active pieces threatening c1, d1, or e1 (the king can't be in check), then the king can castle long, as long as the king hasn't moved yet. Well, the rook has to have stayed in its original position as well. The same can be said for e1, f1, g1 when it comes to castling the other way.