Skip to content

🛡️ Sentinel: [CRITICAL] Fix Path Truncation Vulnerability via Null Byte Injection#3597

Closed
EffortlessSteven wants to merge 1 commit into
mainfrom
fix-null-byte-injection-14647859766468245499
Closed

🛡️ Sentinel: [CRITICAL] Fix Path Truncation Vulnerability via Null Byte Injection#3597
EffortlessSteven wants to merge 1 commit into
mainfrom
fix-null-byte-injection-14647859766468245499

Conversation

@EffortlessSteven
Copy link
Copy Markdown
Member

🚨 Severity: CRITICAL
💡 Vulnerability: The validate_model_request function validated file extensions using .ends_with(".gguf") but did not explicitly check for null bytes (\0). This allowed path truncation attacks where a malicious user could supply /etc/passwd\0.gguf.
🎯 Impact: While the Rust path validation might accept it, underlying C/C++ libraries (like llama.cpp) would truncate the string at the null byte, interpreting it as /etc/passwd, potentially exposing sensitive data or traversing the directory.
🔧 Fix: Explicitly rejected null bytes (\0) in the path validation logic.
✅ Verification: Run cargo test -p bitnet-server test_model_path_restriction -- --exact to verify the new tests pass.


PR created automatically by Jules for task 14647859766468245499 started by @EffortlessSteven

…_model_request

The validate_model_request function previously used `.ends_with(".gguf")`
to validate file extensions but did not explicitly check for null bytes
(`\0`). This exposed the server to path truncation attacks, as underlying
C/C++ libraries (like llama.cpp) would truncate the string at the null
byte, bypassing the extension check. This commit adds an explicit rejection
of null bytes in the path validation logic and includes a regression test.
@google-labs-jules
Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 1, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: bcf40bcd-afd4-4db3-b1c2-bd894c737f10

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-null-byte-injection-14647859766468245499

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Copy Markdown

@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 addresses a path truncation vulnerability by implementing a check for null bytes in model paths and updating the security documentation and unit tests accordingly. The feedback suggests broadening the validation to reject all control characters, rather than just null bytes, to provide more robust protection against path obfuscation and injection attacks.

// Prevent path traversal attacks
if model_path.contains("..") || model_path.contains("~") {
// Prevent path traversal attacks and null byte injection
if model_path.contains("..") || model_path.contains("~") || model_path.contains('\0') {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

security-medium medium

While explicitly checking for null bytes (\0) correctly addresses the path truncation vulnerability, it is generally safer to reject all control characters in file paths. Control characters like newlines or tabs are rarely valid in filenames and can be used to obfuscate paths or confuse logging systems. Consider broadening this check to use is_control() for more robust validation.

Suggested change
if model_path.contains("..") || model_path.contains("~") || model_path.contains('\0') {
if model_path.contains("..") || model_path.contains("~") || model_path.chars().any(|c| c.is_control()) {

Comment thread .jules/sentinel.md
## 2024-05-24 - Path Truncation Vulnerability via Null Byte Injection
**Vulnerability:** The `validate_model_request` function validated file extensions using `.ends_with(".gguf")` but did not explicitly check for null bytes (`\0`). This allowed path truncation attacks where a malicious user could supply `/etc/passwd\0.gguf`. While the Rust path validation might accept it, underlying C/C++ libraries (like `llama.cpp`) would truncate the string at the null byte, interpreting it as `/etc/passwd`, potentially exposing sensitive data.
**Learning:** String validation methods like `.ends_with()` in languages with length-prefixed strings (like Rust) can be bypassed if the string is later passed to C-style null-terminated string APIs.
**Prevention:** Always explicitly reject null bytes (`\0`) when validating file paths or input that will eventually interface with C/OS APIs.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Consider broadening the prevention advice to include all control characters, as they are generally unsafe in file paths and can lead to various injection or obfuscation issues beyond just null byte truncation.

Suggested change
**Prevention:** Always explicitly reject null bytes (`\0`) when validating file paths or input that will eventually interface with C/OS APIs.
**Prevention:** Always explicitly reject control characters (including null bytes `\0`) when validating file paths or input that will eventually interface with C/OS APIs.

@EffortlessSteven
Copy link
Copy Markdown
Member Author

Closing as superseded by #3626.

Reason: duplicate null-byte model path validation fix. The canonical PR is ledger-aligned under TRUTH-003, includes regression coverage, and is recorded in the alignment tracker.

@google-labs-jules
Copy link
Copy Markdown

Closing as superseded by #3626.

Reason: duplicate null-byte model path validation fix. The canonical PR is ledger-aligned under TRUTH-003, includes regression coverage, and is recorded in the alignment tracker.

Understood. Acknowledging that this work is superseded by #3626 and stopping work on this task.

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