# calling latex from php: security issues

I am trying to program a web interface for automated generation of calculus tests. The idea is to take some input from user, say number of problems and name of instructor, and then by means of php generate the latex file, process it with pdflatex and let user download it.

The procedure seems to be quite straightforward. But what if somebody enters for instructor name something like "Mr. Mackey \input{/etc/hosts}" ?

looks like one can retrieve any file accessible to web server.

How to prevent this? May be there are natural php ways? I am very new to php, and would appreciate any advice.

-

## migrated from stackoverflow.comDec 14 '12 at 16:42

This question came from our site for professional and enthusiast programmers.

basically the same things you'd do to prevent SQL injection attacks need to be done to prevent Latex injection attacks - escape any latex metachars. –  Marc B Dec 12 '12 at 21:29
Try the mentioned \include and you will see it fail. Please do a man pdftex and read the comments in texmf.cnf. And of course use chroot and ulimit. –  Martin Schröder Dec 13 '12 at 7:46
David's answer here might help as well. :) –  Paulo Cereda Dec 14 '12 at 16:48
So as not to be reinventing the wheel, you might want to look into LON-CAPA. –  Alan Munn Dec 14 '12 at 16:54
Under bash, a command line such as openin_any=p pdflatex file works as well. –  egreg Dec 14 '12 at 16:59