Summary
A path traversal flaw in Nezha Monitoring's dashboard NoRoute handler allows arbitrary file reads when URLs starting with /dashboard are treated as admin asset requests.
By abusing prefix and path normalization logic, an unauthenticated attacker can request files outside the intended frontend directory, exposing sensitive configuration and operational data.
Affected context
The vulnerability occurs in Nezha Monitoring deployments where the dashboard is exposed over HTTP/HTTPS and the NoRoute handler falls back to serving admin frontend assets.
Any request whose raw path string starts with /dashboard is considered an admin asset request, regardless of path segment boundaries.
When such paths are processed with naive prefix trimming and path.Join, components like ../ may escape the admin asset directory and resolve to files in the broader server filesystem.
Exploit preconditions
- Attack surface: Public or internal Nezha Monitoring dashboard HTTP endpoint.
- Required access: No authentication; any network client that can reach the dashboard can send crafted URLs.
- Trigger point: A specially crafted URL whose raw path starts with
/dashboardbut includes traversal-like segments (e.g.,..) in subsequent components. - Why exploitation is possible: The NoRoute handler:
- Uses
strings.HasPrefixinstead of path-segment-aware checks to identify/dashboardasset requests. - Removes the prefix with
strings.TrimPrefix, leaving attacker-controlled relative path components. - Calls
path.Join("admin-dist", attack-controlled-path), which normalizes../sequences and can resolve to files outside theadmin-distdirectory. - Serves the resolved file with
http.ServeFileifos.Statconfirms its existence, without access control.
Why this happens
The core issue is improper restriction of path traversal in file-serving logic, mapping to CWE-22: Improper Limitation of a Pathname to a Restricted Directory.
Instead of interpreting the URL path in terms of canonical path segments confined to a fixed root, the handler:
- Treats any string starting with
/dashboardas trusted to reference frontend assets. - Performs string-based prefix trimming and generic path joining, allowing
../sequences to escape the intendedadmin-distroot.
This design conflates user-supplied URL paths with trusted filesystem paths, failing to enforce a hard boundary between the public HTTP namespace and the server's internal directory structure.
Potential impact
- Exposure of sensitive configuration files (e.g., YAML, JSON, or environment-specific configs) that may contain credentials or API keys.
- Disclosure of operational data such as logs, status files, or internal metadata that could aid further attacks.
- Leakage of source code or template files, enabling deeper analysis of the application and identification of additional vulnerabilities.
- Indirect compromise of other systems if secrets or tokens stored on disk are retrieved and reused.
General mitigation guidance
Effective mitigation focuses on constraining file-serving endpoints and hardening path handling:
- Enforce a strict document root: resolve requested paths relative to a fixed base directory and reject any request whose canonical path escapes that base.
- Use path-segment-aware routing and checks instead of raw string prefix matching for paths like
/dashboard. - Normalize and validate paths before any filesystem lookup; explicitly reject paths containing
.., absolute path markers, or other disallowed constructs. - Serve static assets via a dedicated, minimal file server or framework helper that is designed to prevent directory traversal, rather than hand-rolling prefix and join logic.
- Limit the sensitivity of files colocated near static assets; avoid placing configuration, secrets, or logs within the same directory tree when possible.
How teams detect issues like this
Detection typically involves a combination of code-centric and behavior-centric approaches:
- Static analysis / code review:
- Flag use of
strings.HasPrefixor similar string functions to gate file-serving logic for paths under a specific prefix (e.g.,/dashboard). - Identify any uses of
path.Joinor equivalent where user-controlled path segments are joined with a base directory and then passed toos.Stat,http.ServeFile, or related APIs without canonicalization checks. - Look for missing validations against
..or absolute-path indicators in URL-to-filesystem translation code. - Automated tools and policies:
- Enable SAST rules targeting directory traversal patterns and untrusted path operations.
- Establish secure coding guidelines that require centralized helpers for serving static assets, and enforce them through PR templates or linters.
- Runtime monitoring:
- Inspect web access logs for suspicious paths containing
.., nested/dashboardsegments, or attempts to fetch configuration-like files (e.g.,config.yaml,.env,docker-compose.yml).

