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
ghreads (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 --inputfile 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 --nameof a--name=valueargument, ifargis one.- push_
field 🔒 - A
gh apifieldkey=value(-F/--field):valueis 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.ghreads those too, so the scan must.Ok(None)for a path that isn’t there or is a directory (gh says so itself);Errwhen there is more than the scan reads. - read_
stdin_ 🔒limited - refusal_
text - The refusal: where, and what kind, never the text.
- replace_
files argswith every file the command reads replaced by its copy:filesmaps 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, thenok; orrefusedwith the reason on stderr and exit status 1.- scan
- Scan
gh <args>.read_filegives 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),Errwhen it is too large to scan.stdingives what stdin holds, read at most once. The bytes are kept as they are for the copyghis 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-Xand<value>.- sources 🔒
- Everything in
argsthat 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,--inputongh api. A file argument of-is stdin. - write_
copy 🔒 - Write
textwhereghcan read it as a file.