T05 · Unauthorized Access and Privilege Escalation
- Location
xqueue-post.py:149- Finding
Symlink Traversal Allows Files Outside the Queue to Be Published
- Content
View full analysis
str: """Upload media to X and return media_id string. Uses v1.1 chunked upload.""" consumer_key = get_credential("x-consumer-key", "X_CONSUMER_KEY") consumer_secret = get_credential("x-consumer-secret", "X_CONSUMER_SECRET") access_token = get_credential("x-access-token", "X_ACCESS_TOKEN") access_secret = get_credential("x-access-token-secret", "X_ACCESS_TOKEN_SECRET") media_data = file_path.read_bytes() media_b64 = base64.b64encode(media_data).decode() ``` ```python def parse_tweet_file(file_path: Path, separator: str) -> list[dict]: """Parse a tweet file into a list of {text, community} dicts.""" content = file_path.read_text().strip() if not content: return [] ``` ```python def find_media(time_dir: Path) -> list[Path]: """Find media files in the time directory.""" media = [] for f in sorted(time_dir.iterdir()): if f.suffix.lower() in SUPPORTED_MEDIA: size = f.stat().st_size max_size = MAX_GIF_BYTES if f.suffix.lower() == ".gif" else MAX_IMAGE_BYTES if size <= max_size: media.append(f) else: print(f"WARN: {f.name} too large ({size} bytes), skipping", file=sys.stderr) return media[:4] ``` ```python # Find tweet files tweet_files = sorted([ f for f in time_dir.iterdir() if f.suffix.lower() in (".md", ".txt") and f.is_file() ]) ``` ### Technical Analysis The scheduler treats directory entries with accepted filename extensions as trusted queue files. It does not reject symbolic links or resolve each candidate path and verify that the resolved target remains under the configure ...[truncated 2308 chars]- Remediation
View remediation
bool: try: if path.is_symlink(): return False resolved_path = path.resolve(strict=True) resolved_root = queue_dir.resolve(strict=True) resolved_path.relative_to(resolved_root) return resolved_path.is_file() except (ValueError, OSError): return False ``` 3. Apply this check before `stat()`, `read_text()`, `read_bytes()`, and `unlink()`. 4. Where the platform supports it, open files with no-follow semantics such as `O_NOFOLLOW`, then validate the opened file descriptor. This reduces symlink-swap race conditions. 5. Ensure every day and time directory is also a real directory beneath the queue root rather than a symlink. 6. Run the scheduler under a dedicated operating-system account with access only to the queue and required executable/runtime files. 7. Restrict queue-directory write permissions so untrusted users and processes cannot insert scheduled content. 8. Consider moving successfully posted files into a controlled archive rather than immediately deleting them, preserving an audit trail without retaining sensitive content indefinitely. ]]>
