/

CVE-2020-37012

Severity:

CRITICAL RISK

(9.8)

OS Command Injection in Tea LaTeX tex2png API Endpoint

CVE-2020-37012

Awaiting Analysis

Vulnerability type

Category:

OS Command Injection

CWE:

CWE-78

Impact:

Remote Code Execution

Severity:

CRITICAL RISK

(9.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

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.php endpoint, specifically the tex2png API 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.

Sources

SourceLink
github.comgithub.com/ammarfaizi2/latex.teainside.org
exploit-db.comexploit-db.com/exploits/48805
vulncheck.comvulncheck.com/advisories/tea-latex-remote-code-execution

Frequently asked

questions

Yes. Because the /api.php tex2png endpoint can be reached over HTTP and does not require authentication, an attacker with network access to the service can exploit it remotely by sending crafted LaTeX payloads.

The attacker only needs the ability to connect to the exposed Tea LaTeX API endpoint. No valid user account or prior foothold on the server is required, making this a high-risk, unauthenticated attack surface.

The most robust fix is to eliminate shell-based command construction using user-controlled data altogether. Invoke LaTeX and related tools through APIs that supply arguments as structured parameters rather than strings, apply strict input validation and feature restrictions to LaTeX content, and run the rendering process inside a hardened sandbox with least privileges.

Adopt secure coding practices that treat all external input as untrusted, particularly where it interacts with interpreters or system commands. Establish code review and automated analysis rules that block direct use of shell execution with interpolated user data, design architecture that isolates document processing components, and incorporate regular security testing focused on injection flaws in exposed APIs.

Find out what's already
exploitable in your codebase.