fix(bright_data): confine get_screenshot output to a configurable directory#522
Draft
yonib05 wants to merge 2 commits into
Draft
fix(bright_data): confine get_screenshot output to a configurable directory#522yonib05 wants to merge 2 commits into
yonib05 wants to merge 2 commits into
Conversation
…ectory Resolve the get_screenshot output_path and require it to be the current working directory (or the directory named by STRANDS_BRIGHT_DATA_OUTPUT_DIR) or a location inside it. Reject a final path component that is a symlink. Add regression tests covering relative traversal, absolute paths outside the root, and symlink targets.
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
get_screenshotpreviously wrote the downloaded screenshot bytes to the rawoutput_pathwithout any validation, so the file could land anywhere on the filesystem.This change resolves
output_pathand confines it to a single root directory:STRANDS_BRIGHT_DATA_OUTPUT_DIRenvironment variable when set.ValueErroris raised.Behavior change
get_screenshotnow writes within the working directory by default. To write somewhere else, setSTRANDS_BRIGHT_DATA_OUTPUT_DIRto the desired directory (it may point anywhere the operator chooses, including a broad location); relativeoutput_pathvalues are taken from that directory and absolute paths inside it are allowed. The docstring, tool parameter docs, and the rejection error message now state this so the override is discoverable.Testing
../../etc/x) rejected, an absolute path outside the root rejected, a symlink target rejected, default-root (no env var) traversal/absolute-outside rejection, an actionable rejection message, and an operator-chosen output directory accepting an absolute path inside it.pytest tests/test_bright_data.pypasses (21 tests).ruff format --checkandruff checkpass on the changed files.