fix(analyzer): stop EA1 from matching multiline gaps and markdown bold spans - #414
Open
AmirF194 wants to merge 1 commit into
Open
fix(analyzer): stop EA1 from matching multiline gaps and markdown bold spans#414AmirF194 wants to merge 1 commit into
AmirF194 wants to merge 1 commit into
Conversation
…d spans Signed-off-by: Amir Fathi <amirfathi.me@gmail.com>
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.
Fixes #405.
Root cause
EA1_PATTERNS[0]instatic_patterns_excessive_agency.pyis(?:tools?|permissions?)\s*:\s*\[?\s*['"]?\*['"]?\s*\]?. Python's\smatchesnewlines regardless of
re.MULTILINE, so the gap the pattern allows between thecolon and the wildcard value is unbounded across blank lines and paragraphs, and
the pattern has no check that the matched
*is a standalone token rather than thefirst
*of a**bold**span. Two shapes both produce a false-positive EA1finding on prose that grants no tool access: a blank-line gap (
tool:\n\n**Input Schema:**) and a markdown bold heading (**API Coverage vs. Workflow Tools:**).Fix
Replace the pattern with
(?:tools?|permissions?)\s*:[ \t]*\[?[ \t]*['"]?\*(?!\*|\w)['"]?[ \t]*\]?:restricts the gap to spaces/tabs (no longer crosses a blank line) and adds a
negative lookahead so the matched
*cannot be followed by another*or a wordcharacter, so it can no longer be the first character of a bold span or an
identifier. The three real wildcard-grant shapes (
tools: "*",tools: [*],permissions: '*') still match.Verification
tests/nodes/analyzers/test_static_patterns.py: the twofalse-positive shapes from the issue no longer produce an EA1 finding, and the
three real wildcard shapes still produce EA1 at MEDIUM severity.
make lintandmake format-checkclean.python:3.12-slimcontainer: 2800 passed (2795existing + 5 new), 14 skipped, 4 xfailed, matching the repo's
test-unitgate.Under
--cov(thetest-cirecipe), two unrelated tests intest_security_end_to_end.pyfail; reproduced the same two failures 3/3 runsagainst unmodified
mainunder the same--covflag, so this is a pre-existingflake independent of this change, not a regression it introduces.
docker-smoke(image build plustests/docker/smoke.sh) passes.