Skip to content

fix(selfhost): bound config lint file reads - #3952

Merged
JSONbored merged 1 commit into
mainfrom
codex/propose-fix-for-config-lint-cli-vulnerability
Jul 7, 2026
Merged

fix(selfhost): bound config lint file reads#3952
JSONbored merged 1 commit into
mainfrom
codex/propose-fix-for-config-lint-cli-vulnerability

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Motivation

  • The self-host config-lint CLI read files unbounded with readFileSync, which could follow symlinks or read special/very large files before the parser's byte cap was applied, risking hangs or excessive memory use.
  • Prevent attacker-controlled repository manifests (or CI runs) from causing availability issues by validating file metadata before reading content.

Description

  • Add readManifestTextForLint(path) that lstats the path, rejects symlinks, rejects non-regular files, checks stat.size against MAX_FOCUS_MANIFEST_BYTES, and only then calls readFileSync to return the UTF-8 text.
  • Import MAX_FOCUS_MANIFEST_BYTES and wire the CLI main() to use the guarded reader and emit the existing usage/error output on pre-read failures.
  • Add unit tests covering successful read at/under the limit, missing path, symlink rejection, non-regular file rejection, and oversized-file rejection, and keep the existing formatLintReport tests.

Testing

  • Ran git diff --check and it passed.
  • Ran the focused test file with npx vitest run test/unit/gittensory-config-lint-script.test.ts and all tests passed.
  • Ran npm run typecheck which completed successfully.
  • Attempted npm run test:ci; it progressed to test:coverage but the run stalled due to pre-existing RangeError: Maximum call stack size exceeded in test/unit/queue.test.ts unrelated to this change, preventing a full gate run.
  • Attempted npm audit --audit-level=moderate but the registry audit endpoint returned 403 Forbidden, so the audit could not be completed.

Codex Task

@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.66%. Comparing base (1ce4364) to head (e442709).
⚠️ Report is 15 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3952   +/-   ##
=======================================
  Coverage   93.66%   93.66%           
=======================================
  Files         372      372           
  Lines       34856    34856           
  Branches    12743    12743           
=======================================
  Hits        32649    32649           
  Misses       1588     1588           
  Partials      619      619           
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 7, 2026
@loopover-orb

loopover-orb Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Warning

🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨

⏸️ Gittensory review result - manual review recommended

Review updated: 2026-07-07 07:54:02 UTC

2 files · 1 AI reviewer · 2 blockers · readiness 93/100 · CI green · clean

⏸️ Suggested Action - Manual Review

  • No linked issue detected — If this PR is intended to solve an issue, link it explicitly in the PR body.
  • Maintainer requires a linked issue — Link the relevant issue (for example Closes #123) before opening the PR.

Review summary
This PR replaces an unbounded existsSync+readFileSync CLI read with a guarded readManifestTextForLint() that lstats the path, rejects symlinks and non-regular files, and enforces the existing MAX_FOCUS_MANIFEST_BYTES cap before reading, wiring main() to surface these pre-read failures through the existing usage/error path. The logic is correct, reuses an existing constant rather than introducing a new magic number, and the new tests exercise the real exported function (success, missing file, symlink, non-regular file, oversized file) rather than fabricating impossible states. This is a narrow, well-scoped hardening fix tied to a referenced regression (#2923) with no scope creep.

Nits — 4 non-blocking
  • scripts/gittensory-config-lint.ts: there's a TOCTOU gap between lstatSync and readFileSync — an attacker who can swap the path to a symlink after the check but before the read defeats the guard; consider opening with a file descriptor (fs.openSync with O_NOFOLLOW or fstat-after-open) instead of stat-then-read by path for a fully race-free check.
  • test/unit/gittensory-config-lint-script.test.ts: the oversized-file test writes MAX_FOCUS_MANIFEST_BYTES + 1 bytes to disk on every run, which is fine functionally but is unnecessary I/O if MAX_FOCUS_MANIFEST_BYTES is large — worth a comment noting the size is intentional if it's more than a few hundred KB.
  • Consider extracting the O_NOFOLLOW-safe read pattern into src/selfhost or a shared fs helper if other self-host CLIs read user-controlled manifest paths, to avoid re-implementing this guard elsewhere.
  • scripts/gittensory-config-lint.ts:20 could annotate the return type of lstatSync's stat variable explicitly instead of relying on inference, for readability at the call site.

Concerns raised — review before merging

  • No linked issue detected — If this PR is intended to solve an issue, link it explicitly in the PR body.
  • Maintainer requires a linked issue — Link the relevant issue (for example Closes #123) before opening the PR.
Signal Result Evidence
Code review ❌ 2 blockers 1 reviewer
Linked issue ⚠️ Missing No linked issue or no-issue rationale found.
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (no linked issue context).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 51 registered-repo PR(s), 43 merged, 343 issue(s).
Contributor context ✅ Confirmed Gittensor contributor JSONbored; Gittensor profile; 51 PR(s), 343 issue(s).
Gate result ❌ Blocking Repo-configured hard blocker found.
Review context
  • Author: JSONbored
  • Role context: owner (maintainer lane)
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: Python, TypeScript, JavaScript, Ruby, Go, Kotlin, MDX, Shell
  • Official Gittensor activity: 51 PR(s), 343 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Treat this as maintainer-lane context rather than normal contributor-lane activity.
  • Explain no-issue PR.
  • Link the issue being solved, or explicitly explain why this is a no-issue PR.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers.

  • Re-run Gittensory review

@loopover-orb loopover-orb Bot added the manual-review Gittensor contributor context label Jul 7, 2026
@JSONbored
JSONbored merged commit 1747226 into main Jul 7, 2026
10 checks passed
@JSONbored
JSONbored deleted the codex/propose-fix-for-config-lint-cli-vulnerability branch July 7, 2026 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. manual-review Gittensor contributor context

Development

Successfully merging this pull request may close these issues.

1 participant