Bug #30419 security flaw in SELECT INTO OUTFILE
Submitted: 14 Aug 2007 19:51 Modified: 14 Aug 2007 20:00
Reporter: Martin Sarfy Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: DML Severity:S2 (Serious)
Version: OS:Any
Assigned to: CPU Architecture:Any

[14 Aug 2007 19:51] Martin Sarfy
Description:
SELECT INTO OUTFILE creates world-writable files. This is with no doubt a big security flaw. User can generate new modified copy of the file if he needs (and this request is uncommon). For a file deletion, write rights to the parent directory are sufficient.

How to repeat:
SELECT INTO OUTFILE "test" -- creates world-writable file
[14 Aug 2007 19:53] Martin Sarfy
Suggested fix:  create file without world-writable right.
[14 Aug 2007 20:00] Martin Sarfy
"SELECT INTO OUTFILE creates world-writable files. To avoid this security risk, you can create new subdirectory with +x rights for mysql and your user only (e.g. using chown me:mysql restricted_dir, chmod 770 restricted_dir), and then save the file into this directory. This way only you and mysql process can modify the file."

I've added this note into documentation.