Summary
DPanel's /api/common/attach/delete API endpoint contains a path traversal flaw that allows authenticated users to delete arbitrary files on the server filesystem.
Because user-controlled paths are joined and passed directly to os.Remove without enforcing a jail or validating traversal sequences, an attacker can escape the intended storage directory and remove sensitive or critical system files.
Affected context
This vulnerability affects DPanel deployments where:
- The /api/common/attach/delete endpoint is exposed to authenticated users (especially admin backends),
- File deletion requests accept a user-supplied path parameter,
- The backend uses storage.Local{}.GetSaveRealPath in combination with filepath.Join, but does not enforce a chroot/jail or perform strict path validation.
In such environments, any authenticated user with access to this endpoint may be able to target files beyond the expected upload or attachment directory.
Exploit preconditions
- Attack surface: HTTP(S) API endpoint
/api/common/attach/delete. - Required access: Valid authenticated session with permissions to reach the administrative backend or the attach-delete API.
- Input control: Ability to supply crafted path values (including traversal sequences) to the
pathparameter. - Trigger point: Invocation of the Delete function in
app/common/http/controller/attach.go, which: - Forwards the user-supplied
pathtostorage.Local{}.GetSaveRealPath(incommon/service/storage/local.go), - Uses
filepath.Jointo construct the file path, - Passes the resulting path directly to
os.Removewithout ensuring it remains inside a restricted directory. - Why exploitation is possible:
filepath.Joinnormalizes..segments but does not impose a directory boundary. Without explicit checks to keep the final path under an allowed base directory, the code effectively trusts user-controlled paths for filesystem deletion.
Why this happens
The underlying issue is improper neutralization and validation of user-supplied file paths before performing filesystem operations.
Specifically:
- The application takes a
pathparameter from an authenticated HTTP request and forwards it throughstorage.Local{}.GetSaveRealPathintoos.Remove. - While
filepath.Joinresolves relative segments, it does not prevent traversal outside the intended storage root. - No explicit enforcement of a chroot-like boundary (e.g., verifying that the final path still resides under the configured base directory) is performed.
This maps to:
- CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') — user input is used to construct paths without properly confining the result.
- CWE-73: External Control of File Name or Path — file deletion behavior is driven by externally controlled path data.
The insecure pattern is "trusting user-controlled path components in destructive file operations, with only syntactic joining but no semantic directory boundary enforcement."
Potential impact
- Deletion of arbitrary application files, including configuration or uploaded assets.
- Removal of log files, hindering incident investigations and monitoring.
- Deletion of security-related files (e.g., keys, certificates) stored on accessible paths.
- Partial or total application outage if essential binaries, libraries, or configuration files are removed.
- Potential impact on co-hosted services if shared paths or misconfigurations expose additional directories.
General mitigation guidance
Effective mitigation focuses on constraining filesystem operations to well-defined, trusted directories and treating all path input as untrusted:
- Enforce directory boundaries: After computing a resolved path, verify that it remains under a configured base directory (e.g., by resolving to an absolute path and checking it has the expected prefix).
- Canonicalization plus validation: Normalize paths (resolving
.and..) and reject any input that attempts to escape the designated storage root. - Whitelist-based paths: Prefer referencing files by internal identifiers or database records rather than raw user-supplied paths.
- Limit available operations: Ensure deletion APIs only operate on files that the application itself created in specific, known directories.
- Least-privilege filesystem permissions: Run the service under an account with minimal filesystem privileges so that even if a path traversal occurs, the scope of deletable files is limited.
- Segregated storage: Store user-managed content in separate directories or volumes from application code and critical system files to reduce blast radius.
How teams detect issues like this
Organizations can detect and monitor for this class of vulnerability through:
- Static analysis patterns:
- Flagging use of
os.Remove,os.RemoveAll, or similar file operations where the target path is derived from HTTP parameters or other untrusted input. - Identifying path-building functions that combine user-controlled data with base directories without subsequent boundary checks.
- Code review signals:
- Controllers or handlers that accept
path,file, orfilenameparameters and pass them into storage layers without robust validation. - Reliance on
filepath.Joinalone as a security boundary mechanism. - Absence of checks to ensure resolved paths remain inside an allowed root directory.
- Policy enforcement:
- Secure coding guidelines requiring canonicalization + root validation for all file operations involving user input.
- CI-integrated linters or SAST tools configured with custom rules for path traversal and externalized file path control.
- Runtime monitoring:
- Logging and alerting on deletion of unexpected files, especially outside designated upload directories.
- Host-based intrusion detection systems (HIDS) monitoring sensitive directories for anomalous deletions initiated by the application process.

