piishape

package
v0.207.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package piishape holds the credential- and identity-shaped patterns that the compaction-eval corpus vet refuses (the "vet classes"). It exists so a package that cannot import internal/compeval (compeval imports internal/agent) can still ask the same question compeval asks: does this text look like it carries a secret.

Index

Constants

View Source
const KeywordRunClass = "credential-keyword-run"

KeywordRunClass names the residual check in a list of classes that still match a text.

View Source
const KeywordRunReach = 32

KeywordRunReach is how many characters after a credential keyword a long value may start.

Variables

View Source
var Classes = []Class{
	{"email", regexp.MustCompile(`(?:` + jsonEscape + `)?[A-Za-z0-9._%+-]+@` + emailDomainStart + `[A-Za-z0-9.-]*\.[A-Za-z]{2,}`)},
	{"private-key-block", regexp.MustCompile(`-----BEGIN [A-Z ]*PRIVATE KEY-----`)},
	{"bearer-token", regexp.MustCompile(`(?i)` + lead + `bearer\s+[A-Za-z0-9_\-][^` + stop + `]{15,}`)},
	{"api-key-assignment", regexp.MustCompile(`(?i)` + assignment(false))},
	{"aws-access-key", regexp.MustCompile(lead + `AKIA[0-9A-Z]{16}\b`)},
	{"github-token", regexp.MustCompile(lead + `gh[pousr]_[A-Za-z0-9]{20,}\b`)},
	{"provider-key", regexp.MustCompile(lead + `sk-(?:(?:ant|proj|svcacct|admin)-[A-Za-z0-9_\-]{20,}|[A-Za-z0-9]{20,})`)},
	{"jwt", regexp.MustCompile(lead + `eyJ[A-Za-z0-9_\-]{8,}\.[A-Za-z0-9_\-]{8,}\.[A-Za-z0-9_\-]{8,}`)},
	{"basic-auth", regexp.MustCompile(`(?i)` + lead + `authorization` + headerGap + `{0,8}?[:=,>\[]` + headerGap + `{0,8}?basic\s+[A-Za-z0-9+/=_\-][^` + stop + `\])}]{11,}`)},
	{"auth-field", regexp.MustCompile(`(?i)` + lead + `auth\\*['"]\s*:\s*\\*['"][A-Za-z0-9+/=_\-][^` + stop + `]{11,}`)},
	{"cookie-header", regexp.MustCompile(cookieHeader)},
}

Classes are the DETERMINISTIC refusal classes for corpus vetting: a corpus is a committed/replayed artifact, so credential- or identity-shaped content refuses the whole corpus rather than being silently scrubbed (scrubbing would change the bytes the hash pins). The table moved here from internal/compeval with six classes; later classes are appended at the end, never reordered.

What the classes recognise:

  • api-key-assignment: a key word (api key, private/access/auth key, secret, token, passwd, password or passwords, PGPASSWORD, passphrase, credential or credentials), which may follow an underscore or any non-word character (GITHUB_TOKEN=, OPENAI_API_KEY=, DB_PASSWORD=), a flag letter (-Dpassword=) or a terminal control sequence (a color code), and may be followed by access/key/secret/token/value/id parts (AWS_SECRET_ACCESS_KEY=, client_secret_value=, secret_id=) and digits (password1=), then = or : (a control sequence may stand between the name and the colon), or else _PASS= or _PWD= (DB_PASS=, MYSQL_PWD=; the short words need the underscore and the equals sign, so a test runner's "PASS: TestName" and the shell's PWD stay quiet), then a value of 12 or more characters. The value may start with a quote (any number of backslashes may stand before it: JSON text inside a shell string doubles them) and then any character except whitespace, a quote, a comma, a semicolon, an ampersand, a backslash, the escape byte, '/', '.', '[' or ']'; it runs to the next whitespace, quote, comma, semicolon, ampersand, backslash or escape byte, so it takes in '.', '/', '+', '=', '@', '~' and ':' (a JWT after access_token=, a slash-bearing secret key) and a leading symbol (DB_PASSWORD=!...). A backslash ends the value because tool-call arguments are JSON text and a backslash there is an escape: running through it would take the closing quote or the next command with it. The match is the WHOLE value on purpose: the harvest redactor is derived from this table, so a value the pattern stops short of would be written out with its tail. A name that only contains the word (MAX_TOKENS, token_count, tokenizer) does not match. A path after a key-ish name (token_store=/var/lib/x) starts with '/', so it does not match; token_store=var/lib/xyzzy does, which is the safe direction. A literal that starts with a quote is a QUOTED literal: its value runs to the closing quote of the same kind, so a space, a comma, a semicolon, an ampersand and the other kind of quote are part of it (a shell export of a key with a space in its value, an env file line with a single-quoted value, a JSON value with a comma), and so is Go's JSON escape for &, < and >. It stops at a backslash (an escaped quote in JSON text), a line break and the escape byte of a control sequence, and the closing quote is not part of the match; an unterminated quote runs to the end of the line. The first-character rule above holds inside the quote, and the 12 characters are counted inside it. A quoted prose value after a key name matches too, which is the safe direction. A QUOTED literal of 12 or more characters is also matched behind a wider operator: Go's := (password := "..."), a comparison (== or !=), a hash rocket (=>), a type annotation in front of the = (const token: string = "...", password: str = "..."), a closing quote or bracket after the name (os.environ["API_TOKEN"] = "...", {'password' => '...'}, a quoted JSON key "token": "..."), and a b, r, u or f prefix on the string (password = b"..."). The quote is required there: after := or == an unquoted value is an identifier or a call (token := strings.TrimSpace(x)), which would flood. A call that passes the name and the literal as two arguments is matched when the name is quoted right behind the opening paren (t.Setenv("API_TOKEN", "...")); the match then starts at the paren. A list of strings (["token", "client_identifier"]) stays quiet.
  • bearer-token: the word bearer, whitespace, then a value of 16 or more characters that starts with a letter, digit, underscore or hyphen and runs to the next whitespace, quote, comma, semicolon, ampersand, backslash or escape byte (whole value, for the same reason).
  • provider-key: a bare provider key, sk- followed by 20 or more letters and digits (OpenAI style), or sk-ant-, sk-proj-, sk-svcacct-, sk-admin- followed by 20 or more key characters. sk-learn and similar short names do not match.
  • jwt: three base64url segments of 8 or more characters, the first starting eyJ.
  • basic-auth: an Authorization header (also Proxy-Authorization, or a quoted JSON key) with the Basic scheme and a value of 12 or more characters. A short run of punctuation (at least one of : = , > [) may stand between the name and the scheme, so a printed Go header (map[Authorization:[Basic ...]]), a call (setHeader('Authorization', 'Basic ...'), Header.Set("Authorization", "Basic ...")), a subscript and a hash literal are matched; so do a line break and indentation (a pretty-printed document, a YAML list: a dash is punctuation) and a placeholder left by an earlier class (the other value of a header with two); the value ends before a closing bracket, paren or brace, which base64 never holds.
  • auth-field: a quoted auth key whose quoted value is an encoded string of 12 or more characters (a container registry's config file).
  • cookie-header: a Cookie or Set-Cookie header, taken as one WHOLE SPAN and not a cookie at a time. The name and an opener fire (the punctuation the Basic header takes may stand between them, so a JSON list, a subscript, a hash and a printed Go header match; a comma counts only when a quote follows it, as in Header.Set("Cookie", "..."), so prose stays quiet; a header fold, a line break, may stand before the punctuation and after it; a greater-than sign right behind the name, an XML tag or an arrow, opens a line; a bracket behind the punctuation, a space or the name opens a list, and a header line takes none) and the span holds a cookie value of 12 or more characters: 12 characters with no white space from the start of a bare value or from the opening quote of a quoted one, an escape counting as one (a JSON unicode escape, or a backslash run and the character it escapes). The match then runs from the header name to the first of the end of the line (a line break, its JSON escape or the end of the text), the closing quote of the string the header sits in (a quote that opens no quoted cookie value: a bare quote, or a backslash run of 1, 3, 7 or 15 and a quote, which are the levels of escaping of a header line or a shell command, of JSON text, and of each further layer; a single quote ends it too, so a curl command's header ends before the shell's closing quote) and the closing bracket of a list or the closing brace of a Go slice literal (a JSON list, a printed Go header, the Go-syntax print of one, a Python list: one span however many elements and lines it has, a bracket inside a string element not ending it, a string of the list closed in the middle of it and open only as its last element). The closing quote and the bracket are not part of the match, so redacted text keeps its quoting and Args stay valid JSON. Nothing inside the span is read for an alphabet: a quoted value with a space, an apostrophe, an ampersand, a comma, a semicolon, a tab, an escaped quote, a doubled backslash, an octal escape, a shell escape (an escaped dollar sign or backtick) or one of Go's HTML escapes (backslash-u0026, 003c, 003e) is inside it, a bare value with a shell escape or a backslash path is inside it, and so is every other cookie and attribute on the line. Over-redacting a cookie line is accepted by design: it is evidence of a header, not of the build. Two rules tell a quote that opens a value from the one that closes the string the header sits in. A quote after an equals sign opens a value only when a value can start behind it (not white space, not a separator or a closer, so base64 padding or an empty last cookie in front of the closing quote does not make it an opener; an empty value is still a value), and a quoted value that is open at a line break goes on to its closing quote when that is within three more line breaks, and ends at its line when it is not (a truncated line takes the rest of its line and no more). An apostrophe in an unquoted value ends the span (note=don't cannot be told from the quote that closes a header written in single quotes), so a cookie behind one is not covered, and neither is one behind a bare double quote inside a value (a raw JSON value). The fine-grained grammar of a cookie value lives only in the harvest redactor, which remembers the values of a span for its value-tail gate. In a list that a bracket closes, a closing bracket is a character of the cookie when a character of a value follows it and the one in front of it is no opening bracket (sid=ab]cd, user[id]=v), and the open string a cut list ends in stops at a closing bracket; the Go-syntax print of any list ([]string{, []interface {}{, []any{), a bytes or raw prefix in front of a quote (b'cookie'), an underscore in front of the name (HTTP_COOKIE) and a value that starts with an ampersand or a closing bracket are covered. The class does not read a YAML block list item, a backtick-quoted value or a HAR name/value pair as an opener; KeywordRun (keywordrun.go) is the check that fails closed on those.

Every class that starts with a word also accepts, right before the word, a JSON string escape (a backslash and n, r, t, b or f, or backslash-u and four hex digits) or a terminal control sequence (the escape byte, '[', parameters and a letter; as raw output or as the JSON escape of the byte): in tool-call arguments the newline before a line that starts with PASSWORD= is those two characters, in colored output a color code stands there, and a word boundary sees neither. The match then carries the escape or sequence; Lead names it and the redactor keeps it.

Not covered (the redactor does not scrub these either; see the reducer's honest limits and docs/systems/coding-agent.md): a key name written in camel case (githubToken=), a key name the list above does not hold (dbpassword=, sid=, session= outside a cookie header), a command-line flag with a space (--token value, curl -u user:pass), URL userinfo (scheme://user:pass@host), an authorization scheme other than Bearer and Basic (Digest, NTLM), a provider prefix the table does not list (sk_live_, xoxb-), an unsigned JWT, a high-entropy string with no key name or known prefix, a value that starts with '/', '.', '[' or ']' (an ampersand may start one, and a cookie value may start with a closing bracket), the part of a value after a backslash inside it (a double-quoted cookie keeps its escapes, above), an UNQUOTED value after :=, == or => (an identifier or a call, by design), a value passed apart from its name (fmt.Sprintf("password=%s", v)), a terminal control sequence other than escape-bracket-letter (a charset switch, an operating-system command, the one-byte form of the bracket), and a Basic header whose name and scheme (or a cookie header whose name and cookies) are more than eight punctuation characters apart or have a word between them (a placeholder, a line break and a dash are not words), a YAML block list item, a backtick-quoted value and a HAR name/value pair (KeywordRun fails closed on these: the trace is left out, the value is not redacted), a cookie behind a single quote or an apostrophe in an unquoted value, a cookie behind a bare double quote inside an unquoted value, a cookie behind a backslash and a lowercase n or r in an unquoted value (the JSON escape of a line break ends the line, so a raw path such as C:\new\x ends the span there; a capital, as in C:\Name, is an ordinary escape), a bare value that holds a shell escape inside four layers of escaping (more than sixteen backslashes), a quoted cookie whose quotes carry a number of backslashes that is no level of escaping (not 0, 1, 3, 7 or 15), a quoted value that starts with white space or a separator, a Go slice literal whose type is left out, a header folded again after its first cookie, and a cookie passed apart from its header name (curl -b, a jar).

Functions

func AssignmentValue

func AssignmentValue(m string) string

AssignmentValue returns the credential value of a match of the api-key-assignment class: the quoted literal's body, or the unquoted value, without the key name, the operator or the opening quote. It is "" when m is not a whole match of the class (strip Lead first). A redactor remembers exactly this part, because the name, a type annotation or a call in front of a literal is ordinary text elsewhere.

func KeywordRun

func KeywordRun(s string) bool

KeywordRun reports whether s holds a credential keyword followed, within KeywordRunReach characters, by a long value run (see above), or a list that goes on behind the placeholder of a cookie header. A placeholder is not read and ends the reach of the keyword in front of it.

func Lead

func Lead(m string) string

Lead returns the escape that opens a match, if any: a JSON string escape or a terminal control sequence that stood in front of the class's first word. It is not part of the credential, so a redactor keeps it and puts its placeholder after it; replacing it would break the JSON of the text it sits in.

func Matching

func Matching(s string) []string

Matching names the classes that match s, sorted. Nil when none does.

Types

type Class

type Class struct {
	Name string
	Re   *regexp.Regexp
}

Class is one refusal class: a name and the pattern that recognizes it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL