feat(memory_poisoning): detect whitespace-padding evasion (MP4)#267
Closed
YanCheng-go wants to merge 1 commit into
Closed
feat(memory_poisoning): detect whitespace-padding evasion (MP4)#267YanCheng-go wants to merge 1 commit into
YanCheng-go wants to merge 1 commit into
Conversation
Blank-line runs, long in-line whitespace runs, and near-all-whitespace files can push malicious instructions below or past what a human reviewer sees in an editor, while an agent still reads the whole file as text. None of P2/TP2/MP2 catch plain whitespace padding (as opposed to character repetition or invisible-character tricks), so this adds a dedicated MP4 rule with three independently-scored signals: vertical blank-line runs (20+ lines), horizontal whitespace runs (80+ chars), and an oversized/near-total whitespace ratio. Padding is classified by Unicode whitespace category plus the zero-width set already used by P2, not a hardcoded space/tab set, and the horizontal signal skips fenced code blocks to avoid flagging ASCII art / table alignment. Closes NVIDIA#20 Signed-off-by: Yan Cheng <chengyan2017@gmail.com>
Author
|
Closing in favor of #24, which already implements this (rule P9, For the record, a review of this PR's implementation turned up real bugs worth knowing about if #24 or any future rework touches similar logic:
Didn't find evidence #24 has these issues, but flagging in case useful. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #20.
Adds a new MP4 rule to
static_patterns_memory_poisoning.pydetecting whitespace used to hide instructions from human review: a skill author pads a file with blank lines or long whitespace runs so malicious instructions sit far below/past what a reviewer sees in an editor, while the agent still reads the whole file as text.Three independently-scored signals, matching the proposal in #20:
Padding is classified by Unicode whitespace category (Python's
\salready covers NBSP, line/paragraph separators, ideographic space, etc.) plus the zero-width character set already used byP2(static_patterns_prompt_injection.py), rather than a hardcoded space/tab set — per the false-positive analysis in the issue.Registered
MP4inpattern_defaults.py(explanation, remediation, category, display name) and added a row to the README Memory Poisoning table. No new analyzer module or graph registration needed —static_patterns_memory_poisoningwas already wired intoANALYZER_NODE_IDS/ANALYZER_NODES.Test plan
make test— 1267 passed, 12 skipped, 34 deselected, 6 xfailed (no regressions)make lint(ruff check) — cleanruff format --check— cleantests/unit/test_patterns_new.py::TestMemoryPoisoningWhitespacePaddingcover: vertical run detection + threshold, confidence delta when content follows, horizontal run detection + threshold, fenced-code-block exclusion, zero-width chars counting as padding, oversized contiguous block, high whitespace ratio, and a negative case (normal content produces no MP4 findings)