Skip to content

security(peft): enforce torch.nn.init prefix validation#1054

Open
RinZ27 wants to merge 1 commit intoNVIDIA:mainfrom
RinZ27:fix/secure-init-parsing
Open

security(peft): enforce torch.nn.init prefix validation#1054
RinZ27 wants to merge 1 commit intoNVIDIA:mainfrom
RinZ27:fix/secure-init-parsing

Conversation

@RinZ27
Copy link

@RinZ27 RinZ27 commented Mar 17, 2026

What does this PR do?

Type of change: Bug fix (Security)

The current implementation of allows importing arbitrary modules via configuration strings, which can lead to RCE if the config source is untrusted.

I added a strict prefix check to ensure only modules are imported, matching the docstring's intent and preventing the loading of malicious packages.

Usage

Testing

Verified the logic by ensuring that valid strings pass while arbitrary modules are rejected.

Before your PR is "Ready for review"

  • Is this change backward compatible?: ✅
  • If you copied code from any other sources or added a new PIP dependency, did you follow guidance in : N/A
  • Did you write any new necessary tests?: N/A
  • Did you update Changelog?: ❌ (Will update if required by maintainers)

Additional Information

Related to security findings in automated scans.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced validation for initializer configuration to ensure valid source references and reject invalid inputs.

@RinZ27 RinZ27 requested a review from a team as a code owner March 17, 2026 06:26
@copy-pr-bot
Copy link

copy-pr-bot bot commented Mar 17, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 17, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: cd87b34a-8349-45c7-9f3f-be0aaef1cc79

📥 Commits

Reviewing files that changed from the base of the PR and between b6285ba and 781fb2c.

📒 Files selected for processing (1)
  • modelopt/torch/peft/config.py

📝 Walkthrough

Walkthrough

String-based initializers for LoRA A/B are now validated to ensure they originate from the torch.nn.init module; a ValueError is raised if a provided string does not start with torch.nn.init..

Changes

Cohort / File(s) Summary
Input Validation for Initializers
modelopt/torch/peft/config.py
Added a check that enforces string initializers to start with the torch.nn.init. prefix and raises ValueError when the prefix is absent, before resolving/importing the callable.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and specifically describes the main security fix: enforcing torch.nn.init prefix validation to prevent RCE via arbitrary module imports in PEFT config initialization.
Security Anti-Patterns ✅ Passed The implementation enforces strict security validation by checking the prefix against an allowlist before dynamic imports, preventing arbitrary code execution vulnerabilities.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can approve the review once all CodeRabbit's comments are resolved.

Enable the reviews.request_changes_workflow setting to automatically approve the review once all CodeRabbit's comments are resolved.

Signed-off-by: RinZ27 <222222878+RinZ27@users.noreply.github.com>
@RinZ27 RinZ27 force-pushed the fix/secure-init-parsing branch from b6285ba to 781fb2c Compare March 17, 2026 06:31
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.

1 participant