File Access via \input
The \input primitive in TeX engines is designed to read files into the typesetting stream. By default, \input is not governed by the shell_escape flag. This means that if the engine's security level allows it, \input can read arbitrary files on the system regardless of whether shell escape is enabled or disabled.
Engine-Specific Behaviors
- pdfTeX: Enabling
shell_escape allows the engine to execute external system commands (via \write18), but it is not a prerequisite for \input to access sensitive files like /etc/passwd. Access is instead controlled by the openout_any and openout_std security settings.
- XeTeX: The
-no-shell-escape option prevents the execution of external binaries, but it does not prevent \input from accessing files outside the current working directory if the engine is running with a permissive security level.
- LuaTeX: The
luaos.execute setting controls the ability of Lua scripts to run system commands. While LuaTeX provides more powerful file I/O via the Lua interface, the standard TeX \input primitive continues to operate based on the engine's underlying file-access security levels, independent of the Lua-specific execution flags.
Security Mechanisms and Restrictions
To prevent unintended file system access, TeX distributions implement security levels (often configured in texmf.cnf). These levels determine where the engine can read and write files:
| Setting |
Effect on \input |
openout_any = p |
Permits reading/writing to any path the OS user can access. |
openout_std = p |
Restricts access to standard TeX directory structures. |
paranoid |
Strictly limits access to the current directory and specific TeX folders. |
Verification Steps
To verify the current security posture of your TeX installation, you can attempt to read a known non-sensitive system file using a minimal TeX file:
\input{/etc/hostname} % Linux/macOS
\input{C:/Windows/win.ini} % Windows
\end
If the engine outputs the contents of these files, the security level is permissive, regardless of your shell_escape settings.
Required Diagnostic
To provide a more precise recommendation for hardening, please specify the TeX distribution (e.g., TeX Live, MiKTeX) and the OS environment (e.g., Docker container, bare-metal Linux) being used.