Skip to main content

Module github_text

Module github_text 

Source
Expand description

The text scan: what an agent’s gh is refused for when the text it sends holds a credential.

The push scan (secret_scan.rs) looks at the lines a push adds; this looks at the words an agent puts in a pull request, an issue, a comment, a review, release notes or a gh api field, with the same formats and the same rule: say where and what kind, never the text itself. Spec: SPEC_CONNECT_WITH_GITHUB §5.6, phase G3b.

The gh function the wrapper exports calls github-text-guard -- <gh args> before it runs gh. The reply is the arguments to run, each followed by a NUL, then ok; or refused (the reason is on stderr). A body given on stdin (--body-file -, -F -, --input -) is read here, scanned, and handed to gh as a file, because stdin can’t be read twice.

Structs§

Hit
Where a credential-shaped string is in the command, and what kind.
Scan
What the scan of a command found.

Enums§

Source 🔒
One piece of text the command sends: given on the command line, or in a file (- for stdin).

Constants§

COPIES_DIR 🔒
What gh reads (a body file, stdin) goes to it as a copy in this folder of the temp directory, and copies older than a day are removed.
COPIES_KEEP 🔒
MAX_HITS 🔒
The most findings reported; a command with more is refused all the same.
MAX_TEXT_BYTES 🔒
The largest text read for the scan (a PR body is at most 65,536 characters; a gh api --input file can be bigger). A larger one is refused: it can’t be scanned.

Functions§

command_words 🔒
The two command words of gh <args> (pr create), skipping flags and the value of -R/--repo.
copies_dir 🔒
The folder the copies go in: the user’s own (mode 0700 on Unix; a folder that is someone else’s, or open to others, is not used), with the files older than a day removed.
is_api 🔒
is_flag 🔒
An argument that is a flag, not text: it starts with -, is short and has no whitespace. A body that begins with - (a list) or --- is text and is scanned.
long_flag_value 🔒
--name of a --name=value argument, if arg is one.
push_field 🔒
A gh api field key=value (-F/--field): value is text, or @file (@- for stdin).
read_file_limited 🔒
A file’s text, whatever it is: a regular file, a named pipe, /dev/stdin, a process substitution. gh reads those too, so the scan must. Ok(None) for a path that isn’t there or is a directory (gh says so itself); Err when there is more than the scan reads.
read_stdin_limited 🔒
refusal_text
The refusal: where, and what kind, never the text.
replace_files
args with every file the command reads replaced by its copy: files maps the value the command gave (- for stdin, or a path) to where the copy is.
run_github_text_guard
github-text-guard -- <gh args>: scan what the command sends. Prints the arguments to run (a stdin body replaced by a file), each followed by a NUL, then ok; or refused with the reason on stderr and exit status 1.
scan
Scan gh <args>. read_file gives a file’s text, whatever kind of file it is (a pipe, a device): Ok(None) when it isn’t there (gh will say so itself), Err when it is too large to scan. stdin gives what stdin holds, read at most once. The bytes are kept as they are for the copy gh is given (a binary upload must arrive unchanged); only the scan reads them as text.
scan_text 🔒
The credentials in text, a line at a time.
sends_text
Does gh <args> send text to GitHub that someone wrote: a PR, issue, comment, review, merge message, release notes or an API call?
short_attached 🔒
-X<value>: a short flag with its value attached (-bTEXT, -Fpath, -fkey=value), as -X and <value>.
sources 🔒
Everything in args that is text: each argument itself, and the files the file flags name, each with the place to report (the flag before it, else the argument’s position).
takes_file 🔒
Flags whose value is a file of text: --body-file/-F (and --notes-file) on the commands that take a body, --input on gh api. A file argument of - is stdin.
write_copy 🔒
Write text where gh can read it as a file.