Skip to content

chore: add input validation#126

Open
AlexanderBarabanov wants to merge 15 commits into
mainfrom
barabanov/minor-validation
Open

chore: add input validation#126
AlexanderBarabanov wants to merge 15 commits into
mainfrom
barabanov/minor-validation

Conversation

@AlexanderBarabanov
Copy link
Copy Markdown
Contributor

@AlexanderBarabanov AlexanderBarabanov commented May 20, 2026

Summary

  • src/physicalai/inference/component_factory.py
    • block path traversal in artifact paths via added _safe_resolve() to reject ../../ style values read from manifests
    • cap recursive component instantiation at _MAX_COMPONENT_DEPTH = 10 to prevent stack exhaustion from nested manifest specs (this issue has been confirmed during fuzzing session)
  • src/physicalai/inference/model.py - validate policy_name against [a-zA-Z0-9][a-zA-Z0-9-_.]* before it is
    used 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_max ordering
    and both values within the encoder bounds.
  • src/physicalai/inference/adapters/registry.py and src/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) accepted

  • test_manifest_traversal_policy_name_raises - a malformed policy name read from the manifest is rejected before any file I/O

  • test_manifest_policy_name_with_slash_raises - a policy name with a path separator in the manifest is rejected

  • test_explicit_traversal_policy_name_raises - a malformed policy name passed directly by the caller is rejected

  • test_rejects_traversal_in_type_based_artifact - artifact path traversal is blocked for type-based component specs

  • test_rejects_traversal_in_class_path_based_artifact - artifact path traversal is blocked for class-path-based component specs

  • test_from_dict_rejects_inverted_range - a calibration file where min and max tick values are swapped is rejected

  • test_from_dict_rejects_out_of_bounds_tick - a calibration file with a tick value outside the hardware encoder range is rejected

Signed-off-by: Barabanov, Alexander <alexander.barabanov@intel.com>
Signed-off-by: Barabanov, Alexander <alexander.barabanov@intel.com>
Signed-off-by: Barabanov, Alexander <alexander.barabanov@intel.com>
Signed-off-by: Barabanov, Alexander <alexander.barabanov@intel.com>
Signed-off-by: Barabanov, Alexander <alexander.barabanov@intel.com>
Signed-off-by: Barabanov, Alexander <alexander.barabanov@intel.com>
Signed-off-by: Barabanov, Alexander <alexander.barabanov@intel.com>
@AlexanderBarabanov AlexanderBarabanov marked this pull request as ready for review May 21, 2026 08:51
@AlexanderBarabanov AlexanderBarabanov requested a review from a team as a code owner May 21, 2026 08:51
Copilot AI review requested due to automatic review settings May 21, 2026 08:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_name before 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.

Comment thread src/physicalai/inference/model.py Outdated
Comment thread src/physicalai/inference/component_factory.py Outdated
Comment thread src/physicalai/inference/component_factory.py
Comment thread tests/unit/inference/test_manifest.py Outdated
Comment thread src/physicalai/capture/transport/_publisher.py Outdated
AlexanderBarabanov and others added 8 commits May 21, 2026 12:50
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>
Signed-off-by: Barabanov, Alexander <alexander.barabanov@intel.com>
Signed-off-by: Barabanov, Alexander <alexander.barabanov@intel.com>
Signed-off-by: Barabanov, Alexander <alexander.barabanov@intel.com>
Signed-off-by: Barabanov, Alexander <alexander.barabanov@intel.com>
Signed-off-by: Barabanov, Alexander <alexander.barabanov@intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants