There are two reasons why cats will commonly attack people - play and fear/distress. This sounds to me like fear, but it can be hard to tell the difference between them sometimes, and they need to be dealt with in different ways.
A few questions:
- Does she ever "play rough" with your boyfriend? Do they wrestle or does she ever play with him using teeth or claws?
- Before she attacks you, what is her body language like? A playful cat will "dance" or run around you. They might scoot toward you and then away. They might crouch and wiggle their rump as they prepare to pounce. A distressed cat attacking usually seems much more "out of nowhere." They might look calm or be laying or walking nearby. They likely won't be looking at you, but you'll see their ears are pointed your way.
Assuming this is distress/fear, it sounds like there are two things going on: you mentioned that she will bite and scratch when you're petting her sometimes. You also mentioned that there have been times when she approaches you and attacks - like in the hall or when you were closing the window.
When petting her
I would recommend not petting her for the time being, but continuing to greet her like you have been. Crouch down, glance toward her, offer your hand, look away, and call to her. If she comes and sniffs your hand, maybe you can have a cat treat on hand to offer her, but don't pet her. Let her sniff and then (slowly) stand back up and continue what you were doing. Do this whenever you notice her. Probably she'll come up to you sometimes and not others, that's fine. Cats are all about personal space, and greeting her and then ending the interaction tells her that you respect her space and she needs to respect yours.
Once you have had 10+ positive interactions like that (no petting, just greeting and maybe offering food), you can try petting her just a little bit again. Start with just one or two pets, a chin scratch, whatever she likes best, and be on the lookout for signs that she isn't liking it. The biggest sign is usually a cat swishing or flicking their tail. Some cats get overwhelmed really easily, and this is usually the first sign that humans can tell. If you see that, stop even if she's still rubbing on you. Stay calm, slowly stand up, and go about your business. Again, this will tell her that you respect her space and she needs to respect yours.
Never chase her to pet, even a little bit. If she moves out of super easy reach of your hand, wait for her to come back to you again. Let her choose to engage with you on her own terms.
Assuming she's not being playful, there must be something going on in these instances that has her scared or overwhelmed. Some potential ideas:
- The noise of the window closing or socks on the floor really bothered her
- She has previously been kicked by a foot wearing socks
- She is scared you're going to hurt her or isn't sure what you're doing.
Since we can't ask her what the problem is, it can be hard to tell. You've done a great job of including specifics here. You said that socks scare her - how do you know that? Is it something about her behavior other than the attacking? Have you seen the same behavior in any other circumstances? Do shoes/slippers have the same effect?
You/your boyfriend may find it really, really helpful to work on that fear. There's a book called "The Trainable Cat: A Practical Guide to Making Life Happier for You and Your Cat" which has great, specific instructions for desensitizing a cat to an environmental fear (their example is a vacuum cleaner, but it can apply to anything). If it is a fear, then working on it slowly will likely help and prevent the attacks by lowering her fight or flight response.
In the short term, it might be helpful for her to be "given" a room during the night time. This should be a space where she feels comfortable and has access to water, food, litterbox, toys, and lots of soft things to lay on. Ideally it would also have a door that can close. Putting her in her room overnight would keep you safe and will lower her stress because she won't have to be on high alert the whole night. Anxious cats typically do a lot better with smaller spaces.
A note for your boyfriend
Cats are often territorial, and yours might feel distressed by the presence of a new human who is (in her view) displacing her. I'd advise you to do your very best to create consistency in her routine regardless of whether your girlfriend is visiting or not. For example, if your cat is allowed to sleep in your room when your girlfriend isn't there, but is kicked out when your girlfriend is there, that could be causing a problem. In this case it seems like the best temporary fix would be to not let your cat sleep in your room at all so that it's consistent. Once she's getting along better with your girlfriend, it likely won't be a problem anymore. As another example, make sure that you're giving your cat attention even when your girlfriend is over. Snuggles, playtime, whatever you normally do. Continue to offer positive attention even if your cat doesn't seem interested at first.