chore: add input validation#126
Open
AlexanderBarabanov wants to merge 15 commits into
Open
Conversation
Signed-off-by: Barabanov, Alexander <alexander.barabanov@intel.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds validation and safety checks to inputs crossing trust boundaries (manifest/calibration/user args) to prevent path traversal and recursion-based DoS during inference component loading and robot calibration parsing.
Changes:
- Added strict artifact path resolution within export directories and capped recursive component instantiation depth.
- Validated
policy_namebefore using it in filesystem path construction, with unit tests for valid/invalid names. - Validated SO-101 calibration tick ranges for ordering and encoder bounds, plus tests.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
src/physicalai/inference/component_factory.py |
Adds safe artifact path resolution and recursion depth cap for component instantiation. |
src/physicalai/inference/model.py |
Validates policy_name (manifest + explicit arg) before constructing model paths. |
src/physicalai/robot/so101/calibration.py |
Validates joint tick ranges for ordering and encoder bounds. |
src/physicalai/inference/adapters/registry.py |
Adds Semgrep suppression comment for non-literal import false positive. |
src/physicalai/capture/transport/_publisher.py |
Adds Bandit suppression comments for subprocess usage. |
tests/unit/inference/test_manifest.py |
Adds tests for artifact traversal blocking and component depth cap. |
tests/unit/inference/test_model.py |
Adds tests for policy name validation (positive + negative cases). |
tests/unit/robot/test_so101.py |
Adds tests for SO-101 calibration tick ordering and bounds. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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
src/physicalai/inference/component_factory.py_safe_resolve()to reject../../style values read from manifests_MAX_COMPONENT_DEPTH = 10to prevent stack exhaustion from nested manifest specs (this issue has been confirmed during fuzzing session)src/physicalai/inference/model.py- validatepolicy_nameagainst[a-zA-Z0-9][a-zA-Z0-9-_.]*before it isused to construct a filesystem path. The allowlist was derived from surveying real-world model names to ensure common cases are not broken, the positive test added.
src/physicalai/robot/so101/calibration.py- validate SO-101 joint tick ranges:range_min < range_maxorderingand both values within the encoder bounds.
src/physicalai/inference/adapters/registry.pyandsrc/physicalai/capture/transport/_publisher.py- added Semgrep/Bandit suppressions on false positives.Why
Several inputs that cross a trust boundary (manifest JSON loaded from disk, calibration files, and user-supplied
policy_name) were used in sensitive operations (filesystem path construction, recursive instantiation) without validation.Validation
All pre-existing unit tests pass unchanged, confirming no regression in normal usage.
Added the following unit-tests (both positives and negatives):
test_valid_policy_name_accepts_real_world_names- common real-world policy names (pi0_fast,pi0.5,smolvla,multi_task_dit,pi0-fast_v2) acceptedtest_manifest_traversal_policy_name_raises- a malformed policy name read from the manifest is rejected before any file I/Otest_manifest_policy_name_with_slash_raises- a policy name with a path separator in the manifest is rejectedtest_explicit_traversal_policy_name_raises- a malformed policy name passed directly by the caller is rejectedtest_rejects_traversal_in_type_based_artifact- artifact path traversal is blocked for type-based component specstest_rejects_traversal_in_class_path_based_artifact- artifact path traversal is blocked for class-path-based component specstest_from_dict_rejects_inverted_range- a calibration file where min and max tick values are swapped is rejectedtest_from_dict_rejects_out_of_bounds_tick- a calibration file with a tick value outside the hardware encoder range is rejected