If I accept any input from the scary Internet to generate first a tex file and then a pdf using XeTeX in a server, is it enough to remove all backslashes and escape all the reserved characters #, %, $, _, ^, &, {, } as \#, \%, etc to be in the safe side?
Edit:
The backslash-removal and character-escaping is done just in the content part of the file, for instance:
\begin{document}
\maketitle
This is the user generated input with characters like \#, \%.
\end{document}
pdflatexyou're pretty safe, unless you enable shell escapes and such. – JPi Mar 23 '17 at 02:28$\frac{1}{3}$would become\$frac\{1\}\{3\}\$. – egreg Mar 23 '17 at 07:21\begin{verbatim}...\end{verbatim}(in this case you have to make sure that the text does not contain a line with\end{verbatim}), or even better, put the external text into a file and include it verbatim. – gernot Mar 23 '17 at 08:16\string. But only for shortish things, of course. Otherwiseverbatimor whatever. – cfr Mar 23 '17 at 22:55