The cockpit door has a peep hole, and loitering near the front of the plane seems to be prohibited by most US air lines.
There are obviously some risks here, as the door is opened briefly twice, but there are a number of steps taken to minimize this risk.
An attack can be designed against any vulnerability. Whether that attack becomes practically executable remains to be seen.
The biggest realized risk seems to have been Germanwings Flight 9525. A suicidal co-pilot waited until the Captain left the cockpit. Then he locked the door and flew the plane into the side of a mountain.