Claude/jolly kirch 89a1f6#15
Merged
Merged
Conversation
Adds a QR encoding of `verification_url_complete` (the verification URL with the user_code pre-filled) to the device-code enrollment pane. Admin scans the workstation screen with a phone instead of typing the URL + short code by hand — useful when the workstation and admin are in the same room but no shared input device. - pychron/cloud/qr.py — new module. `make_qr_png` writes a segno- generated PNG (error-correction M, scale 8, border 2 — readable from arm's length) to a caller-supplied path with 0600 permissions on POSIX. `make_qr_for_device_code` is the convenience wrapper that emits `~/.pychron/qr/device_<lab>.png`, overwriting any prior file for that lab so a re-enrollment does not pick up a stale QR. - pychron/cloud/tasks/preferences.py — new `_pending_qr_path = File` trait (excluded from .cfg), populated in `_on_device_code_user_code` alongside the existing user_code + URL fields. QR generation failure is non-fatal — the typed code + URL still work. Reset in the start handler and in `_reset_pending` so the QR clears on cancel / success / terminal failure. - pyproject.toml — adds `segno>=1.6,<2` (pure Python, ~24KB, writes PNG via stdlib zlib — no PIL required). - test/cloud/test_qr.py — 5 unit tests: PNG magic bytes, file lands under `~/.pychron/qr/`, re-enrollment overwrites rather than accumulating, empty-URL rejected, default host slug. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Address path-traversal finding from /security-review on PR #14. `make_qr_for_device_code(host_slug=...)` previously interpolated the slug directly into the output filename (`device_<slug>.png`). The caller in `tasks/preferences.py` passes `self.lab_name`, which can hold an attacker-influenced value (server-issued after a prior enrollment, or a hand-edited preference) carrying `..` / `/` / null bytes. The resulting file would land outside the scoped `~/.pychron/qr/` directory. Two-layer fix: 1. `_sanitize_slug` whitelists `[A-Za-z0-9_-]` at function entry; any other byte becomes `_`. This collapses traversal payloads to inert filenames before they reach the path layer. 2. After path construction, `os.path.realpath(out_path)` is asserted to live under `os.path.realpath(qr_dir())`. A defense-in-depth guard so any future slug-handling regression cannot escape the scoped directory. Tests cover the traversal payloads (`../../etc/passwd`, `..`, `../../tmp/owned`, `a/b/c`, `lab.name`, `foo\x00bar`) plus the preservation of normal slugs (`NMGRL`, `lab-2024_NM`). 138/138 cloud tests green. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Context
Verification
Verification details:
...Risk
Target Branch Check
develop, the activedev/*stream,release/*, orhotfix/*)Follow-ups