Added permissions check and secure erasure of temporary data