Skip to content

Check the URL scheme before downloading in generate_docset.py - #5803

Merged
nlohmann merged 1 commit into
developfrom
fix/docset-codacy
Oct 10, 2026
Merged

nlohmann merged 1 commit into
developfrom
fix/docset-codacy

Conversation

@nlohmann

Copy link
Copy Markdown
Owner

Codacy reports two Bandit findings in docs/docset/generate_docset.py, added in #5799 (which was merged with this Codacy failure). Every pull request that merges the current develop inherits them; #5738 fails Codacy for this reason.

Summary

  • B310 (urlopen with an unchecked scheme): download() now rejects any URL whose scheme is not http or https before opening it. Only URLs that is_remote() matched reach it, so nothing changes in practice; the check makes it explicit. The call is marked # nosec B310.
  • B506 (yaml.load): the Loader passed to yaml.load derives from yaml.SafeLoader (it only ignores mkdocs.yml's custom tags), so the load is safe. The call is marked # nosec B506 with that reason in a comment above it, following the # nosec style of check_version_history.py.
  • B324 (SHA-1): the hash that names downloaded files is created with usedforsecurity=False. Codacy did not report it, but Bandit does locally.

Tests

  • bandit on the file: no findings (before: B310, B506, B324).
  • python3 docs/docset/generate_docset.py list (run by make style_check) still succeeds.
  • ruff check (default rules): 18 findings before, 17 after; none new.

Public API

No breaking changes. This only touches the documentation tooling.


Written by Claude Code.

🤖 Generated with Claude Code

Codacy flagged two Bandit findings in the docset generator added in
#5799: B310 (urlopen with an unchecked scheme) and B506 (yaml.load).
download() now rejects anything but http(s) URLs before opening them,
and the yaml.load call is marked, since its Loader derives from
yaml.SafeLoader. The SHA-1 used to name downloaded files is marked as
not used for security.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
@nlohmann
nlohmann merged commit f8b47ff into develop Oct 10, 2026
52 of 167 checks passed
@nlohmann
nlohmann deleted the fix/docset-codacy branch October 10, 2026 14:21
@nlohmann nlohmann added this to the Release 3.13.0 milestone Oct 10, 2026
req = urllib.request.Request(u.geturl(), headers={'User-Agent': USER_AGENT})
with urllib.request.urlopen(req, timeout=20) as r:
# (the scheme is checked above)
with urllib.request.urlopen(req, timeout=20) as r: # nosec B310
ext = os.path.splitext(path)[1]
if u.query or not ext or path.endswith('/'):
digest = hashlib.sha1(url.encode()).hexdigest()[:12]
digest = hashlib.sha1(url.encode(), usedforsecurity=False).hexdigest()[:12]
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.

2 participants