In some situations, a creature may attack a party member by entering it's square. This includes grappling, attacks by swarm creatures, and some other situations. The party member being attacked may attack the creature without penalty. Other party members attacking the creature run the risk of harming their party mate.
For attacks that require a roll to hit, the attack is applied to both the creature and party member. For example, poor Joe is being attacked by a swarm of rats, his team mate Ron attacks the rats with a sword. He rolls a 12 (suitably adjusted). The rats have an AC of 11, so the sword hits doing damage to them. Luckily, Joe has an AC of 14, so the sword attack doesn't hit him.
For area effects that require a save instead of a roll to hit, both the creature and the party member must make a save and take damage accordingly. See Friendly Fire.