Skip to content

Harden YARD and git clone against untrusted-repo RCE - #1918

Merged
schneems merged 3 commits into
mainfrom
schneems/harden-yard-and-git-clone
Sep 15, 2026
Merged

schneems merged 3 commits into
mainfrom
schneems/harden-yard-and-git-clone

Conversation

@schneems

@schneems schneems commented Sep 15, 2026

Copy link
Copy Markdown
Member

CodeTriage clones user-submitted repositories and runs YARD on them to build
docs. That path had a remote-code-execution exposure of the same class abused
against RubyDoc.info, plus a shell-injection risk in the clone and a temp-dir
leak. Three commits:

  1. Harden YARD doc parsing against .yardopts RCE — enable YARD safe mode
    and stop reading the repo's attacker-controlled .yardopts, closing the
    -e/--load / --query / --template-path code-execution vectors.
  2. Harden git clone of untrusted repos — allow-list clone URLs to
    https://github.com, run git via an argv array (no shell) with a --
    option guard, plus shallow / no-prompt flags.
  3. Clean up the temp dir cloned for doc parsing — wire up the previously
    dead cleanup so populate_docs! removes the temp checkout on every exit
    path (a caller-supplied location: is left untouched).

CodeTriage runs YARD against untrusted, user-submitted repositories to
build documentation. YARD reads a repo's `.yardopts` file by default, and
options like `-e/--load` (Kernel#load), `--query` (instance_eval), and a
custom `--template-path` execute code shipped in the repo -- the same class
of remote code execution abused against RubyDoc.info.

Enable YARD safe mode (which disables those code-execution features) and
set `use_yardopts_file = false` so the attacker-controlled `.yardopts` is
never read at all. YARD's parser is Ripper-based and static, so disabling
these opt-in exec features closes the RCE without affecting doc extraction.
GithubFetcher::Repo#clone interpolated a repo's clone URL straight into a
shell (`cd #{dir} && git clone #{clone_url}`), so a crafted URL could run
arbitrary shell commands, and git's own transports (file://, ext::...)
could be abused to reach the local filesystem or execute commands.

- Allow-list the URL: only https on host github.com (safe_clone_url?), and
  refuse anything else before running git (UnsafeCloneUrlError).
- Run git via Open3 array form (no shell) and put the URL after `--` so it
  can't be parsed as a git option.
- GIT_TERMINAL_PROMPT=0 avoids credential-prompt hangs; --depth 1
  --single-branch --no-tags keep the checkout small.
GithubFetcher::Repo#cleanup existed but was private and never called, so
every populate_docs! run leaked a Dir.mktmpdir clone -- a slow disk-fill.

Make cleanup public and guard it on @dir so it only ever removes a dir the
fetcher created, and call it from Repo#populate_docs! in an ensure block so
the temp dir is removed on every exit path (success, a raising parse, or a
failed clone). A caller-supplied `location:`, which we did not clone, is
left untouched.
@schneems
schneems force-pushed the schneems/harden-yard-and-git-clone branch from ac413e8 to d970b64 Compare September 15, 2026 18:38
@schneems
schneems marked this pull request as ready for review September 15, 2026 18:50
@schneems
schneems merged commit d1868f8 into main Sep 15, 2026
3 checks passed
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