Skip to content

The agent that grows with you

fix(plugin-guard): a bracket span holding a quote is a list, not a character class

Teknium400ed22df105
diff --git a/tests/tools/test_plugin_guard.py b/tests/tools/test_plugin_guard.py
index 1972aed6cdd..6ecec4f7625 100644
--- a/tests/tools/test_plugin_guard.py
+++ b/tests/tools/test_plugin_guard.py
@@ -810,6 +810,7 @@ class TestIntakeFalsePositiveRound2:
files = dict(BASE_FILES)
files["desktop/plugin.js"] = 'eval("\\x63\\x75\\x72\\x6c \\x68\\x74\\x74\\x70");\n'
files["mix.py"] = 'x = "\\x63\\x75" + re.sub(r"[\\x00-\\x1F]", "", "\\x72\\x6c")\n' # class + payload
+ files["tests/test_audio.py"] = 'frames = [Frame(b"\\x01\\x00" * 200), Frame(b"\\x02\\x00")]\n' # list, not class
result = scan_plugin(_mk_plugin(tmp_path, files), source="owner/repo")
sev = {f.file: f.severity for f in result.findings if f.pattern_id == "hex_encoded_string"}
- assert sev == {"desktop/plugin.js": "medium", "mix.py": "medium"}
+ assert sev == {"desktop/plugin.js": "medium", "mix.py": "medium", "tests/test_audio.py": "medium"}
diff --git a/tools/plugin_guard_context.py b/tools/plugin_guard_context.py
index 8ad4b02229a..d31de75cb95 100644
--- a/tools/plugin_guard_context.py
+++ b/tools/plugin_guard_context.py
@@ -322,9 +322,10 @@ def is_pip_install_in_prose_literal(finding: Finding, line: str) -> bool:
# same escapes as RANGES inside a bracket class: ``/[\x00-\x1F\x7F]/``, ``[\x1b\x9b][[\]()#;?]*``.
# Bytes named inside ``[...]`` are matched, never assembled into a string, so when every escape
# on the line sits inside a character class the finding is informational. One ``\xHH`` outside a
-# class (a payload beside a filter) keeps the pattern's severity.
+# class (a payload beside a filter) keeps the pattern's severity, and so does a bracket span that
+# holds a quote — ``[b"\x01\x00" * 200]`` is a Python LIST of byte strings, not a class.
_HEX_ESCAPE = re.compile(r"\\x[0-9a-fA-F]{2}")
-_CHAR_CLASS = re.compile(r"\[(?:[^\]\\\n]|\\.)*\]")
+_CHAR_CLASS = re.compile(r"\[(?:[^\]\\\n\"'`]|\\.)*\]")
def is_hex_in_char_class(finding: Finding, line: str) -> bool: