Repository navigation
fix(lp4): recognize Go capability calls in least-privilege check - #1124
Varshith-Kali wants to merge 2 commits into
Conversation
LP4 reported env and file_read as over-declared in Go skills because the capability patterns only covered Python and JavaScript calls. Extend the env, file_read and file_write pattern tables with the idiomatic Go calls: os.LookupEnv and os.ExpandEnv for env; os.ReadFile, os.Open, os.ReadDir, filepath.Walk/WalkDir/Glob and io.ReadAll for file_read; os.WriteFile, os.Create and os.CreateTemp for file_write, plus the pre-1.16 ioutil aliases. Patterns follow the existing table conventions (qualified call names, case-insensitive), so Python and JavaScript detection is unchanged. Fixes NVIDIA#1121. Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
|
CI note on the current head: test-unit shows only the 4 known pre-existing failures in tests/nodes/analyzers/test_json_decoded_views.py (unicode fence source coordinates, |
rng1995
left a comment
There was a problem hiding this comment.
[SkillSpector Review]
Decision — Request changes.
Value and readiness — Recognizing Go's direct file and environment calls fixes LP4 reports that can prompt authors to remove permissions their skills actually use. The shared capability table needs tighter evidence before this change is ready.
Material findings
mcp_least_privilege.py:94–112addsio.ReadAllas file-read evidence. It can consume anyio.Reader, including a network response or an in-memory buffer. This can clear a genuinely over-declared file-read permission or create an LP1 finding for an undeclared file-read capability that was never used. The newreadalltest passes an arbitrary reader, so it currently locks in that mistake. Keep the direct file APIs, drop the generic reader match unless its input is proven to be a file, and add a negative case with an in-memory reader. Capability patternsos\.open\bis applied to every file through the shared case-insensitive table. A Pythonos.opencall with write-only flags now counts as read evidence. Scope the new Go invocation patterns to Go components, or use an equivalent language-sensitive match, and cover a Python write-only call in the unchanged-behavior tests. Capability scan
PIC tradeoffs — Uses the existing bounded matcher. Restricting evidence to language and API pairs that establish the capability preserves LP1 precision and LP4 coverage without introducing Go data-flow analysis.
Verification and gaps — Reviewed the complete diff, the matching and reporting paths, PR discussion, and the unit-job logs. The recorded job reported 26,126 passes and four failures in Unicode fence source coordinates. The contributor reports reproducing those failures on the PR base. The Go fixtures do not cover the generic-reader or cross-language cases above. Static review only.
Reviewed head: 5e2137cda8ebb5e8a3a89691872840ef660a7e3f
io.ReadAll consumes any io.Reader, so it proved nothing about file access: it could clear a genuinely over-declared file-read permission or create LP1 for an undeclared file-read that was never used. Drop it from the file-read table; a file opened with os.Open still counts through os.Open. Move the remaining Go patterns (os.ReadFile, os.Open, os.ReadDir, filepath.Walk/Glob, os.WriteFile, os.Create, os.CreateTemp, os.LookupEnv, os.ExpandEnv, ioutil aliases) into a Go-only table applied only to .go files. The shared table is language-agnostic, so os.open previously counted a Python write-only os.open call as read evidence. Tests: remove the readall positive case that locked in the mistake; add negative cases for an in-memory reader and a network response body, a positive case for os.Open plus io.ReadAll, and Python write-only os.open cases for LP4 and LP1. Addresses review on NVIDIA#1124. Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
|
Thanks for the review, both findings are fixed in ec630e0. io.ReadAll: dropped from the file-read table entirely. It consumes any io.Reader, so on its own it proves nothing about file access. A file read through os.Open plus io.ReadAll still counts, through os.Open itself. The old readall positive test is removed, and there are now negative cases for an in-memory buffer (bytes.NewBufferString) and a network response body, both of which keep LP4 and fire no LP1 for file_read. os.open cross-language leak: all new Go patterns moved into a Go-only table that _detect_capabilities applies only to .go files (os.ReadFile, os.Open, os.ReadDir, filepath.Walk/Glob, os.WriteFile, os.Create, os.CreateTemp, os.LookupEnv, os.ExpandEnv, ioutil aliases). A Python os.open with write-only flags no longer counts as read evidence; covered by new tests for both LP4 (permission stays over-declared) and LP1 (no finding with an unrelated declaration). os.Getenv stays in the shared table since it was already covered there before this PR. Tests: tests/test_mcp_least_privilege.py, 80 passed. The new negative tests fail on the previous head, so they catch the old behavior. |
Fixes #1121.
Bug: LP4 reported env and file_read as over-declared in Go skills because the capability patterns in mcp_least_privilege.py only covered Python and JavaScript calls. A Go skill honestly declaring env and file_read got false LP4 findings, and the only way to clear them was to delete true declarations, leaving the manifest under-declared.
Fix: extend the env, file_read and file_write pattern tables with the idiomatic Go calls:
Patterns follow the existing table conventions (qualified call names, case-insensitive), so Python and JavaScript detection is unchanged.
Repro (minimal Go skill from the issue, os.LookupEnv + os.ReadFile):
Tests: added TestLP4GoCapabilityPatterns in tests/test_mcp_least_privilege.py: 12 parametrized Go cases (one per new call, each fails before the fix and passes after), a negative control proving LP4 still fires for a Go skill that declares permissions its code never uses, an LP1 check proving undeclared Go writes are now caught, and Python/JavaScript unchanged checks.