T05 · Unauthorized Access and Privilege Escalation
- Location
SKILL.md:217- Finding
Single-Image Detection Processes the Entire Parent Directory
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md:217
Vulnerability Type: Excessive local file access and incorrect dataset scoping
Risk Level: MediumVulnerable Code
python # Create prediction dataset predict_ds = PredictDataset( path=os.path.dirname(image_path), image_size=(256, 256) ) # Execute prediction predictions = self.engine.predict(model=self.model, dataset=predict_ds)Technical Analysis
The
detect()method is documented as processing one image, but it passes the image's parent directory toPredictDataset. The anomalib dataset loader can therefore enumerate and process every supported image in that directory rather than only the requested file.The method subsequently selects
predictions[0]without verifying that the prediction belongs toimage_path. This creates two related security and correctness problems:- The operation reads unrelated local images beyond the minimum access necessary for the requested task.
- A prediction for another file may be attributed to the requested image.
This does not bypass operating-system file permissions: the process can only read files available to its existing account. Nevertheless, it violates least-privilege scoping within the application.
Attack Path
- An attacker or untrusted user causes a target image to be stored in a directory containing other sensitive, adversarial, or numerous image files.
- The application invokes
detect()with the path of only the target image. os.path.dirname(image_path)resolves to the containing directory.PredictDatasetenumerates and loads supported images throughout that directory.- The inference engine processes files that were not explicitly requested.
- The implementation takes
predictions[0], which may correspond to an unrelated file, and returns that result while recording the requested path.
Impact Assessment
The flaw can expose unrelated ...[truncated 523 chars]
- Remediation
View remediation
Remediation Suggestions
Pass the validated image file directly to
PredictDatasetinstead of its parent directory:python requested_path = Path(image_path).resolve(strict=True) if not requested_path.is_file(): raise ValueError("The supplied path must identify a regular file") predict_ds = PredictDataset( path=str(requested_path), image_size=(256, 256), )Apply the following additional controls:
- Restrict accepted files to explicitly supported image extensions and verify the decoded format.
- If uploads are involved, copy each image into an isolated per-request directory before processing.
- Reject symbolic links when they are not required.
- Verify that the returned prediction path resolves to the requested canonical path.
- Require exactly one prediction for single-image operations and fail closed otherwise.
- Enforce file-size, pixel-count, and inference-time limits to reduce denial-of-service risk.
