Skip to content

Harden Prompty local image path handling - #48942

Open
Sydney Lister (slister1001) wants to merge 1 commit into
Azure:mainfrom
slister1001:fix/evaluation-prompty-path-containment
Open

Harden Prompty local image path handling#48942
Sydney Lister (slister1001) wants to merge 1 commit into
Azure:mainfrom
slister1001:fix/evaluation-prompty-path-containment

Conversation

@slister1001

Copy link
Copy Markdown
Member

Description

Harden azure-ai-evaluation local Prompty image handling so rendered input cannot read files outside the Prompty directory.

  • Canonicalize the Prompty root and candidate image path before file access.
  • Reject absolute paths, Windows-drive paths, parent traversal, and symlink escapes.
  • Preserve in-directory local images, HTTP/data URLs, and the existing plain-text fallback for unresolvable Markdown image references.
  • Keep unsafe data:...;path: references as explicit invalid input.
  • Add cross-platform, mixed-content, and compatibility regression coverage.

Validation

  • python -m pytest --confcutdir=tests\unittests tests\unittests\test_inline_image_fallback.py -q --tb=short — 25 passed, 1 skipped.
  • Black 24.4.0 formatting and check passed for both changed Python files.
  • git diff --check passed.

All SDK Contribution checklist:

  • The pull request does not introduce breaking changes
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There is a single informative commit.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

Reject absolute, traversal, and symlink-escape image paths before reading local files, while preserving in-directory image support and graceful Markdown fallback.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 6fcc3b99-8914-4e38-9905-16829c362bd7
@github-actions github-actions Bot added the Evaluation Issues related to the client library for Azure AI Evaluation label Sep 9, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
10 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@slister1001
Sydney Lister (slister1001) marked this pull request as ready for review September 10, 2026 18:54
Copilot AI balanced review requested due to automatic review settings September 10, 2026 18:54
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
10 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

File validation and reading remain separated by a symlink race that can bypass containment.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Hardens Prompty image resolution against directory traversal and symlink escapes.

Changes:

  • Canonicalizes and validates local image paths.
  • Preserves fallback behavior for invalid Markdown references.
  • Adds traversal, symlink, and compatibility tests.
File summaries
File Description
_utils.py Adds secure-path validation and fallback handling.
test_inline_image_fallback.py Adds path-security regression coverage.
CHANGELOG.md Documents the security hardening.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +386 to +388
if not path.is_file():
raise InvalidInputError(f"Cannot find the image path '{path.as_posix()}'")
file_contents = path.read_bytes()
@slister1001

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
You have several pipelines (over 10) configured to build pull requests in this repository. Specify which pipelines you would like to run by using /azp run [pipelines] command. You can specify multiple pipelines using a comma separated list.

@slister1001

Copy link
Copy Markdown
Member Author

/azp run python - pullrequest

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Evaluation Issues related to the client library for Azure AI Evaluation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants