T05 · Unauthorized Access and Privilege Escalation
- Location
api_case_gen.py:302- Finding
Unrestricted Local File Read Through Specification-Controlled $ref Paths
- Content
View full analysis
dict: key = str(yaml_path.resolve()) if key not in self._cache: if yaml_path.exists(): try: with open(yaml_path, encoding="utf-8") as f: self._cache[key] = yaml.safe_load(f) or {} except yaml.YAMLError as e: log.error("YAML parse error in %s: %s", yaml_path, e) self._cache[key] = {} else: log.debug("File not found: %s", yaml_path) self._cache[key] = {} return self._cache[key] def resolve_ref(self, ref: str, context_file: Path) -> tuple[dict, str, Path]: """Resolve a $ref string relative to context_file.""" if "#" in ref: file_part, fragment = ref.split("#", 1) else: file_part, fragment = ref, "" if file_part: target_path = (context_file.parent / file_part).resolve() else: target_path = context_file.resolve() if not target_path.exists() and self._root and file_part: real_parts = [p for p in Path(file_part).parts if p != ".."] if len(real_parts) >= 2: module = real_parts[0] rest = Path(*real_parts[1:]) for vdir in self._version_dirs: candidate = self._root / module / vdir / rest if candidate.exists(): target_path = candidate.resolve() log.debug("Cross-module resolved: %s → %s", ref, target_path) break spec = self._load(target_path) ``` ### Technical Analysis The `$ref` value comes from the analyzed OpenAPI or Swagger document. Its file component is joined to the specification directory and canonicalized with `resolve()`, but the resulting path is never checked against ...[truncated 2089 chars]- Remediation
View remediation
