While the (lack of) protection of the cloak's wearer from the spells was well explained in KeyBrd's answer, the invisibility was not, so I'd like to address that.
It was established throughout the books that the cloak is an exceptional one, not losing its properties, etc. However, some devices can penetrate it. One of them is Moody's magical eye, as explained in the following excerpt from "Harry Potter and the Goblet of Fire":
Moody took a step closer to the foot of the stairs. Harry saw Moody's magical eye travel over Snape, and then, unmistakably, onto himself.
Harry's heart gave a horrible jolt. Moody could see through invisibility cloaks... he alone could see the full strangeness of the scene: Snape in his nightshirt, Filch clutching the egg, and he, Harry, trapped in the stairs behind them. Moody's lopsided gash of a mouth opened in surprise. For a few seconds, he and Harry stared straight into each other's eyes. Then Moody closed his mouth and turned his blue eye upon Snape again.
Recall that it is the eye that sees through the cloak, because - as we learn later on - this Moody is not the real Moody, but rather Barty Crouch Jr., who has no extraordinary wizarding powers (although, he could've use Homenum revelio spell, but I don't believe that he did). In the movies, that scene is not present.
The aforementioned movie and book scene in the Hagrid's cabin (from "Harry Potter and the Chamber of Secrets") is explained by J.K. Rowling:
Angela Morrissey: Why is it that Albus Dumbledore can see Harry under his invisibility cloak at certain moments? (during the series is the cloak only infallible to those who do not own a deathly hallow).
J.K. Rowling: Dumbledore, who could perform magic without needing to say the incantation aloud, was using "Homenum revelio", the human-presence-revealing spell Hermione makes use of in Deathly Hallows.
Another device that can see through the invisibility cloak is the Marauder's map, as Lupin explains in the book "Harry Potter and the Prisoner of Azkaban":
"The number of times I saw James disappearing under it...", said Lupin, waving an impatient hand again. "The point is, even if you're wearing an Invisibility Cloak, you still show up on the Marauder's Map. I watched you cross the grounds and enter Hagrid's hut. Twenty minutes later, you left Hagrid, and set off back toward the castle. But you were now accompanied by somebody else."
As the name "invisibilidy" hints: the cloak hides its wearer from the sight, but not from all the magical spells and devices.