Skip to content

[Bug] Filter NUL byte (\x00) is not stripped — wrong escape "\\u0000" used instead of "\u0000" #6545

Description

@kelvin-qin

Contact Information

No response

MaxKB Version

MaxKB 2.10.4-lts

Problem Description

In apps/common/utils/common.py:443, s_list = ["\\u0000"] is a 6-character literal
string (backslash + "u0000"), not the actual NUL byte. .replace() therefore never
matches a real NUL byte, so NUL characters pass through the "special character filter".
This function is used to sanitize user/content input, so NUL bytes survive cleansing.

Steps to Reproduce

  1. Call filter_special_character("a\x00b") # input contains a real NUL byte
  2. Inspect the return value

The expected correct result

Expected Result

Return "ab" (the NUL byte is removed).

Actual Result (error log / stacktrace)

Return value is 'a\x00b' unchanged — the NUL byte is still present.
Reproduced by executing the real source function:
input repr: 'a\x00b' (len 3)
output repr: 'a\x00b' (len 3)
NUL byte still present after filter?: True

Related log output

Additional Information

Suggested Fix (optional)

  • Line 443: change s_list = ["\\u0000"] to s_list = ["\u0000"]
    (single backslash so Python decodes it as the NUL byte), or use:
    s_list = ["\x00"].

在Python中:

"\u0000" 是转义后的反斜杠加上字面文本 u0000,即字符串 \u0000(6个字符:, u, 0, 0, 0, 0)。
真正的NUL字节应写作 "\u0000"(不加双反斜杠),是单个字符 \x00。
因此,当调用 filter_special_character("a\x00b") 时,输入中包含的是真正的NUL字节 (\x00),而代码尝试替换的是字面字符串 "\u0000",二者完全不匹配,.replace() 不会有任何效果。

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions