Skip to content

feat: harden the GitHub remote detector (BootUI 2.6.0) - #377

Draft
ffroliva wants to merge 45 commits into
mainfrom
feat/0.11.0-github-detector
Draft

ffroliva wants to merge 45 commits into
mainfrom
feat/0.11.0-github-detector

Conversation

@ffroliva

@ffroliva ffroliva commented Dec 5, 2026 •

Copy link
Copy Markdown
Owner

Summary

Task 1.5 of the 0.11.0 plan (#367): the GitHub remote detector reads repository metadata within fixed limits and
parses remotes with BootUI 2.6.0's rules (GitHubRepositoryDetector).

  • src/sharpit/engine/collectors/github/detector.py:
    • bounded reads: config 256 KiB, .git file, commondir and HEAD 8192 bytes; the walk stops at 64 levels;
      invalid UTF-8 is decoded with replacement, as BootUI does;
    • a remote path has exactly two valid segments after leading and trailing / and one .git are removed; a raw
      query or fragment, even an empty one, is rejected;
    • Java-equivalent trim (characters up to U+0020) and line splitting;
    • characters java.net.URI rejects (whitespace, control characters, \ " < > ^ { | }, a second @in the authority, a malformed percent escape) are rejected explicitly, sinceurllib.parse.urlsplitaccepts them; a host outside the hostname grammar gives "No GitHub origin remote was detected", as a nullgetHost()` does in BootUI;
    • a gitdir: pointer to a UNC or device path stops the walk before any filesystem call on it; an empty pointer
      resolves to its own folder (BootUI readGitDirFile); neither falls through to an enclosing repository;
    • Remotes and detect_remotes() report origin and upstream with BootUI's upstream reason text (used by Task 1.8).
  • src/sharpit/engine/collectors/github/token.py: the credential host is trimmed as Java trims; a remote host or a
    GH_HOST value containing a control character (other than ASCII whitespace padding) resolves no token.
  • docs/reference/matrix-updates/0.11.0-github.tsv: rows github.detector.unc-pointer,
    github.detector.percent-encoding, github.detector.uri-characters, github.token.control-chars.

Review scope

This branch was cut from the 0.11.0 integration line, so against main the diff also shows the changes of the earlier 0.11.0 pull requests (Wave 0, #368 to #376, and the S1 and S11 fixes). Those merge first; the changes of this pull request are the commits after Merge branch 'release/0.11.0' into feat/0.11.0-github-detector, in src/sharpit/engine/collectors/github/, tests/engine/collectors/github/ and docs/reference/matrix-updates/0.11.0-github.tsv.

Red evidence

Each test was run against the code before its fix (scripts/dev/red_check.py, or the earlier source restored in the
worktree); every red below is an assertion.

Finding Test Red
https://github.com/a/b/extra and trailing-slash forms were judged by len < 2 test_detector_rejects_malformed_origin_remotes, trailing-slash cases assertion: Repository returned
An empty ? or # passed urlsplit test_detector_rejects_malformed_origin_remotes[...?] assertion: Repository returned
Unbounded config and metadata reads; unbounded walk size-limit and depth-63/64 tests assertion
\, {, ` , a second @, NBSP, \x01` in a remote were accepted test_detector_rejects_malformed_origin_remotes[...]
A malformed percent escape in userinfo was accepted test_detector_rejects_malformed_origin_remotes[https://x%zz@github.com/team/service] assertion: Repository returned
A host outside the hostname grammar was reported as a non-GitHub host test_detector_rejects_host_outside_uri_hostname_grammar assertion: reason text
A config with an invalid byte in a comment was refused (BootUI decodes with replacement) test_detector_decodes_non_utf8_config_comments_with_replacement assertion: not a Repository
An empty or UNC gitdir: pointer fell through to an enclosing repository test_unsafe_gitdir_pointer_does_not_fall_through_to_enclosing_repository[...] (3 cases) assertion: outer/repo returned
A token host with a control character was trimmed and matched test_a_host_gh_could_misread_resolves_nothing[...] assertion: token resolved
A GH_HOST with a leading control character bound the enterprise token GH_HOST control-character case assertion: token resolved

Two added cases were already green before their fix and stay as guards: a malformed escape inside a path segment
(rejected by the segment rule) and the prefix-only UNC guard in test_gitdir_unc_pointer_is_not_resolved.

Deviations from BootUI

  • github.detector.unc-pointer (safety model over parity): a UNC or device gitdir: target is refused before any
    filesystem call. Known limits: a .git symlink or junction, a relative pointer through a symlinked directory and a
    mapped network drive letter are not covered.
  • github.token.control-chars: a host string with a control character resolves no token; BootUI trims and accepts it.
  • github.detector.uri-characters: explicit rejection of what java.net.URI rejects (Python's parser is laxer).
  • github.detector.percent-encoding: percent-encoded path segments are refused.

Verification

uv run ruff check (All checks passed), uv run ruff format --check (1395 files already formatted), uv run pyright
(0 errors); uv run pytest -q -n 4 tests/engine/collectors/github tests/fastapi -k github (249 passed);
tests/test_code_shape.py tests/test_ported_citations.py tests/safety/test_w7_github_safety.py (10 passed). The full
suite runs in CI.

Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
… file

Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
…e protocol

Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
The Origin header is parsed as scheme://host[:port] with an http or https scheme, as BootUI 2.6.0 does: a path (a trailing slash included), query, fragment, userinfo, control character, trailing colon, unsupported scheme or a port above 65535 makes the origin unreadable, and an unreadable origin is cross-site. The value is no longer trimmed.\n\nA port of more than five digits is refused before int() converts it, in the origin and in the request's own Host, so a very long port is a cross-site refusal and no longer an unhandled ValueError. Adds a property test of the origin parser.

Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
…UI 2.6.0)

A write that carries Sec-Fetch-Site must send same-origin or none (ASCII, case-insensitive); same-site, cross-site, an empty value and any unknown value are refused. A present but empty Origin header is an unreadable origin and is cross-site, no longer read as absent. A same-site navigation GET still loads the shell, and an API path still requires the request's own scheme, host and port. A request whose own origin cannot be formed stays cross-site where that comparison applies.\n\nDocuments the rule in SECURITY.md and the BootUI contract note, and records the deviations in the 0.11.0 guard matrix fragment.

Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Record the two deviations of the inactivity log from BootUI 2.6.0 in a matrix fragment, update the MVP plan text that still described the old log line, extract the inactivity logging of install() into a helper to keep its complexity at the pinned count, and wrap one over-long test assertion.

Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
An invalid SHARPIT_ENABLED must log exactly one record, the fixed warning, as BootUI does. The count of the remaining configuration warnings stays.

Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
An invalid SHARPIT_ENABLED is already reported by the fixed inactive warning. Counting its settings warning as well produced a second WARNING record, where BootUI logs one.

Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
…tests

Port BootUiInactiveStartupDiagnosticTests.deliberateDisablementIsSilentAtInfo, cite the BootUI tests the other inactivity tests port, and keep the expected log texts in one test module. A single Inactivity alias types the inactivity category. The matrix row for the warning count records that it leaves out the invalid SHARPIT_ENABLED warning.

Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>

# Conflicts:
#	tests/fuzz/test_trust_boundary_fuzz.py
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
…token

Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
…ootUI's URI rules

Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
@ffroliva ffroliva changed the title fix: bound and align the GitHub remote detector with BootUI 2.6.0 feat: harden the GitHub remote detector (BootUI 2.6.0) Dec 5, 2026

This branch has not been deployed

No deployments
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.

1 participant