Summary
Tea LaTeX 1.0 contains an OS command injection vulnerability in the /api.php endpoint, where LaTeX input is passed to shell commands without proper sanitization.
An unauthenticated attacker can submit a crafted LaTeX payload to the tex2png API action and cause arbitrary shell commands to be executed on the server when the document is processed.
Affected context
This vulnerability occurs in Tea LaTeX 1.0 deployments that expose the /api.php endpoint publicly or to untrusted clients.
The risk is present when the tex2png functionality takes user-supplied LaTeX content and invokes underlying system tools (e.g., LaTeX compilers, image converters) via shell commands without robust input validation or safe execution mechanisms.
Any environment where LaTeX payloads from unauthenticated or untrusted sources are processed by this API is potentially affected.
Exploit preconditions
- Attack surface: HTTP interface exposed via the
/api.phpendpoint, specifically thetex2pngAPI action. - Required access: No authentication required; the attacker only needs network access to the vulnerable Tea LaTeX instance.
- Trigger point: Submission of a malicious LaTeX payload that is processed by the tex2png functionality and passed into a shell command.
- Why exploitation is possible: User-controlled LaTeX content is incorporated into a system command or pipeline without correct quoting, sanitization, or use of safer execution APIs, enabling injection of arbitrary shell metacharacters or directives.
Why this happens
The core issue is a classic OS command injection flaw mapped to CWE-78: Improper Neutralization of Special Elements used in an OS Command.
The tex2png implementation likely constructs shell commands by concatenating or interpolating user input directly into command strings (e.g., calling LaTeX and image conversion tools) and then executes them via shell.
Because the LaTeX payload is treated as trusted and not strictly constrained to a safe subset, attackers can embed shell syntax that the command processor interprets as additional commands.
This insecure pattern turns what should be passive document data into active shell instructions.
Potential impact
- Remote execution of arbitrary OS commands with the privileges of the Tea LaTeX process
- Full compromise of the application host, including file read/write where permissions allow
- Deployment of malware or backdoors on the server
- Exfiltration or tampering of sensitive data processed or stored on the host
- Use of the compromised server as a pivot point for lateral movement within the network
- Service disruption or denial-of-service through destructive commands or resource exhaustion
General mitigation guidance
Effective mitigation centers on removing the ability of user-controlled data to influence shell command structure and limiting the power of any executed processes.
Conceptual defensive patterns include:
- Avoid shell command construction with user input: Use APIs that bypass the shell (e.g., direct binary invocation with argument arrays) and never construct command lines via string concatenation.
- Constrain LaTeX capabilities: Restrict to a minimal, safe subset of LaTeX features and disallow constructs that can spawn external processes or access the filesystem where possible.
- Input validation and normalization: Apply strict whitelisting for acceptable characters and commands in LaTeX payloads, and reject or strip unexpected tokens instead of trying to escape everything.
- Sandbox execution: Run LaTeX compilation in a locked-down environment (containers, jails, or chroot-like sandboxes) with limited filesystem visibility, no network access, and minimal privileges.
- Least privilege: Execute the LaTeX processing service as a dedicated, non-privileged user and apply filesystem and OS-level restrictions to reduce blast radius if compromise occurs.
- Segregation of duties: Isolate the document rendering component from other sensitive services and data, so a compromise in tex2png does not automatically expose the entire system.
How teams detect issues like this
Organizations can approach detection and assurance for this class of vulnerability through multiple layers:
- Static analysis: Scan source for patterns where user input flows into command execution APIs (e.g., calls that spawn LaTeX tools via shell, string-based command construction, use of system/exec-like functions with interpolated parameters).
- Code review heuristics: During manual review, flag any instance where LaTeX payloads or other user-controlled fields are combined with shell metacharacters, command-line flags, or passed to interpreters without strict validation.
- Security testing: Use dynamic application security testing (DAST) to send benign command-injection probes through the tex2png endpoint and monitor for anomalous behavior or error messages.
- Runtime monitoring: Enable host and application logging to capture executed commands, abnormal process trees, and unexpected file or network activity originating from the Tea LaTeX process.
- Policy enforcement: Integrate pre-commit or CI checks that prevent the introduction of new code paths where untrusted input is passed into OS commands without a vetted wrapper or sandbox.

