T05 · Unauthorized Access and Privilege Escalation
- Location
scripts/quark_drive.py:403- Finding
Local Upload Allowlist Can Be Bypassed Through String-Prefix Matching
- Content
View full analysis
int: cfg = load_config() local_allow = cfg.get("localAllowlist", []) remote_allow = cfg.get("remoteAllowlist", []) # auto-login if needed ensure_logged_in(timeout=int(cfg.get("loginTimeoutSeconds", 300)), progress_mode="terminal") # simple checks src = Path(args.file).expanduser().resolve() if not any(str(src).startswith(str(Path(a).expanduser().resolve())) for a in local_allow): raise PermissionError(f"本地路径不在 allowlist: {src}") ``` ### Technical Analysis The local upload authorization check compares normalized paths using `str.startswith()`. String prefixes do not enforce filesystem path-component boundaries. For example, if the configured allowed directory is: ```text /path/to/Uploads ``` then all of the following pass the string-prefix test: ```text /path/to/Uploads/file.zip /path/to/Uploads-private/secret.zip /path/to/Uploads_backup/credentials.tar ``` The latter two paths are sibling directories, not descendants of the allowed directory. Consequently, the implementation does not enforce the declared constraint that the Skill may read and upload files only from configured local path prefixes. Calling `Path.resolve()` prevents some symbolic-link tricks, but it does not correct the sibling-prefix authorization flaw. ### Attack Path 1. The Skill is configured with a local allowlist entry such as `/home/user/Uploads`. 2. A file containing sensitive data exists at a similarly prefixed path, such as `/home/user/Uploads-private/secrets.zip`. 3. An attacker or untrusted agent instruction invokes: ```bash python3 scripts/quark_drive.py upload /home/user/Uploads-private/secrets.zip ``` 4. Both paths are resolved. 5. The string `/home/user/Uploads-private/secre ...[truncated 652 chars]- Remediation
View remediation
bool: resolved_src = src.expanduser().resolve(strict=True) for entry in allowed_roots: root = Path(entry).expanduser().resolve(strict=True) try: resolved_src.relative_to(root) return True except ValueError: continue return False ``` Then enforce it before opening or hashing the file: ```python src = Path(args.file).expanduser().resolve(strict=True) if not src.is_file(): raise FileNotFoundError(src) if not is_path_allowed(src, local_allow): raise PermissionError(f"Local path is outside the allowlist: {src}") ``` Additional hardening should include: - Reject an empty local allowlist. - Define whether an allowlisted file itself is valid or only descendants of an allowlisted directory. - Revalidate the path immediately before opening it to reduce time-of-check/time-of-use risk. - Where practical, open files relative to a pre-opened allowlisted directory descriptor. - Add regression tests for sibling paths such as `Allowed-private`, `Allowed2`, and `Allowed_backup`. ]]>
