Summary
A command injection flaw in ONLYOFFICE Docs' cache-flushing helper can let a local attacker who already has command execution as the ds user run commands as root. The risk arises when the helper is invoked with a crafted --hash argument, which is interpolated into a GNU sed expression and run through a passwordless sudo rule.
Affected context
The issue affects the documentserver-flush-cache.sh maintenance helper in ONLYOFFICE Docs (Document Server) 9.4.0-129 on the official onlyoffice/documentserver container. It becomes relevant where the packaged sudoers policy allows the ds user to run this helper as root without a password and with unrestricted arguments.
Exploit preconditions
- Attack surface: The maintenance helper inside the affected container
- Required access: Command execution as the
dsuser - Trigger point: Invocation of the helper with a crafted
--hashargument - Why exploitation is possible: The argument is interpolated without validation into a GNU
sedexpression, whoseeflag can execute commands; the sudoers rule permits the helper to run as root with unrestricted arguments
Why this happens
The helper places attacker-influenced input into a command expression without safely constraining or encoding it. GNU sed's e flag can execute text as a command, and the broad sudoers permission causes the helper to run with root privileges. This is a command injection flaw mapped to CWE-78: Improper Neutralization of Special Elements used in an OS Command.
Potential impact
- An attacker with command execution as
dscould execute arbitrary commands as root in the container. - The container's files, processes, and services could be compromised.
- Depending on container privileges and isolation, an attacker could attempt to access connected resources or affect other systems.
General mitigation guidance
Defensive approaches focus on preventing untrusted input from becoming executable command syntax and limiting the authority of maintenance helpers.
- Prefer APIs that avoid shell or expression interpretation; if external tools are necessary, pass arguments through safe interfaces and validate them against a strict format.
- Avoid embedding user-controlled values in
sedexpressions, especially expressions that support command execution. - Configure sudo permissions narrowly, limiting permitted commands and arguments rather than allowing unrestricted invocation.
- Apply least privilege to the helper and container, and restrict who can obtain command execution as the
dsuser. - Treat runtime arguments as untrusted, even when they are supplied by an internal service or maintenance workflow.
How teams detect issues like this
- Use static analysis to identify untrusted values interpolated into shell commands or
sedexpressions, particularly expressions using command-execution features. - Review sudoers policies for maintenance scripts granted elevated privileges with unrestricted arguments.
- Enforce code-review and CI policies that flag shell construction from untrusted input and overly broad privilege rules.
- Monitor helper invocations and privilege transitions from the
dsaccount for unexpected arguments or command activity.

