Skip to content

fix(as2): match MCP config reads that resolve the home directory - #1159

Open
thedavididris wants to merge 1 commit into
NVIDIA:mainfrom
thedavididris:as2-home-directory-paths
Open

thedavididris wants to merge 1 commit into
NVIDIA:mainfrom
thedavididris:as2-home-directory-paths

Conversation

@thedavididris

Copy link
Copy Markdown

Fixes #1157.

AS2 matched 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. Those reads got no AS2 finding and the skill was reported as score: 7, recommendation: SAFE. The Path("~/.cursor/mcp.json").expanduser() form of the same read gives AS2 HIGH and score: 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, USERPROFILE and APPDATA read through os.environ[...], os.environ.get(...), os.getenv(...) or process.env;
  • Node's os.homedir().

A path that the existing agent-directory pattern already reports (.claude/mcp.json, .codex/mcp_config.json and 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_finding covers expanduser, Path(expanduser(...)), os.path.join from expanduser("~"), Path.home(), os.environ, os.environ.get("APPDATA"), os.getenv, Node's os.homedir() and process.env.HOME, and a .gemini/mcp_config.json path that must still be reported once. The nine cases that reach a config fail on main.
  • test_as2_home_directory_path_to_another_file_is_not_access checks 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.
  • On the reproduction skill from the issue, skillspector scan --no-llm now reports AS2 HIGH and score: 36, recommendation: CAUTION for 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 on main. That is separate from this change.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AS2 misses MCP config reads that resolve the home directory with expanduser, Path.home or HOME

1 participant