Unfortunately, the only thing that will 100% solve the security issue in this particular scenario will never happen due to cost as it would require a redesign of the nose of all aircraft to:
- Move the forward bulkhead and external door back a metre or so towards the tail to accommodate a bunk in the cockpit
- Install piddle bags in the cockpit (obv. the cheapest part)
- Replace the internal door with a refreshment/meal hatch
- Install a separate flight crew external door forward of the passenger door
I'd rather pay for an air marshal to spend the duration of the flight in the jumpseat...