Skip to content

[L-9] Network allowlist byte/char index mismatch on Unicode URLs (TM-UNI-019) #438

@chaliy

Description

@chaliy

Summary

The network allowlist path matching uses pattern_path.len() (byte count) as a char index into url_path, causing wrong path comparison on URLs with multi-byte characters.

Threat Model ID: TM-UNI-019

Affected Code

  • crates/bashkit/src/network/allowlist.rs:194url_path.chars().nth(pattern_path.len()) uses byte count as char index
// pattern_path.len() is BYTE count
// but chars().nth() expects CHAR index
url_path.chars().nth(pattern_path.len())

Impact

  • Path prefix matching may check the wrong character position when pattern contains multi-byte UTF-8
  • Could allow a URL that should be blocked, or block one that should be allowed
  • Low severity: URL paths with multi-byte chars in allowlist patterns are uncommon

Fix

Use pattern_path.chars().count() or use byte-based comparison consistently:

if url_path.len() > pattern_path.len() {
    url_path.as_bytes().get(pattern_path.len()) == Some(&b'/')
}

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    securitySecurity vulnerability or hardeningseverity/lowLow severity

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions