QWED-AI/qwed-verification: CWE-73, sandbox path check bypassed by missing separator boundary
Summary
SystemGuard.verify_file_access() in qwed_sdk/guards/system_guard.py is the
file-access half of a class documented as a "Deterministic Shell & File Firewall"
that "Prevents RCE and sandbox escapes via static analysis." It is exposed
publicly through QWEDLocal.verify_file_access() in qwed_sdk/qwed_local.py,
which is the SDK's own documented, deterministic (no LLM) sandboxing API.
The containment check is:
is_allowed = any(
abs_path.startswith(os.path.abspath(allowed_dir))
for allowed_dir in self.allowed_paths
)
This is a string-prefix test with no path-separator boundary. For a default
allowed_paths = ["/tmp", "./workspace", "."], a filepath such as
/tmp-exfil/secret or /tmpXYZ/anything satisfies
abs_path.startswith(os.path.abspath("/tmp")) even though it is not inside
/tmp at all, because "/tmp-exfil/secret".startswith("/tmp") is True in
Python. The same applies to any path that happens to start with the literal
characters of os.path.abspath(".") (the current working directory string)
without a separator after it.
The function's own earlier check for literal .. in the raw filepath
(DEFAULT_FORBIDDEN_PATHS includes r"\.\.") does not catch this: the bypass
path contains no .. substring at all, it simply picks a sibling path name
that shares a string prefix with an allowed directory. No symlink resolution
(os.path.realpath) is used either, so a symlink under an allowed directory
pointing outside it is also not caught.
Verified against QWED-AI/qwed-verification at main (6b759d465ef3a582273a428162274a501104e874).
Classification
- CWE: CWE-73 (External Control of File Name or Path) / missing path-separator boundary in a containment check
- Repository / Commit:
QWED-AI/qwed-verification@main(6b759d465ef3a582273a428162274a501104e874) - File / lines:
qwed_sdk/guards/system_guard.py:134-146,SystemGuard.verify_file_access, theis_allowed = any(abs_path.startswith(...))check - Public entry point:
qwed_sdk/qwed_local.py,QWEDLocal.verify_file_access()
Evidence
def verify_file_access(self, filepath: str, operation: str = "read") -> Dict[str, Any]:
...
for pattern in self.forbidden_patterns:
if pattern.search(filepath):
return {"verified": False, "risk": "FORBIDDEN_PATH", ...}
try:
abs_path = os.path.abspath(filepath)
except Exception:
return {"verified": False, "risk": "INVALID_PATH", ...}
is_allowed = any(
abs_path.startswith(os.path.abspath(allowed_dir))
for allowed_dir in self.allowed_paths
)
if not is_allowed:
return {"verified": False, "risk": "SANDBOX_ESCAPE", ...}
return {"verified": True, ...}
Default allowed_paths = ["/tmp", "./workspace", "."] (from __init__).
Impact
Any caller that relies on SystemGuard.verify_file_access() or
QWEDLocal.verify_file_access() to decide whether an agent-controlled or
otherwise untrusted file path is safe to read or write can be given a path
that is textually outside every allowed directory while still passing the
check, as long as it shares a string prefix with one of them (a sibling
directory name, or any path starting with the raw current-working-directory
string). Since this class's own docstring states it exists specifically to
prevent sandbox escapes for agent file access, a bypass here defeats the
guarantee the SDK advertises to its callers.
Suggested remediation
Replace the prefix check with a boundary-aware comparison, for example:
import os
def _is_within(path: str, root: str) -> bool:
path = os.path.realpath(path)
root = os.path.realpath(root)
return path == root or path.startswith(root + os.sep)
and resolve symlinks (os.path.realpath, not just os.path.abspath) before
the comparison, so a symlink inside an allowed directory cannot point outside
it.
CVE Request & Credits
We kindly request a CVE assignment for this vulnerability upon validation.
- Reporter: Filip Kulisiewicz (KulFilip)
- Remediation developer: Filip Kulisiewicz (KulFilip)
Advisory page: https://qwedai.tech/security/advisories/ghsa-wfx7-f63g-p968
