Fix allowed_local_media_path psirt#4199
Open
michalkulakowski wants to merge 5 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens allowed_local_media_path validation for OpenAI image inputs to prevent prefix-based bypasses (e.g., /allowed_path_private/... being treated as within /allowed_path), and adds a regression test for the bypass case.
Changes:
- Add a new unit test covering a prefix/sibling-path bypass attempt for local filesystem image URLs.
- Normalize
allowed_local_media_pathbefore doing the prefix comparison inloadImage()to ensure directory-boundary enforcement.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/test/http_openai_handler_test.cpp |
Adds a regression test ensuring sibling-prefix paths are rejected. |
src/llm/apis/openai_api_handler.cpp |
Introduces path normalization for allowed_local_media_path prior to prefix checking. |
Comment on lines
+51
to
+59
| std::string normalizeAllowedLocalMediaPath(const std::string& allowedLocalMediaPath) { | ||
| if (allowedLocalMediaPath.empty()) { | ||
| return allowedLocalMediaPath; | ||
| } | ||
| const char lastCharacter = allowedLocalMediaPath.back(); | ||
| if (lastCharacter == '/' || lastCharacter == '\\') { | ||
| return allowedLocalMediaPath; | ||
| } | ||
| return allowedLocalMediaPath + FileSystem::getOsSeparator(); |
Comment on lines
+252
to
255
| const auto normalizedAllowedLocalMediaPath = normalizeAllowedLocalMediaPath(allowedLocalMediaPath.value()); | ||
| const auto firstMissmatch = std::mismatch(imageSource.begin(), imageSource.end(), normalizedAllowedLocalMediaPath.begin(), normalizedAllowedLocalMediaPath.end()); | ||
| if (firstMissmatch.second != normalizedAllowedLocalMediaPath.end()) { | ||
| return absl::InvalidArgumentError("Given filepath is not subpath of allowed_local_media_path"); |
mzegla
approved these changes
May 11, 2026
Comment on lines
+51
to
+66
| std::string normalizePathSeparators(const std::string& path) { | ||
| std::string normalizedPath = path; | ||
| std::replace(normalizedPath.begin(), normalizedPath.end(), '\\', '/'); | ||
| return normalizedPath; | ||
| } | ||
|
|
||
| std::string normalizeAllowedLocalMediaPath(const std::string& allowedLocalMediaPath) { | ||
| std::string normalizedAllowedLocalMediaPath = normalizePathSeparators(allowedLocalMediaPath); | ||
| if (normalizedAllowedLocalMediaPath.empty()) { | ||
| return normalizedAllowedLocalMediaPath; | ||
| } | ||
| if (normalizedAllowedLocalMediaPath.back() == '/') { | ||
| return normalizedAllowedLocalMediaPath; | ||
| } | ||
| return normalizedAllowedLocalMediaPath + '/'; | ||
| } |
Comment on lines
+258
to
263
| const auto normalizedAllowedLocalMediaPath = normalizeAllowedLocalMediaPath(allowedLocalMediaPath.value()); | ||
| const auto normalizedImageSource = normalizePathSeparators(imageSource); | ||
| const auto firstMismatch = std::mismatch(normalizedImageSource.begin(), normalizedImageSource.end(), normalizedAllowedLocalMediaPath.begin(), normalizedAllowedLocalMediaPath.end()); | ||
| if (firstMismatch.second != normalizedAllowedLocalMediaPath.end()) { | ||
| return absl::InvalidArgumentError("Given filepath is not subpath of allowed_local_media_path"); | ||
| } |
Comment on lines
260
to
263
| const auto firstMismatch = std::mismatch(normalizedImageSource.begin(), normalizedImageSource.end(), normalizedAllowedLocalMediaPath.begin(), normalizedAllowedLocalMediaPath.end()); | ||
| if (firstMismatch.second != normalizedAllowedLocalMediaPath.end()) { | ||
| return absl::InvalidArgumentError("Given filepath is not subpath of allowed_local_media_path"); | ||
| } |
rasapala
requested changes
May 12, 2026
added 2 commits
May 12, 2026 16:24
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🛠 Summary
JIRA/Issue if applicable.
Describe the changes.
🧪 Checklist
``