Help with IK Rigging
You need to limit the IK movement for the bones. The parameters are found under the bone tab. Check the limit option for the proper axis.

The line signifies where the bone(s) will go to accommodate the IK and will change when you change the degrees. Set it where ever you like.