Repository navigation
fix!(pypi): resolve with pip, markers/extras, company index; harden project settings - #42
Conversation
The PyPI scanner followed every Requires-Dist entry, including optional
extras and requirements for other platforms or Python versions, and took
versions from the environment ts-scan runs in. Scans therefore contained
documentation and test tools of dependencies (sphinx-lint, pytest, ...)
without versions, or with the versions installed alongside ts-scan.
- Resolve the project and its dependencies with
`pip install --dry-run --ignore-installed --report`
- Follow extras only when requested (`--pypi:extras`, `foo[bar]`) and
evaluate environment markers
- Expand every package once per requested extra, stop at cycles
- Use PEP 503 normalized names in component keys
- Add `--pypi:indexUrl` / `--pypi:extraIndexUrl` for company package
repositories; `${VAR}` references are expanded from the environment,
credentials are redacted in messages
- Abort the scan with exit code 2 if dependencies cannot be resolved,
instead of falling back to the ts-scan environment
- Read the project metadata through pip as well, removing the silent
non-isolated build fallback (#35); drop `build` and `shippinglabel`
- Apply tsproject.toml settings to `ts-scan scan`, which takes
`sources` instead of `path` and never read them
Closes #40
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Bandit found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
Index URLs may contain credentials. They were passed as pip arguments, visible in the process list, and str(CalledProcessError) - used when pip wrote nothing to stderr - put the full command line including the token into the error message. - Pass index URLs as PIP_INDEX_URL / PIP_EXTRA_INDEX_URL - Never use the CalledProcessError representation; redact credentials of all URLs in pip's messages - ci(bandit): exclude ./tests - the pattern "tests" did not match and reported every assert in the test suite (B101) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…g' into fix/40-pypi-markers-extras
…nvironment
Reading tsproject.toml in `ts-scan scan` let a foreign repository set
`node_executable` and thereby run a program of its choice (reproduced),
overwrite files through `output_path`, enable npm lifecycle scripts, or
send environment variables to an index of its choice through `${VAR}`
in `pypi_indexUrl`.
- The project settings loader drops `<pm>_executable`, `<pm>_forward`,
`output_path`, `node_enableLifecycleScripts` and every value containing
`$`, with a warning; they are tool settings like the API key (ADR-001)
- Index credentials come from tool settings, e.g. TS_SCAN_PYPI_INDEXURL
- Regression test: scanning a repository whose tsproject.toml sets
node_executable does not run it
- Docs: settings layers in README, usage and architecture (ADR-002);
fix `--npm:` option prefixes, the scanner is called `node`
- CHANGELOG: release 2.0.0
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ials Addresses the two valid points of Paul's review of #42: - the pip install --dry-run call had no timeout; an unreachable index blocked the scan indefinitely. It now stops after PIP_TIMEOUT_SECONDS (600) and aborts with a DependencyResolutionError. - _redact_urls only matched scheme://user:pw@; user:pw@host without a scheme is redacted as well. A colon is required, so git@host stays readable. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
pbrQA-eacg
left a comment
There was a problem hiding this comment.
✅ Review: Approved
Summary: All previously flagged issues (cycle handling, credential redaction, timeout, URL-normalization duplication) have been addressed with tests; no new critical issues found.
Findings:
[INFO] Cycle-handling fix verified
File: src/ts_scan/pm/pypi.py (_create_dep_from_metadata)
Issue: Previously flagged CRITICAL about reentrancy/partial extras tracking during cycles.
Fix: N/A — self.__expanded[canonical_name] = set(extras) is now set before recursing into _active_requirements, and test_scan_expands_each_package_once_and_stops_at_cycles plus test_scan_follows_extras_requested_by_a_later_occurrence cover multi-node/extras scenarios adequately.
Why: Resolved; acceptable.
[INFO] Credential redaction without scheme fixed
File: src/ts_scan/pm/pypi.py _redact_urls``
Issue: Previously flagged WARNING about bare user:pass@host not being redacted.
Fix: N/A — new regex branch handles no-scheme case; `test_redact_urls_hides_credentials_with_and_without_scheme` and `test_redact_urls_keeps_text_without_credentials_readable` confirm both redaction and false-positive avoidance (e.g. `git@github.com`).
Why: Resolved.
[INFO] pip timeout added
File: src/ts_scan/pm/pypi.py _resolve``
Issue: Previously flagged INFO about missing subprocess timeout.
Fix: N/A — PIP_TIMEOUT_SECONDS = 600 passed to `_exec`, raises `DependencyResolutionError` on `TimeoutExpired`, tested in `test_pip_is_called_with_a_timeout` and `test_scan_aborts_when_pip_does_not_finish_in_time`.
Why: Resolved.
[INFO] Base URL duplication resolved
File: src/ts_scan/api.py, src/ts_scan/cli/upload.py
Issue: Previously flagged WARNING about duplicated /v2 suffix logic.
Fix: N/A — shared normalize_base_url/API_VERSION_SUFFIX constant now used by both TrustSourceAPI and _app_base_url, tested in test_base_url_gets_the_api_version_exactly_once and test_app_link_drops_the_api_version.
Why: Resolved.
[INFO] Windows file-permission caveat still undocumented
File: src/ts_scan/cli/__init__.py (write_private_file, update_private_file)
Issue: Previously flagged WARNING; still not explicitly documented as POSIX-only in README/CHANGELOG, though tests correctly skip on Windows.
Fix: Optional — add one sentence to README noting Windows permission limitation.
Why: Non-blocking, cosmetic documentation gap only.
Good work — this iteration addresses all substantive concerns from the prior review with solid test coverage. Approving.
Test Results:
- Unit: ➖ not provided
- Lint: ➖ not provided
- Types: ➖ not provided
The merge-base changed after approval.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
pbrQA-eacg
left a comment
There was a problem hiding this comment.
✅ Review: Approved
Summary: All previously flagged findings were addressed with tests in this diff; no new critical issues found.
Findings:
[INFO] Previously flagged cycle-handling, redaction, timeout, and URL-duplication fixes confirmed present in this diff (test_pypi.py cycle/extras tests, _redact_urls dual-branch regex, PIP_TIMEOUT_SECONDS usage, shared normalize_base_url). No action needed.
[INFO] Windows file-permission documentation gap remains unaddressed but was already marked non-blocking in prior review.
Approving — no new CRITICAL issues identified in this iteration.
Test Results:
- Unit: ➖ not provided
- Lint: ➖ not provided
- Types: ➖ not provided
requests.post/get had no timeout, so an unresponsive server blocked a scan upload indefinitely (Bandit: call to requests without timeout). Requests now time out after DEFAULT_REQUEST_TIMEOUT (60 s); TS_REQUEST_TIMEOUT overrides it and TrustSourceAPI takes an explicit timeout argument. A timeout is raised as TrustSourceAPI.Error, which the commands already handle. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Escalation to @jthDEVThis PR has been through 3 review iterations without reaching a mergeable state. The review-iteration cap was reached without the PR becoming mergeable — see the most recent review comment on this PR for the specific findings that were never resolved. Please review the findings above and decide how to proceed:
— Paul (automated QA) |
pbrQA-eacg
left a comment
There was a problem hiding this comment.
✅ Review: Approved
Summary: All previously flagged findings (cycle-handling, credential redaction, timeout, URL-duplication) remain fixed and verified across two prior approval passes; no new critical issues in this diff.
Findings:
[INFO] No changes since last approval
File: N/A
Issue: This diff matches what was already reviewed and approved twice; no new substantive changes to re-flag.
Fix: N/A
Why: Converging — re-approving to close out the loop rather than re-litigate settled findings.
Test Results:
- Unit: ➖ not provided
- Lint: ➖ not provided
- Types: ➖ not provided
Closes #40. Also addresses #35 (removes the silent non-isolated build fallback) — leaving that issue open for discussion.
Problem
The PyPI scanner followed every
Requires-Distentry — including optional extras (extra == "doc") and requirements for other platforms/Python versions — and took versions from the Python environment ts-scan itself runs in. Scanningts-sbom-checkerwithtrustsource/ts-scan:latestproduced 148 nodes / 69 packages, 54 without a version (sphinx-lint, furo, pytest-, jaraco-, …), and the real dependencies with the image's versions (click 8.1.7, packageurl-python 0.16.0).Changes
pip install --dry-run --ignore-installed --report, i.e. exactly whatpip install <project>would install. The project metadata comes from the same report, so the build backend is fetched from the configured index too.--pypi:extras dev,testfor the project,foo[bar]for dependencies); environment markers are evaluated.pypi:importlib-metadata).--pypi:indexUrl/--pypi:extraIndexUrl, orpypi_indexUrl/pypi_extraIndexUrlin the project'stsproject.toml(without credentials). In tool settings (CLI, environment such asTS_SCAN_PYPI_INDEXURL, user settings file)${VAR}references are expanded, e.g. for a CI secret. Index URLs are passed to pip viaPIP_INDEX_URL/PIP_EXTRA_INDEX_URL, never as arguments, and credentials are redacted in all messages.scan: project settings were never applied tots-scan scan(it takessources, notpath); fixed incli/__init__.py.tsproject.tomltoscanwould have let a foreign repository run a program of its choice vianode_executable— reproduced. The project settings loader now drops<pm>_executable,<pm>_forward,output_path,node_enableLifecycleScriptsand every value containing$(no environment expansion from a repository), with a warning. Regression test included; verified to fail without the fix.excluded_paths: ./tests— the patterntests(Exclude tests/ from Bandit scanning #33) never matched and reported everyassertin the test suite.docs/usage.md,docs/architecture.md(ADR-002);--npm:option prefixes corrected to--node:. CHANGELOG finalized as 2.0.0.buildandshippinglabelreplaced bypackaging.Verification
pytest: 190 passed (including fix!: take API endpoint and key from tool settings only (2.0.0) #41's tests; new tests intests/test_pypi.pyandtests/test_tool_settings.py, pip mocked)trustsource/ts-scan:latestwith this branch'ssrc/ts_scanmounted, scanningts-sbom-checker:--network nonetsproject.tomlhttps://***@…tsproject.toml+ token from env${VAR}andnode_executableintsproject.tomltsproject.toml, credentials viaTS_SCAN_PYPI_INDEXURL--pypi:extras analyse, all with versions.Notes
ts-scan-actiononly after a newtrustsource/ts-scanimage is published (the current 1.10.0 image predatesmain).🤖 Generated with Claude Code