Repository navigation
fix(as2): match MCP config reads that resolve the home directory - #1159
Open
thedavididris wants to merge 1 commit into
Open
thedavididris wants to merge 1 commit into
thedavididris wants to merge 1 commit into
Conversation
AS2 reported a read of an MCP client's config only when the path was one string literal directly inside open() or Path(), or followed cat, less, head or grep. open() does not expand "~", so code that reads one of these files resolves the home directory first, and those reads got no finding. Add a direct-access pattern for a home-directory reference (expanduser, Path.home, os.homedir, or HOME, USERPROFILE and APPDATA from the environment) followed on the same line by a quoted path that ends in an MCP config file name. Paths the agent-directory pattern already reports are left to it, so one read stays one finding. Fixes NVIDIA#1157 Signed-off-by: David Idris <david@glemad.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 #1157.
AS2 matched a read of an MCP client's config only when the path was one string literal directly inside
open(...)orPath(...), or followedcat,less,headorgrep.open()does not expand~, so code that reads one of these files resolves the home directory first. Those reads got no AS2 finding and the skill was reported asscore: 7, recommendation: SAFE. ThePath("~/.cursor/mcp.json").expanduser()form of the same read gives AS2 HIGH andscore: 36, recommendation: CAUTION.Fix
One more direct-access AS2 pattern: a home-directory reference followed on the same line by a quoted path that ends in an MCP config file name. It uses the existing file-name pattern, so it covers the same clients. The home-directory references are:
expanduser(,Path.home();HOME,USERPROFILEandAPPDATAread throughos.environ[...],os.environ.get(...),os.getenv(...)orprocess.env;os.homedir().A path that the existing agent-directory pattern already reports (
.claude/mcp.json,.codex/mcp_config.jsonand the like) is left to that pattern, so this change does not turn one read into two findings. That pattern now has a name,_AGENT_DIRECTORY_MCP_FILE, because both places use it. Its text is unchanged.Not changed: setup instructions that only name one of these files are still not flagged, and a home-directory path to any other file is not AS2.
Tests
test_as2_home_directory_paths_produce_findingcoversexpanduser,Path(expanduser(...)),os.path.joinfromexpanduser("~"),Path.home(),os.environ,os.environ.get("APPDATA"),os.getenv, Node'sos.homedir()andprocess.env.HOME, and a.gemini/mcp_config.jsonpath that must still be reported once. The nine cases that reach a config fail onmain.test_as2_home_directory_path_to_another_file_is_not_accesschecks a home-directory path to another file, a file with a similar name (mcp-schema.json), and a home-directory reference and a config name on separate lines.skillspector scan --no-llmnow reports AS2 HIGH andscore: 36, recommendation: CAUTIONfor each of the four forms that scanned as SAFE.One thing I noticed and left alone: a line that two existing AS2 patterns match, such as
open(".claude/mcp.json"), is already reported as two AS2 findings onmain. That is separate from this change.