Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions unsloth/import_fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,22 @@ def fake_supports_pdl(*args, **kwargs):
"lora_shrink_op": "vllm.lora.ops.triton_ops.lora_shrink_op",
"fused_moe_lora_op": "vllm.lora.ops.triton_ops.fused_moe_lora_op",
}

# Whitelist of allowed module paths to prevent arbitrary code execution
allowed_modules = {
"vllm.lora.ops.triton_ops.lora_expand_op",
"vllm.lora.ops.triton_ops.lora_shrink_op",
"vllm.lora.ops.triton_ops.fused_moe_lora_op",
}

for name, path in consumer_modules.items():
# Validate module path against whitelist before importing
if path not in allowed_modules:
logger.warning(
f"Unsloth: Skipping import of non-whitelisted module: {path}"
)
Comment on lines +1078 to +1091
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

While adding a whitelist for module imports is a good security practice, the current implementation introduces redundancy. The allowed_modules set is a manual copy of the values from the consumer_modules dictionary. This creates a maintenance burden, as any changes to consumer_modules must be manually duplicated in allowed_modules, which is error-prone.

Since consumer_modules is hardcoded and not derived from any external input, it already acts as a whitelist. The additional check is currently redundant. I suggest removing the allowed_modules set and the validation check to avoid this duplication.

Suggested change
# Whitelist of allowed module paths to prevent arbitrary code execution
allowed_modules = {
"vllm.lora.ops.triton_ops.lora_expand_op",
"vllm.lora.ops.triton_ops.lora_shrink_op",
"vllm.lora.ops.triton_ops.fused_moe_lora_op",
}
for name, path in consumer_modules.items():
# Validate module path against whitelist before importing
if path not in allowed_modules:
logger.warning(
f"Unsloth: Skipping import of non-whitelisted module: {path}"
)
for name, path in consumer_modules.items():

continue

try:
module = importlib.import_module(path)
if hasattr(module, "supports_pdl"):
Expand Down