scan on Windows: static tools scan an empty temp dir (false "No findings") and source files are rewritten in place
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
Direzione di ricerca
Start with cli/file_filter.py, cli/scan_cli.py, and the file staging logic around scan/static_scanner.py:602-618; trace how Windows absolute paths are joined to the temporary directory. Reproduce with the bookstore example and check both the staged files and the original file’s modification time. Done means Windows static tools receive the target files, source files remain unchanged, and the reported findings include relative paths.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Note: Setup, reproduction and debugging were done with Claude Code (Anthropic's AI coding assistant), including the root-cause analysis and the suggested fix. I reviewed the findings before filing.
Summary
On Windows, switch-trust scan never hands the target's files to bandit / OpenGrep / detect-secrets, so the static layer always reports 0 findings. As a side effect, each scanned file is rewritten in place over the original, because the "copy into the temp dir" lands on the source path. With no LLM configured, the result is a clean "No findings." report for code that has real issues.
Two smaller Windows blockers that have to be worked around before a scan even starts are listed at the end.
Environment
- Windows 11 (10.0.26200), Python 3.12.14
switch-trust-cli1.7.2 (confirmed in the PyPI wheel and onmainat4e3cac5)- OpenGrep 1.32.0 on PATH
- No LLM provider configured (static layer only)
Steps to reproduce
- Work around the two startup blockers below (termios, encoding).
switch-trust scan examples\bookstore_agent --output out.json- Check the modified time of
examples\bookstore_agent\agent.pybefore and after.
Expected
The README shows this example producing missing-authentication and unbounded-loop findings; the static rules alone should at least flag openai-agent-no-input-guardrails and openai-runner-no-max-turns (running OpenGrep directly on the folder with agent_opengrep_rules.yaml does return them). The source file should not be modified.
Actual
Findings 0
Tools bandit, opengrep, detect-secrets
No findings.
agent.py's modified time changes to the exact moment the static layer starts:
mtime: 2026-10-26 20:34:01.9506
log: 2026-10-26 20:34:01,951 INFO switch_trust.scan.static_scanner: Running Bandit on 1 files...
Root cause
cli/file_filter.py:65makes the target absolute (os.path.abspath), andcli/scan_cli.py:272buildsRepoFile(path=rf.path, ...)with that absolute path.scan/static_scanner.py:602(and:618for requirements) writes each file toos.path.join(py_dir, repo_file.path.lstrip(os.sep)).- On Windows the path is
C:\Users\me\project\agent.py.lstrip(os.sep)strips nothing (it starts with a drive letter), so the second argument is still absolute, andos.path.joindiscardspy_dirand returns the original path:>>> ntpath.join(r"C:\Users\me\AppData\Local\Temp\tmpab12\src", r"C:\Users\me\project\agent.py".lstrip("\\")) 'C:\\Users\\me\\project\\agent.py' - The "copy" is written over the source file (text mode,
"w"),py_dirstays empty, and bandit/OpenGrep scan an empty folder.
This happens for any scan target on a drive-letter path, C: included, so it affects every Windows user. On Linux/macOS the same code works by luck (/home/x/a.py → home/x/a.py stays inside the temp dir), but the findings' paths still don't match the RepoFile keys, so the exact-path lookup in tool_dispatcher.py (f.filepath == file_path) falls back to basename matching.
Effect on files: in our case the rewrite produced identical bytes, but in general it can convert LF to CRLF, and since files are read with errors="replace", any non-UTF-8 bytes would be permanently replaced with U+FFFD.
Suggested fix
Make RepoFile paths relative to the scan root, the same way scan/agent_scanner.py already does in _read_inventory_files:
# cli/scan_cli.py, handle_scan()
root = path if os.path.isdir(path) else os.path.dirname(path)
...
repo_file = RepoFile(
path=os.path.relpath(rf.path, root), content=content, size=len(content)
)
and, as a guard so a stray absolute path (e.g. C:\...) can never escape the temp dir again:
# scan/static_scanner.py
dest = os.path.join(py_dir, os.path.splitdrive(repo_file.path)[1].lstrip("\\/"))
With both applied locally, the same scan returns 3 static findings (input guardrails, output guardrails, max_turns), agent.py is untouched, and findings carry relative paths ("file": "agent.py"). Single-file targets work too.
Other Windows blockers (hit before the above)
ModuleNotFoundError: No module named 'termios'on any command:cli/console.pyimportstermios/ttyat module level. They are Unix-only and only needed for the arrow-key menu inselect(); importing them inside the TTY branch and falling back toPrompt.askonwin32fixes it.UnicodeEncodeError: 'charmap' codec can't encode charactersat the start of every scan:static_scanner.py:609writes the OpenGrep rules withopen(rules_path, "w")and no encoding, and the rules contain characters outside cp1252 (Windows' default).encoding="utf-8"fixes it. A few otheropen(..., "w")calls also lack an encoding (scan_cli.py:61,runner.py:273,repository_json.py:530);PYTHONUTF8=1works around all of them.
Happy to test a fix on Windows.
- Lingua principale
- Python
- Stelle
- 75
- Fork
- 7
- Merge medio
- 38m
- PR unite (30g)
- 2
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di sandbox-quantum/switch-trust-cli
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 56/100
sandbox-quantum/switch-trust-cli#26 · 3 commenti ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
sandbox-quantum/switch-trust-cli#6 · 2 commenti ·
Tutte le issue di sandbox-quantum/switch-trust-cli
Issue simili
-
Console writes URL credentials to the local log, though AGENTS.md says secrets never reach diskAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 86/100
sandbox-quantum/switch#2163 ·
I maintainer di solito rispondono entro 1 giorno
-
bug pydanty:is-working
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
pydantic/pydantic-ai#13939 ·
I maintainer di solito rispondono entro 1 giorno
-
priority: low python
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
LearningCircuit/local-deep-research#8849 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 86/100
francescopace/espectre#223 ·
I maintainer di solito rispondono entro 3 giorni
-
good first issue Status: Triaged
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 84/100
canonical/imagecraft#538 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni