Path traversal (MITRE CWE-22, read 2026-10-29) happens when firmware builds a filesystem path from external input — a filename in a web UI request, an upload parameter, an exported-log name — without removing or rejecting the special sequences (../, absolute paths, encoded separators) that let that path resolve outside its intended directory. MITRE rates it a high likelihood of exploit, and its own description covers both reading files it shouldn't (confidentiality) and, in upload or import handlers, writing or overwriting files it shouldn't (integrity, and potentially code execution if an attacker can overwrite something the system later runs).
Key takeaways
- MITRE's 2025 CWE Top 25 ranks CWE-22 sixth, with a score of 8.99 and 10 CVEs mapped to it in CISA's Known Exploited Vulnerabilities catalog.
- For each one, trace whether the supplied name is used directly (or lightly concatenated) to build a path passed to a file-open, read, write or delete call, without a canonicalization-and-containment check afterward.
- A fix tested against one payload is a fix for one payload.
- Canonicalize, then verify containment.
Why does path traversal matter for device makers?
MITRE's 2025 CWE Top 25 ranks CWE-22 sixth, with a score of 8.99 and 10 CVEs mapped to it in CISA's Known Exploited Vulnerabilities catalog. Attackers use this weakness in practice, and the rank is computed from real CVE records (our CWE Top 25 guide explains the score). In a device, the damage depends on what the vulnerable handler does with the path:
| Typical device feature | Direction | What an attacker gets when the check is missing |
|---|---|---|
| Log download, diagnostic bundle export | Read | Any file the web server process can read: password hashes, private keys, Wi-Fi and cloud credentials |
| Web-UI or captive-portal static file server | Read | The same, often before any login |
| Configuration restore or import | Write | Overwritten start-up scripts or settings that survive a reboot |
| Firmware or certificate upload | Write | A file placed where the system later runs or trusts it |
| Log delete, cleanup or reset helper | Delete | Removal of files the device needs to boot |
If the embedded web server runs as root, "any file the process can read" means every file on the device. That is why the write and delete rows deserve the fastest fix.
1. Detect
- Audit every firmware web-UI or API handler that accepts a filename, path fragment, or file-upload destination as a parameter: log download/export, configuration backup/restore, firmware-image upload, certificate import, captive-portal asset serving.
- For each one, trace whether the supplied name is used directly (or lightly concatenated) to build a path passed to a file-open, read, write or delete call, without a canonicalization-and-containment check afterward.
- Test with both classic traversal (
../../../etc/passwd) and encoded/alternate variants (URL-encoded%2e%2e%2f, double-encoding, backslash separators, absolute paths) — a denylist that only blocks the literal../string will often miss these. - Check upload and import handlers specifically for write-path traversal, which is more severe than read-path traversal because it can let an attacker place a file anywhere the process can write, including executable locations.
Which traversal variants should your tests cover?
A fix tested against one payload is a fix for one payload. Build the regression test from the variants below. Each row is a case that MITRE's CWE-22 entry or one of its child entries names, and the OWASP Path Traversal page lists more encodings (for example %2e%2e%5c for ..\ and the overlong ..%c0%af) worth adding to a fuzz list.
| Variant | Example value for file= |
MITRE reference | Why a string filter misses it |
|---|---|---|---|
| Relative traversal | ../../etc/shadow |
CWE-23 | Baseline case; caught only if the filter is complete |
| Absolute path | /etc/shadow |
CWE-36 | Contains no ../ at all |
| Backslash separator | ..\..\etc\shadow |
CWE-22 mitigations | Filtering / is not enough where \ is also a separator |
| URL-encoded or double-encoded | %2e%2e%2f, %252e%252e%252f |
CWE-174, CWE-180 | Validation ran before decoding, or decoding ran twice |
| Nested sequence | .../...//etc/shadow |
CWE-182 | Removing ../ in one pass leaves a new ../ behind |
| Prefix trick | /var/log/../../etc/shadow |
CWE-22 demonstrative example | A "starts with /var/log/" check passes |
| Symbolic link | a link inside the export directory pointing to / |
CWE-59 | The string is clean; the filesystem is not |
| Archive entry name | ../../etc/init.d/S99x inside a .tar |
CWE-22 observed examples ("Zip Slip") | The name arrives inside a file, not as a request parameter |
2. How do you fix it?
Canonicalize, then verify containmentResolve the supplied path to its canonical absolute form with a built-in function ( realpath()in C, or your language's equivalent) — MITRE notes this "effectively removes '..' sequences and symbolic links" — and then explicitly check that the canonical result is still inside the restricted parent directory before opening it. Reject the request if it isn't. On Linux 5.6 and later,openat2()withRESOLVE_BENEATHmoves that containment check into the kernel, as part of the open itself.Validate the raw input with an allowlist, not a denylistRestrict filenames to a strict character set (alphanumeric, hyphen, underscore, a single extension) and explicitly reject path separators ( /,\\) in the component itself, so traversal sequences never reach the path-construction step.Prefer an indirection layer over raw filenames where possibleMap a request to a file via an internal ID or lookup table (e.g. "log #3" rather than a raw filename), so user input never becomes part of a filesystem path at all. Run file operations inside a sandbox or chroot/jail where feasibleMITRE lists this as an operation-phase mitigation: it won't fix the underlying bug, but it bounds the damage if a traversal check is ever missed. Apply the same fix pattern everywhere the pattern repeatsPath traversal in firmware is usually a repeated handler pattern (one file-serving utility function reused across many endpoints) — fix the shared utility, then confirm every call site actually uses the fixed version.
Worked example: how do you fix a log-download handler?
Synthetic example. The device, handler and code are invented for this guide and are not taken from any product.
A hypothetical IP camera serves logs at GET /cgi-bin/log?file=<name>. The handler joins the name to the log directory and opens it:
/* SYNTHETIC - vulnerable */
char path[256];
snprintf(path, sizeof path, "/var/log/cam/%s", file);
FILE *f = fopen(path, "r");
A request for file=../../etc/shadow opens /etc/shadow. The fixed version validates the name, resolves it, and checks containment against the directory with its trailing slash:
/* SYNTHETIC - fixed */
#define LOG_DIR "/var/log/cam/"
static int name_ok(const char *s) {
size_t n = strlen(s), dots = 0;
if (n == 0 || n > 64 || s[0] == '.') return 0;
for (size_t i = 0; i < n; i++) {
if (s[i] == '.') { if (++dots > 1) return 0; continue; }
if (!isalnum((unsigned char)s[i]) && s[i] != '-' && s[i] != '_') return 0;
}
return 1;
}
FILE *open_log(const char *name) { /* name was URL-decoded exactly once */
char joined[PATH_MAX], real[PATH_MAX];
if (!name_ok(name)) return NULL;
if (snprintf(joined, sizeof joined, LOG_DIR "%s", name) >= (int)sizeof joined) return NULL;
if (!realpath(joined, real)) return NULL;
if (strncmp(real, LOG_DIR, strlen(LOG_DIR)) != 0) return NULL;
return fopen(real, "r");
}
What each part does, and why:
name_ok()is the allowlist. It follows MITRE's filename guidance in CWE-22: a limited character set, at most one.character, and no directory separators.- Decode once, then validate. MITRE asks for input to be decoded and canonicalized before validation, and never decoded twice; a second decode after the check undoes it.
- Compare against
"/var/log/cam/", with the slash. Without it, a sibling directory such as/var/log/cam-private/would pass a prefix check. - Return one generic error for every rejection. MITRE warns that error messages that reveal path information help attackers refine the traversal string.
- Mind the gap between check and open. If anyone else can create symbolic links in that directory, the path checked by
realpath()and the path opened byfopen()can differ. On Linux 5.6 and later, open the directory once and callopenat2()withRESOLVE_BENEATH | RESOLVE_NO_SYMLINKS; the man page says resolution then fails if any component is not a descendant of that directory. glibc has no wrapper, so the call goes throughsyscall(SYS_openat2, ...). Older board support kernels keep therealpath()version.
For this particular handler, the simplest fix of all is the indirection in step 3 above: the UI lists five log files, so ?id=0 to ?id=4 can select from a fixed table and no request string ever reaches the filesystem.
Do backup, restore and update archives need the same check?
Yes. Every entry name inside an uploaded archive is attacker input, even when the archive claims to come from the user's own device. MITRE's CWE-22 observed examples include several "Zip Slip" extraction flaws, and CVE-2021-21972, where an unauthenticated tar upload combined with .. sequences was exploited in the wild per the KEV catalog.
- Verify the signature of a firmware image before extracting anything from it.
- For each entry, reject absolute names and any
..component, then apply the same canonicalize-and-contain check against the extraction directory. - Reject symbolic-link and hard-link entries unless the format truly needs them. A link entry followed by a regular file written "through" it is a classic two-step escape.
- Extract into an empty, dedicated temporary directory, then move only the expected files into place.
- For uploaded files, let the device choose the stored name. The OWASP File Upload Cheat Sheet recommends a filename generated by the application, a length limit, and validation after decoding.
3. Verify
- Re-test the same traversal payloads (plain and encoded) against the patched handler and confirm every one is rejected, not just the exact proof-of-concept string originally reported.
- Confirm legitimate requests (normal filenames, expected extensions) still work — an over-broad fix that breaks the intended feature is as much a problem as a missed bypass.
- Add the traversal test cases to your regression suite so a future handler added to the same code path inherits the same protection by default (ideally by calling the shared, fixed utility rather than re-implementing path handling).
What are the common pitfalls?
- A prefix check without the trailing separator, or a prefix check on the raw string instead of the resolved one. MITRE's own demonstrative example shows
/safe_dir/../important.datpassing a "starts with/safe_dir/" test. - Validating before decoding, or decoding twice. Both let a dangerous value appear after the check has run.
- Stripping
../once. MITRE's example: removing../from.../...//in sequence still leaves../. - Filtering only
/. Some filesystems and libraries also accept\as a separator. - Treating a firewall rule or a jail as the fix. MITRE rates an application firewall's effectiveness as "Moderate" and a sandbox or jail as "Limited"; both are defence in depth around a correct check.
- Fixing the reported endpoint but not the shared helper, so the next endpoint built on the old helper reopens the hole.
- Testing reads only. Upload, import and delete handlers carry the higher-impact write cases.
- Assuming login is the control. An authenticated traversal is still a finding, and an authentication gap in front of it turns it into an unauthenticated one; see how to fix authentication bypass.
4. Ship an update
Path-traversal fixes are usually self-contained to the affected handler(s); distribute the update through your normal signed-firmware channel, and use your firmware SBOM to confirm which product lines share the vulnerable file-serving utility, since it is common for the same code to be reused across several models.
5. Disclose via PSIRT
Path traversal in an unauthenticated web endpoint is frequently exploited at scale by internet-wide scanners once published, so treat disclosure timing accordingly — see KEV + EPSS prioritization. Run the advisory through your coordinated disclosure process (CVD process explained; PSIRT setup for a hardware company if you don't have one yet), and check the Cyber Resilience Act's 24-/72-hour reporting duty for EU-market products if there is evidence of active exploitation (CRA 24h/72h reporting).
Name the most specific weakness in the advisory: CWE-23 or CWE-36 when you know which form the bug takes, CWE-22 when you do not. List every affected model that shares the handler, not only the one tested.
What can SoftWSP check, and what needs code review?
Path traversal in your own handler code is found by the review and tests above. SoftWSP covers the other half of the image: third-party components. It extracts a software bill of materials from a firmware image as CycloneDX JSON and matches the components against NVD, CISA KEV, FIRST EPSS and CISA ICS advisories. A published CWE-22 CVE in the embedded web server or an archive library you ship then shows up together with its exploitation signals. An AI-drafted report cites each source, and an engineer reviews it before you receive it. SoftWSP does not trace request input to file paths in your code and does not judge reachability. See device & firmware security.
This guide summarises public MITRE CWE guidance; it is not a substitute for a full code review, and does not constitute legal advice.
Put this guide to work
Frequently asked questions
What is path traversal?
MITRE's CWE-22 (Improper Limitation of a Pathname to a Restricted Directory) defines it as a product that "uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but... does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory." CWE-22's own page, read 2026-10-29, notes this most commonly uses `../` sequences to climb out of the intended directory (relative path traversal), or a crafted absolute path (`/etc/passwd`-style, absolute path traversal).
Where does this show up in device firmware specifically?
Embedded web UIs frequently expose file operations by name — a log download, a configuration-file export/import, a firmware-update upload, a captive-portal asset server — where the filename comes from a request parameter. If that parameter is used to build a filesystem path without checks, a request for `../../etc/shadow` or similar can read or, in upload/import handlers, overwrite files well outside the intended directory. MITRE's CWE-22 page rates this weakness's **Likelihood of Exploit as High**.
What does CWE-22 say the impact can be?
MITRE lists four consequence categories: reading files or directories outside the restricted path (confidentiality — including, per MITRE, bypassing authentication by reading a password file); modifying or overwriting files (integrity); executing unauthorized code if an attacker can place or overwrite an executable or library the system later runs; and denial of service if a critical file is deleted or corrupted via the same path.
What is the correct fix, per MITRE?
Two mitigations working together: canonicalize the path and check it, and validate the input before it ever reaches path construction. MITRE's Implementation-phase mitigation says to "use a built-in path canonicalization function (such as realpath() in C)... that produces the canonical version of the pathname, which effectively removes '..' sequences and symbolic links," and then verify the canonical result is still inside the intended restricted directory before using it. Separately, validate the raw filename against a strict allowlist of characters, explicitly excluding path separators (`/`, `\`) so a crafted pathname component never reaches the canonicalization step with traversal sequences already baked in.
Is blocking the literal string '../' enough?
No — MITRE's input-validation guidance calls for an "accept known good" allowlist strategy (reject anything that doesn't strictly match an expected filename pattern) rather than a denylist that tries to block specific bad substrings, because denylists are routinely bypassed with encoding tricks (URL-encoded separators, double-encoding, mixed slash styles, or absolute paths that don't contain '../' at all but still escape the intended directory). Canonicalizing the path and then checking it is inside the intended directory catches these cases that a substring denylist misses.
Sources
- MITRE CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
- The Open Group: realpath() — POSIX.1-2017 function specification
- MITRE: 2025 CWE Top 25 Most Dangerous Software Weaknesses
- MITRE CWE-23: Relative Path Traversal
- MITRE CWE-59: Improper Link Resolution Before File Access ('Link Following')
- Linux man-pages: openat2(2) — RESOLVE_BENEATH and RESOLVE_IN_ROOT
- OWASP: Path Traversal
- OWASP Cheat Sheet Series: File Upload Cheat Sheet
About this guide
SoftWSP Firmware Security Desk
Covers the Firmware vulnerabilities & fixes cluster: 131 guides.

In this cluster
Questions about this page?
