Harden YARD and git clone against untrusted-repo RCE - #1918
Merged
Merged
Conversation
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
force-pushed
the
schneems/harden-yard-and-git-clone
branch
from
September 15, 2026 18:38
ac413e8 to
d970b64
Compare
schneems
marked this pull request as ready for review
September 15, 2026 18:50
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.
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:
and stop reading the repo's attacker-controlled
.yardopts, closing the-e/--load/--query/--template-pathcode-execution vectors.https://github.com, run git via an argv array (no shell) with a--option guard, plus shallow / no-prompt flags.
dead
cleanupsopopulate_docs!removes the temp checkout on every exitpath (a caller-supplied
location:is left untouched).