Summary
A code injection vulnerability in the parseActions function of ntfy.sh before version 2.21 allows remote attackers to trigger arbitrary code execution on the server.
When attacker-controlled data is fed into action parsing without strict validation or safe evaluation, the server may interpret parts of the input as executable code, leading to full compromise of the affected instance.
Affected context
This vulnerability affects ntfy.sh notification server deployments running versions prior to 2.21 where the parseActions functionality processes user-supplied or externally sourced action definitions.
The risk is highest when:
- Clients or integrations can submit arbitrary or semi-structured action data
- The server trusts these definitions without strong validation
- Action definitions are interpreted or transformed in a way that can reach a code-evaluation primitive
Exploit preconditions
- Attack surface: Remote network access to an exposed ntfy.sh instance using vulnerable
parseActionslogic. - Required access: Ability to submit or influence action payloads (e.g., via API, message, or notification configuration).
- Trigger point: Server-side invocation of
parseActionson untrusted input, typically during message handling or action processing. - Why exploitation is possible: The parsing logic treats parts of the action definition as code or directly feeds them into a code execution or dynamic evaluation mechanism without robust sanitization and context separation.
Why this happens
The underlying issue aligns with CWE-94: Improper Control of Generation of Code ('Code Injection').
The parseActions function appears to mix data parsing with dynamic behavior in a way that can be influenced by attacker-controlled input.
Instead of treating action definitions as inert data, the implementation likely:
- Builds executable expressions, templates, or commands using untrusted fields, or
- Passes untrusted values into an interpreter, template engine, or shell without strict constraints.
This unsafe coupling of user input with code-generation or evaluation logic enables arbitrary code execution when crafted inputs are processed by the server.
Potential impact
- Remote execution of arbitrary code with the privileges of the ntfy.sh server process
- Full compromise of the ntfy.sh instance, including reading or modifying stored data
- Use of the compromised server as a pivot point for lateral movement within the hosting environment
- Deployment of malware, backdoors, or cryptominers on the underlying host
- Service disruption, data tampering, or integrity loss of notifications and actions
General mitigation guidance
Effective mitigation centers on strict separation between data and executable behavior in action handling:
- Treat all action definitions as data-only structures and avoid any direct interpretation as code or commands.
- Replace dynamic evaluation or code generation with fixed, declarative handlers and whitelisted operations.
- Use structured schemas (e.g., JSON/YAML schemas or typed structs) for actions and validate all fields against expected types and ranges.
- Remove or harden any use of generic eval-like, reflection-based, or shell-executing APIs in parsing paths that process user input.
- Apply least-privilege principles for the ntfy.sh process, including restricted OS permissions and sandboxing, to limit blast radius if similar issues arise.
How teams detect issues like this
Detection typically involves a combination of code-centric and behavior-centric approaches:
- Static analysis & code review:
- Search for usage of dynamic evaluation functions, reflection, or shell invocation within
parseActionsand related code paths. - Flag string concatenation or interpolation that constructs commands, code fragments, or handler lookups directly from user-controlled fields.
- Enforce coding standards that prohibit eval-like constructs on untrusted data.
- Automated scanning:
- Use SAST tools configured with rules for CWE-94 to detect code injection patterns in the codebase.
- Integrate these checks into CI pipelines to prevent reintroduction of similar issues.
- Runtime & logging:
- Enable detailed logging of action definitions and server errors to identify anomalous or suspicious action payloads.
- Monitor for unusual process spawns, outbound connections, or resource spikes originating from the ntfy.sh service.

