Skip to content

🛡️ Sentinel: [CRITICAL] Fix Path Truncation Vulnerability#3471

Draft
EffortlessSteven wants to merge 2 commits intomainfrom
sentinel-fix-null-byte-injection-3383889181527515022
Draft

🛡️ Sentinel: [CRITICAL] Fix Path Truncation Vulnerability#3471
EffortlessSteven wants to merge 2 commits intomainfrom
sentinel-fix-null-byte-injection-3383889181527515022

Conversation

@EffortlessSteven
Copy link
Copy Markdown
Member

🚨 Severity: CRITICAL
💡 Vulnerability: Path Truncation Vulnerability via Null Byte Injection.
The model path validation checked for file extensions (.gguf) and traversal strings (..) but failed to reject strings containing a null byte (\0). In Rust, &str can contain null bytes, but when passed to underlying C-style OS APIs, the path is truncated at the null byte. An attacker could bypass the extension validation by supplying a path like /models/secret\0.gguf. The validation would pass (ends in .gguf), but the OS would attempt to read /models/secret.
🎯 Impact: Potential arbitrary file read within the allowed model directories (or broader if combined with other vulnerabilities), bypassing security controls designed to restrict file types.
🔧 Fix: Updated the validate_model_request logic in crates/bitnet-server/src/security.rs to explicitly check for and reject paths containing \0. Added a corresponding regression test.
Verification: Run cargo test -p bitnet-server --lib security::tests.


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

Updates the `validate_model_request` function in `bitnet-server` to
explicitly reject any paths containing null bytes (`\0`). This prevents
attackers from bypassing file extension restrictions (e.g., passing
`/models/secret\0.gguf` to read `/models/secret`) by exploiting
C-level string truncation bugs in the underlying filesystem APIs.

Adds a test to verify null bytes are correctly rejected.
@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 Mar 27, 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: 5d95004b-796a-4c8c-b3bf-f228f8331be8

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 sentinel-fix-null-byte-injection-3383889181527515022

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 introduces a check for null bytes in model paths to prevent injection vulnerabilities and adds a corresponding regression test. The reviewer suggests strengthening the validation by using char::is_control to block all control characters and recommends adding further test cases to cover these scenarios.


// Prevent path traversal attacks
if model_path.contains("..") || model_path.contains("~") {
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-high high

While adding the check for the null byte (\0) is a great fix for the reported path truncation vulnerability, we can make this validation even more robust by disallowing all control characters in the model path, not just the null byte. File paths should not contain control characters, as they can lead to various injection or interpretation issues.

You can achieve this by using char::is_control. This would also cover the null byte case since \'\0\'.is_control() is true.

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

Comment on lines +646 to +650
// Null byte injection attempt
assert!(matches!(
validator.validate_model_request("/models/llama.gguf\0.gguf"),
Err(ValidationError::InvalidFieldValue(msg)) if msg == "Invalid characters in model path"
));
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

This is a great regression test for the null byte injection! To complement the suggested change of blocking all control characters, it would be beneficial to add another test case that verifies other control characters are also rejected. This ensures the validation is robust against a broader class of invalid inputs.

        // Null byte injection attempt
        assert!(matches!(
            validator.validate_model_request("/models/llama.gguf\0.gguf"),
            Err(ValidationError::InvalidFieldValue(msg)) if msg == "Invalid characters in model path"
        ));

        // Other control character injection attempt
        assert!(matches!(
            validator.validate_model_request("/models/llama\x07.gguf"), // Using BELL character
            Err(ValidationError::InvalidFieldValue(msg)) if msg == "Invalid characters in model path"
        ));

Updates the `validate_model_request` function in `bitnet-server` to
explicitly reject any paths containing null bytes (`\0`). This prevents
attackers from bypassing file extension restrictions (e.g., passing
`/models/secret\0.gguf` to read `/models/secret`) by exploiting
C-level string truncation bugs in the underlying filesystem APIs.

Adds a test to verify null bytes are correctly rejected.

Also fixes GitHub Actions CI failure due to running out of disk space
during `cargo test --workspace` on Ubuntu 22.04 runner. This removes
unnecessary toolchains like Android, dotnet and ghc, and minimizes
test artifacts by disabling debug symbols.
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