Skip to content

fix(bcos): strip .git suffix instead of char-set in _detect_repo_name - #7955

Merged
Scottcjn merged 2 commits into
Scottcjn:mainfrom
Vyacheslav-Tomashevskiy:fix/bcos-detect-repo-name-rstrip
Jul 13, 2026
Merged

Scottcjn merged 2 commits into
Scottcjn:mainfrom
Vyacheslav-Tomashevskiy:fix/bcos-detect-repo-name-rstrip

Conversation

@Vyacheslav-Tomashevskiy

Copy link
Copy Markdown
Contributor

Problem

BCOSEngine._detect_repo_name() (tools/bcos_engine.py) derives the repo name from the git remote with:

name = url[len(prefix):].rstrip(".git").rstrip("/")

str.rstrip(".git") does not remove the .git suffix — it strips every trailing character that is a member of the set {'.', 'g', 'i', 't'}, greedily. So any repository whose name ends in ., g, i, or t is silently mangled:

remote current (wrong) correct
github.com/acme/audit.git acme/aud acme/audit
github.com/scottcjn/rustkit.git scottcjn/rustk scottcjn/rustkit
github.com/acme/my-bot acme/my-bo acme/my-bot
github.com/acme/toolkit acme/toolki acme/toolkit
github.com/acme/rustchain-client acme/rustchain-clien acme/rustchain-client

The trigger class is broad (-kit, -bot, -client, -agent, -test, audit, commit, unit, circuit, orbit, toolkit, …).

Impact

_detect_repo_name() sets report["repo_name"] in run_all(), and the full report is serialized and hashed into the on-chain commitment and certificate id:

report_json = json.dumps(report, sort_keys=True, separators=(",",":"))
commitment = blake2b(report_json.encode(), digest_size=32).hexdigest()
cert_id = f"BCOS-{commitment[:8]}"

So a BCOS trust attestation certifies a repository under a corrupted name, and the wrong name is bound into the commitment / cert_id for a large fraction of real repos.

Fix

name = url[len(prefix):].rstrip("/")
if name.endswith(".git"):
    name = name[:-len(".git")]
return name

Tests

Added test_repo_name_detection_preserves_names_ending_in_git_charset covering names ending in the .git charset. It fails on main (assert 'acme/aud' == 'acme/audit') and passes with the fix. The existing bcos suite stays green:

tests/test_bcos_engine.py tests/test_bcos_engine_core.py tests/test_bcos_recognition_broadening.py
19 passed

rstrip(".git") strips the trailing character SET {'.','g','i','t'}, not
the literal ".git" suffix, so any repo whose name ends in '.', 'g', 'i'
or 't' is silently mangled (e.g. audit->aud, rustkit->rustk, my-bot->my-bo,
toolkit->toolki). repo_name feeds report["repo_name"] which is hashed into
the BCOS commitment and cert_id, so the attestation certifies the wrong
repository identity for a large class of real repos.

Fix: rstrip('/') then remove an exact '.git' suffix. Add regression test
covering names ending in the .git charset (fails on main, passes here);
existing bcos suite stays green (19 passed).
@github-actions

Copy link
Copy Markdown
Contributor

Welcome to RustChain! Thanks for your first pull request.

Before we review, please make sure:

  • Non-doc PRs have a BCOS-L1 or BCOS-L2 label
  • Doc-only PRs are exempt from BCOS tier labels when they only touch docs/**, *.md, or common image/PDF files
  • New code files include an SPDX license header
  • You've tested your changes against the live node

Bounty tiers: Micro (1-10 RTC) | Standard (20-50) | Major (75-100) | Critical (100-150)

A maintainer will review your PR soon. Thanks for contributing!

@github-actions github-actions Bot added BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) tests Test suite changes size/S PR: 11-50 lines labels Jul 13, 2026
@Vyacheslav-Tomashevskiy

Copy link
Copy Markdown
Contributor Author

/claim

Fixes the rstrip(".git") character-set footgun in BCOSEngine._detect_repo_name — repos ending in ./g/i/t (audit, rustkit, my-bot, toolkit, …) were mangled and the corrupted name hashed into the BCOS commitment/cert_id. Regression test fails on main, passes with the fix; existing bcos suite green (19 passed).

@Scottcjn

Copy link
Copy Markdown
Owner

Maintainer validation: all 19 focused BCOS tests pass locally. Replacing rstrip(".git") is the correct fix because rstrip treats its argument as a character set and can corrupt repository names ending in g, i, or t. The aggregate CI failure is the stale main-branch fetchall/checksum baseline repaired in #7957, not a regression in this PR.

@Scottcjn
Scottcjn merged commit 2e3318f into Scottcjn:main Jul 13, 2026
11 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

RTC Reward

This merged PR earned 5 RTC — sent to Vyacheslav-Tomashevskiy.

RustChain Bounty Program

Scottcjn pushed a commit that referenced this pull request Jul 18, 2026
…epo_name (#7955) (#7998)

* test(bcos): add regression test for .git suffix stripping

Add test_detect_repo_name_strips_dotgit_suffix_not_chars to verify that
repos like audit, test, gigi are not truncated by the old rstrip('.git')
bug which stripped individual characters instead of the exact suffix.

Refs #7955

* test(bcos): add no-suffix and SSH coverage for _detect_repo_name regression

Address @elianguitarra review feedback:
- Add no-suffix URL cases ending in t/i/g (my-bot, toolkit) to ensure
  rstrip('/') + exact-suffix matching is preserved.
- Add SSH remote cases (git@github.com:owner/repo.git) to confirm both
  URL branches are protected by the fix.

Refs #7955
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) size/S PR: 11-50 lines tests Test suite changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants