Skip to content

Scanning 1#4044

Closed
girichinna27 wants to merge 2 commits into
unslothai:mainfrom
girichinna27:scanning-1
Closed

Scanning 1#4044
girichinna27 wants to merge 2 commits into
unslothai:mainfrom
girichinna27:scanning-1

Conversation

@girichinna27
Copy link
Copy Markdown

Pull Request — Semgrep Rule Fix
Rule ID: subprocess-shell-true
Rule Message: Found 'subprocess' function 'Popen' with 'shell=True'. This is dangerous because this call will spawn the command using a shell process. Doing so propagates current shell settings and variables, which makes it much easier for a malicious actor to execute commands. Use 'shell=False' instead.
File Path: unsloth/chat_templates.py
Line: 2694

root and others added 2 commits February 13, 2026 11:13
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @girichinna27, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the security posture of the application by correcting an unsafe use of subprocess.Popen. By disabling shell execution and properly structuring command arguments, it prevents potential command injection risks and aligns with best practices for executing external processes.

Highlights

  • Security Fix: Addressed a Semgrep subprocess-shell-true rule violation by changing subprocess.Popen to use shell=False, mitigating potential command injection vulnerabilities.
  • Command Argument Handling: Refactored the command passed to subprocess.Popen from a single string to a list of arguments, which is the recommended and safer way to execute external commands without shell interpretation.
  • Prompt Preprocessing: Removed the line that replaced single quotes in the prompt, as it is no longer necessary with the updated command execution method.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • unsloth/chat_templates.py
    • Updated subprocess.Popen call to use shell=False for enhanced security.
    • Converted the command string into a list of arguments for subprocess.Popen.
    • Removed the prompt.replace("'", "") line, as it is no longer needed.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly addresses a critical security vulnerability associated with using subprocess.Popen with shell=True. By switching to shell=False and passing the command as a list of arguments, the code is now protected against shell injection attacks. The associated removal of the single-quote replacement from the prompt is also a correct and necessary change that preserves data integrity. The implementation is clean and effectively resolves the security issue.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d7db609c74

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread unsloth/chat_templates.py
Comment on lines 2684 to 2685
prompt = tokenizer.apply_chat_template(messages, tokenize = False, add_generation_prompt = True)
prompt = prompt.replace("'", "") # Subprocess does not like ''
prompt = remove_special_tokens(tokenizer, prompt)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Restore apostrophe normalization for GGUF comparison

This change stops removing ' from chat-template prompts, but test_hf_gguf_equivalence still parses llama-cli output with re.findall(r"([\d]{1,}) \-\> \'([^\']{1,})\'", gguf_tokens), which cannot capture tokens that contain apostrophes. With the current default messages (e.g., It's, I'm), those GGUF tokens are skipped, gguf_tokenized becomes misaligned, and the HF vs GGUF check can fail even when tokenization is actually correct.

Useful? React with 👍 / 👎.

danielhanchen added a commit that referenced this pull request Feb 16, 2026
* Fix security-regression fallout in chat templates and PDL patching

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Drop security regression test files from PR scope

* Apply suggestion from @danielhanchen

---------

Co-authored-by: Daniel Hanchen <danielhanchen@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@danielhanchen
Copy link
Copy Markdown
Member

Closing this PR as superseded by #4062, which was merged on 2026-02-16 and consolidates/corrects the security-related changes from #4042, #4044, and #4045 while preserving runtime behavior.

@danielhanchen danielhanchen mentioned this pull request Feb 18, 2026
abiswas-realadvice pushed a commit to abiswas-realadvice/unsloth that referenced this pull request May 14, 2026
…nslothai#4045 (unslothai#4062)

* Fix security-regression fallout in chat templates and PDL patching

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Drop security regression test files from PR scope

* Apply suggestion from @danielhanchen

---------

Co-authored-by: Daniel Hanchen <danielhanchen@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.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