web2c based tex's have quite a lot of customisation to control this. As is a well known theorem of Turing, it's not possible to detect all possible infinite loops in any non trivial programming language, so if the tex code is \def\x{\x}\x it will loop forever, however any web hosting setup should allow you to specify time limits for any forked processes so that isn't really a problem, you can always kill the job after whatever time limit you want to set.
running scripts is not allowed by default so your second concern is only an issue if you allow it to run arbitrary user specified commands, so don't do that:-)
You may also want to clamp down on the ability to read files outside of the input tree by banning reading of /etc/passwd etc (writing such files is again prevented by default)
the texmf.cnf controlling your text installation will have
% Do we allow TeX \input or \openin (openin_any), or \openout
% (openout_any) on filenames starting with `.' (e.g., .rhosts) or
% outside the current tree (e.g., /etc/passwd)?
% a (any) : any file can be opened.
% r (restricted) : disallow opening dot files
% p (paranoid) : as `r' and disallow going to parent directories, and
% restrict absolute paths to be under $TEXMFOUTPUT.
openin_any = a
openout_any = p
you may want to make openin_any also p
Other than that tex is as safe as anything else you can do, it can not spawn any new commands, it can not write anywhere other than the directory it is started from (and subdirectories of that) and it can not read any files out of the specified input path.
\endinput% this file is anti-social if this line is removed
\makeatletter
\ProvidesFile{xxx}[\noexpand\ver@xxx]
\ProvidesFile{xxx}[\ver@xxx]
\documentclass{article}
\begin{document}
\end{document}
--saferoption (or don't use it at all). Of course, never run TeX as root. – Henri Menke Oct 20 '16 at 11:30\beginmay not be safe: try\begin{input}{/etc/passwd}inside the document (Linux).\begin{figure}(ortabularorequationetc.) even if\begin{document}is provided by the template. Perhaps the OP should expand a little on what user input will consist of. – Chris H Oct 20 '16 at 12:53cat/etc/passwdon multi-user systems, but that doesn't really compromise the system. In theory, knowing user names makes an attack slightly easier, but strong passwords and standard precautions mean that makes little difference. The attacker already knows there's arootuser, for example. – cfr Oct 20 '16 at 14:59/etc/passwd), you can read user's sensitive data, e.g.:\begin{input}{/home/guessed-username/.netrc}. This is a serious threat! – yo' Oct 20 '16 at 19:54ls /hometo get the names of other users. There is no threat here at all unless the system is already insecure because the permissions on directories are inappropriate. For me to read your.netrc, your home directory must be world readable and world executable (or I must be in the same group as you and it must be group readable and executable) and.netrcmust be world readable (or group readable). If that is true, my reading/etc/passwdis beside the point. – cfr Oct 20 '16 at 21:28.netrcinto a PDF document they are allowed to open. – yo' Oct 20 '16 at 21:30/etc/passwdis world readable. It is assumed that everyone can read it. That is simply not a threat at all. Knowing your username does not give me access to your files unless the system is fundamentally insecure. If that's the case, you have more to worry about than my reading/etc/passwd. Knowing your user name doesn't give me access to anything. There is no threat here. It is just FUD. – cfr Oct 20 '16 at 21:33/dev/nullor/srv/httpor something along those lines. I've never done this so I don't know the details, but if you arebob, say, you don't run anything on the public side asbob. – cfr Oct 20 '16 at 21:54