Documentation
¶
Overview ¶
Package valueshape decides one question: does this string LITERAL's own shape prove it is something other than a credential?
It is a leaf. It imports no codefit package except internal/core/namematch, and nothing outside the standard library, because both providers' SEC-001 consume it (Go directly; TypeScript through a rule-engine operator, T4) and neither may pull the other in through it.
What it does ¶
SEC-001 (both providers) affirms "this looks like a hardcoded credential" at Confidence 1.0 once a variable's NAME establishes it (ADR 0075, internal/core/namematch): the value itself is checked for nothing beyond "non-empty string". That is too little. `const secretFile = "lib/config.ts"` is a real false affirmation, reproduced on main@76dbaec over MCP.
NotACredential(value) closes the VALUE side of that gap, narrowly. It is a veto, never a classifier: given the un-quoted content of a string literal, it reports (Form, true) only when the shape is positive proof the value is a URL, a URN, an environment-variable name, or a file path — and ("", false) in every other case, meaning "this establishes nothing; the name gate's affirmation stands." The four Forms are enumerated by Forms(), in the fixed order NotACredential checks them: URL, URN, env-var-name, file-path — the first that proves wins, and the returned Form is itself the evidence that eventually reaches a finding's message.
Edge cases ¶
The empty string returns ("", false): it establishes nothing about its own shape. Every guard resolves an internal parse ambiguity — a URL whose fragment or query fails url.ParseQuery, most concretely — toward NOT vetoing, because a blind form is worse than one line of noise a developer has to read (see NotACredential's own doc comment for the guard-by-guard detail, and CLAUDE.md's TDD/mutation section for why "when in doubt, do not veto" is this project's standing rule rather than a one-off judgment call here).
What this does NOT see, and the census behind it ¶
Census, 2026-09-28, real sensor over MCP (not a static probe: SEC-001's name gate driven through the actual AST/regex path, because a hand-rolled enumeration cannot reproduce a tokenizer's real boundaries — the same discipline ADR 0075 already applied to itself).
Go: 320 SEC-001 name-gate findings over the Go standard library (net/http, crypto, database/sql, cmd/go), golang.org/x/oauth2, golang.org/x/sys, modelcontextprotocol/go-sdk, gotreesitter, and codefit's own tree. Bucketed by the shape of the VALUE, not the finding's severity:
URL 103
short test literal 65
URN 46
short identifier 36
SCREAMING_SNAKE env-var name 35
hex/base64 blob 14
contains '/' 10 (includes AWS's own published
example secret access key — the
reason no bare '/' veto exists
anywhere in this package)
text with spaces 4
header name 2
placeholder 2
path with extension 1
other 2
TypeScript: 52 SEC-001 name-gate findings over three real projects (1,545 files total; project identities withheld per this repository's dogfood doctrine — counts and forms are publishable, locations are not). URL, URN, env-var-name, and path-with-extension: 0 occurrences. Text with spaces: 2. The remainder is short literals and identifiers, mostly under test paths.
The bucket table above is a HUMAN categorization of the 320 values, made to decide which four buckets this package should close — it is not what NotACredential itself returns. Measured directly against the real predicate, over that same 320-value corpus, the VETOED-BY-FORM counts are:
FormURL 102 FormURN 46 FormEnvVarName 18 FormFilePath 1 ----------------------- total vetoed 167 / 320 (52.2%)
The gap between a bucket count and its predicate count is expected and not a discrepancy to chase: the bucket table records what a human judged the VALUE to look like, while the predicate additionally enforces every guard in NotACredential's doc comment (no userinfo, no credential-named query key, at least one underscore, a closed extension list, and so on). Adding the token-like guard below moves the URL count from 102 to 100 (167 total to 165): the two URLs it demotes to keep-firing are occurrences of `https://login.live.com/oauth20_token.srf`, whose path segment `oauth20_token.srf` is itself token-like (18 characters, letters and a digit) despite being an OAuth endpoint NAME, not a secret. That is accepted noise, not a defect: this package has no way to distinguish "a token-shaped endpoint name" from "a token", and the alternative — narrowing the guard until it stops catching that — is exactly the kind of narrowing this package's own doctrine (see WHAT THIS DOES NOT SEE below) refuses to make without new measurement in the other direction.
Widening the token-like guard to host labels, query keys, fragment keys and encoded path segments (2026-11-23) was re-measured with the real sensor over the same corpus: the predicate's counts stay 100 / 46 / 18 / 1, and no previously silenced value fires again. None of those 100 URLs carries a query, a fragment or a percent-escape, and their longest host label is 15 bytes, so that zero measures the host-label position only; the other three positions have no instance in the corpus to be noisy on.
Four buckets above are exactly the four Forms this package closes: URL, URN, SCREAMING_SNAKE env-var name, path with extension. The rest are DELIBERATELY left firing, with the reason each was rejected as a guard:
- short test literal / short identifier (`test_client_secret`, `progressToken`) — by SHAPE, indistinguishable from a real short secret such as `s3cr3t`, which ADR 0075 requires to keep firing (no length floor). This package has no notion of "test" or "identifier-like" to tell them apart, and inventing one here would be exactly the kind of speculative widening ADR 0075's own vocabulary work refused.
- hex/base64 blob, and specifically a JWT or an STS-style token — never vetoed. A JWT's dots would pass FormFilePath's charset; what stops it is the CLOSED extension list, which a base64url segment never matches. '+', '/' and '=' — base64's own alphabet — are why FormFilePath's charset excludes '+' and '=' outright, and why plain '/' alone (also the path separator) was never treated as sufficient proof.
- contains '/' — never a bare veto condition on its own. The measured reason is concrete: AWS's own published example secret access key, `wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY`, contains '/' (and '+'). A '/'-only guard would have silenced the exact string AWS publishes to demonstrate what a real key looks like. A path with no listed extension (`/etc/secrets/db`) keeps firing for the same reason.
- text with spaces — a prose-veto guard was PROPOSED and DROPPED 2026-09-28, before it was ever implemented: a passphrase is a secret WITH spaces ("correct horse battery staple"), and the measured yield for vetoing prose was 4/320 Go findings plus 2/52 TypeScript findings — noise this project accepts rather than risk silencing a real passphrase. Prose keeps firing; `master secret` is the concrete, catalogued example of the accepted noise.
- header name (`X-Api-Key`) — never vetoed: mixed case fails FormEnvVarName's all-uppercase requirement, and no extension fails FormFilePath.
- placeholder — a name like `YOUR_CLIENT_SECRET` IS vetoed here, but only because it happens to also be SCREAMING_SNAKE-shaped; a placeholder that does not match the environment-variable-name pattern (an upper-case letter first, at least one underscore, none leading, trailing or doubled) is not covered by any guard in this package and keeps firing: `changeme`, `<token>`, `TODO`, and `__SECRET__`, whose underscores are all leading or trailing.
- path with extension — the one Go bucket this package DOES close, and the bucket that motivated this feature (`lib/config.ts`).
- "other" (Go: 2, uncategorized) — not investigated further; the census is a sample against real code, not an exhaustive taxonomy, and a residual "other" bucket this small does not justify a fifth guard without its own measured evidence.
One further declared limit, inside FormEnvVarName itself: a value made only of uppercase letters, digits and underscores, WITH at least one underscore, IS vetoed. An AWS access key ID (the published example one is the fixture in valueshape_test.go; it is not spelled here because SEC-001's layer 1 matches that format in any source text, comments included) and `JBSWY3DPEHPK3PXP` (base32 TOTP secret shape) both keep firing precisely because neither carries an underscore — the guard requires one specifically so it does not swallow either of those real secret shapes, and that trade-off is the boundary of what FormEnvVarName can prove, not an oversight to be tightened later without new measurement.
The URL token-like guard, and its own declared limit ¶
A URL that clears every other FormURL guard can still carry its secret in plain sight, in a position no credential-named-key check was ever meant to see: a Slack incoming-webhook URL, a Discord webhook URL, an S3 presigned URL, an Azure SAS URL, and a Telegram bot-token URL each embed the secret itself in a PATH SEGMENT or a QUERY/FRAGMENT VALUE whose KEY (`sig`, `X-Amz-Signature`, or no key at all for a bare path segment) namematch's credential vocabulary does not recognise. Measured directly (the same real predicate as above): all five of those shapes were VETOED as FormURL before this guard existed — a false affirmation this package would otherwise still be shipping.
The guard: FormURL does NOT veto when ANY of the following pieces of the URL is token-like (see isTokenLike, the single definition of "token-like" in this package):
- a HOST LABEL: u.Hostname() split on "." — the port is not part of it, and a host that is an IP literal (IPv4, or IPv6 with or without brackets and zone) is skipped as a whole, because an IPv6 address is long and mixes letters and digits without being a secret. A function URL whose first label is the secret (`https://<token>.lambda-url.<region>.on.aws/`) is the shape this closes.
- a PATH SEGMENT: the ESCAPED path split on "/", each segment then decoded as a whole. Splitting before decoding is what keeps an encoded separator from hiding a token: `/hook/9f8e7d6c5b%2F4a39281706` is ONE segment, decoded to `9f8e7d6c5b/4a39281706` (21 bytes), where splitting the decoded path would leave two pieces each shorter than the minimum. A segment that fails to decode is inspected in its escaped form.
- a QUERY KEY or QUERY VALUE, both decoded (url.ParseQuery). Keys are inspected whether or not they carry a value. A bare key (`feed.ics?<token>`) parses as a key with an empty value, so a guard that read only values never saw it. Keys that DO carry a value are inspected too, deliberately: nothing in the URL grammar stops a token from sitting in the key position (`?<token>=1`), url.ParseQuery cannot tell `?k` from `?k=`, and the only cost is a long parameter NAME that mixes letters and digits — noise, never a silenced secret.
- a FRAGMENT KEY or FRAGMENT VALUE, read the same way as the query, since OAuth's implicit flow puts a token there. It starts from the ESCAPED fragment (url.URL.EscapedFragment), exactly as the query starts from RawQuery: split on the literal "&" and "=" first, then each piece decoded once. url.URL.Fragment is already decoded, and parsing it would turn an encoded "&" or "=" into a real separator: `#9f8e7d6c5b%264a39281706` is ONE 21-byte key, where the decoded fragment would split into two short ones. A fragment that is NOT a list of pairs — a hash route `#/invite/<token>`, a bare `#<token>` — reads as one key with no value, and that key is inspected WHOLE. That covers it piece by piece as well: a piece that is token-like makes the whole token-like (it is at least as long and carries the same letter and digit), so no piece of such a fragment escapes inspection.
The credential-named-parameter check (carriesCredential) is a different question and reads the DECODED fragment on purpose: `#access_token%3Dabc` denotes `access_token=abc` once decoded, and keeps firing.
A query or fragment that fails url.ParseQuery is never vetoed, so a parse failure cannot hide a token here either. Both guards answer that way on their own input: carriesCredential on the decoded fragment, the token-like guard on the escaped one. Neither relies on the other having refused first.
Token-like requires ALL of: at least 16 bytes, at least one ASCII letter, AND at least one ASCII digit. Both letter and digit are required, deliberately: a value with only one of the two is a declared, measured limit, not an oversight —
- a long ALL-LETTER segment (`openid-configuration`, from `https://accounts.google.com/.well-known/openid-configuration`) is a descriptive endpoint name, not a secret, and must stay vetoed;
- a long ALL-DIGIT segment (`12345678901234567890`, a numeric id) is an identifier, not a secret, and must stay vetoed;
- a segment carrying both letters and digits but SHORTER than 16 bytes (`v2.0`, `token`, from `https://login.microsoftonline.com/common/oauth2/v2.0/token`) is too short to be distinguished from an ordinary path component, and must stay vetoed.
The same thresholds apply in every position. These stay vetoed, each for the reason given, and are pinned in valueshape_test.go's VETOED table:
- a long all-letter host label (`https://authorizationserver.example.com`) — a descriptive name, no digit;
- a fragment anchor with a digit but under 16 bytes (`#section-2`);
- a bare query flag (`?debug`), short and letters only;
- a version-like path (`/api/v2/resources`), every segment short;
- a port (`:8443`) and an IPv6 literal host (`[2001:db8::8a2e:370:7334]`) — not a label at all.
So the declared limit, after inspecting every position above, is exactly this — a secret-bearing URL is still vetoed as FormURL when its token part:
- is SHORTER than 16 bytes, in whatever position it sits;
- lacks an ASCII letter or lacks an ASCII digit (an all-letter token; an all-digit one);
- is cut by the URL's own literal separators — "." between host labels, a literal "/" between path segments, a literal "&" or "=" in a query or fragment — into pieces that are each shorter than 16 bytes. Only an ENCODED separator inside one piece is undone, in the path, the query and the fragment alike (see above); a literal one is the URL's real structure, and nothing about it distinguishes a token cut in two from two short pieces.
The guard has no shape to act on in any of those cases. This trades a rare short, single-class or pre-cut embedded secret for never mistaking a long identifier or a long descriptive name for one, mirroring the same trade-off FormEnvVarName already makes with its own underscore requirement, above.
FormFilePath and a bare file name ¶
FormFilePath requires no separator: a single `word.ext` with a listed extension (`server.key`, `Hunter2024.db`) IS vetoed. That is a declared limit, not an oversight: a secret that happens to end in a dot plus a known extension has, by shape, the form of a file name, and is not reported. The extension list is closed so a JWT or a base64 blob cannot reach it; a password chosen to look like a file name can.
Index ¶
Constants ¶
const DeclaredLimit = "SEC-001 stays silent when the string literal's own shape proves it is " +
"not a credential (ADR 0086, internal/core/valueshape; forms url, urn, env-var-name, " +
"file-path): a URL with a scheme and a host, no userinfo, no credential-named query or " +
"fragment parameter carrying a value, and nothing token-like (16+ bytes with a letter and " +
"a digit) in any host label (an IP-literal host is skipped whole, never read as labels), " +
"decoded path segment, query key or value, or fragment key or value (each position is " +
"split before it is decoded, so an encoded slash, ampersand or equals sign cannot cut a " +
"token, and a fragment that is not key=value is read whole); a urn: URN; a SCREAMING_SNAKE " +
"name with at least one underscore; a path ending in a known file extension. Such a " +
"literal is not reported at all. " +
"Declared, not fixed, in both directions. NOT REPORTED although it may be a secret: a " +
"value that matches the environment-variable-name pattern (an ASCII upper-case letter " +
"first, then ASCII upper-case letters and digits, at least one underscore, none leading, trailing or " +
"doubled), whatever it holds; a bare file name with a known extension and no " +
"separator (Hunter2024.db); and a URL whose embedded token is shorter than 16 bytes, lacks " +
"either a letter or a digit, or is cut by the URL's own literal separators (dots between " +
"host labels, slashes between path segments, & or = in a query or fragment) into pieces " +
"each shorter than 16 bytes. STILL REPORTED although it is often not a secret, because its " +
"shape is indistinguishable from one: short test literals, short identifiers, prose, paths " +
"without a known extension, header names, and placeholders that do not match that " +
"pattern: changeme, <token>, TODO, __SECRET__."
DeclaredLimit is the served text of what the value veto does and does not see, in both directions, for a provider manifest to cite BY REFERENCE instead of restating it by hand. It names no provider: each manifest says who applies the veto and how its literal reaches NotACredential, then appends this.
Both providers cite it: the TypeScript manifest (ts.hardcoded-secrets in internal/providers/typescript/coverage.go) and the Go capability (limitValueVeto in internal/providers/golang/security.go). Neither keeps a copy of its own, so there is one text to keep true. Every statement here is pinned through the real providers by their valueveto tests, the four placeholders included.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Form ¶
type Form string
Form names the shape a string literal proved it has.
func Forms ¶
func Forms() []Form
Forms returns every Form, in a fixed order (for exhaustiveness checks and parity tables). The order matches the order NotACredential checks guards in, which is itself load-bearing: see the doc comment there.
func NotACredential ¶
NotACredential reports whether value's OWN shape proves it is something other than a credential, and which Form proved it. value is the literal's content WITHOUT quotes.
This is a veto, not a classifier: it fires only when the shape is positive proof of something else, never on mere suspicion. ("", false) means "the value establishes nothing" — the caller (SEC-001, in both providers) keeps affirming exactly as it did before this package existed. When a guard's evidence is ambiguous — a query string or URL fragment that fails to parse — it resolves to NOT vetoing: a blind form that silences a real credential is worse than one more line of noise the developer has to read, which is this project's standing rule (see CLAUDE.md, "TDD" preamble on mutation, and ADR 0075's Arm B post-mortem on the cost of a false affirmation flowing the other way).
Guards run in this fixed order and the first that proves wins:
- FormURL — value has a scheme (`^[A-Za-z][A-Za-z0-9+.-]*://`), url.Parse succeeds with a non-empty Host, carries no userinfo (`user:pass@` is itself a credential), neither its query string nor its URL fragment (parsed the same way, since OAuth's implicit flow puts the token there) has a key matching namematch's credential vocabulary with a NON-EMPTY value, AND no HOST LABEL (IP literals skipped), PATH SEGMENT, QUERY KEY or VALUE, or FRAGMENT KEY or VALUE is token-like (see isTokenLike; every position is split before it is decoded, so an encoded "/", "&" or "=" cannot cut a token): a webhook, presigned, function or feed URL whose secret sits in the host, the path, a bare query key, a hash route or a query value whose key namematch does not recognise must still be seen.
- FormURN — `urn:<namespace-id>:<namespace-specific-string>`, case-insensitive.
- FormEnvVarName — SCREAMING_SNAKE, requiring at least one underscore.
- FormFilePath — every character in a narrow charset, no "://" anywhere in the value, and a trailing extension from a closed list.
WHAT THIS DOES NOT SEE. This is a deliberately partial veto, not a classifier for "everything that is not a credential" — see doc.go for the full census this list is measured against, and CLAUDE.md's census/negative- fixture doctrine for why an undeclared gap here would be worse than a declared one:
- Short test literals and short identifiers (`test_client_secret`, `progressToken`) are, BY SHAPE, indistinguishable from a real short secret such as `s3cr3t` — which ADR 0075 requires to keep firing, since it has no length floor. Nothing in this package infers "test" from a name; that stays the caller's job, if it does it at all.
- Prose (values containing whitespace) does not veto. It did, briefly: the scope this package implements is the version AFTER that guard was dropped 2026-09-28, because "correct horse battery staple" is a real passphrase and this project would rather keep firing on "master secret" (measured noise: 4/320 Go findings, 2/52 TypeScript) than silence one real passphrase.
- A file path with no extension (`lib/config`, `/etc/secrets/db`) does not veto — FormFilePath anchors on a closed extension list precisely so it never has to guess from bare structure alone.
- Header names (`X-Api-Key`) do not veto: mixed case fails FormEnvVarName, and no extension fails FormFilePath.
- Placeholders (`YOUR_CLIENT_SECRET`) DO veto here, as an env-var name — see the census in doc.go for why that is a measured, not a hypothetical, bucket. A placeholder that does not match envVarNamePattern (an ASCII upper-case letter first, at least one underscore, none leading, trailing or doubled) does not veto: `changeme`, `<token>`, `TODO`, and `__SECRET__`, whose underscores are all leading or trailing.
- A secret that matches envVarNamePattern (an ASCII upper-case letter first, then ASCII upper-case letters and digits, at least one underscore, none leading, trailing or doubled) IS vetoed by FormEnvVarName. That is a declared limit, not an oversight: an AWS access key ID (no underscore) and `JBSWY3DPEHPK3PXP` (base32, no underscore) both keep firing precisely because they lack the underscore this guard requires.
- A secret-bearing URL whose token part is SHORTER than tokenLikeMinLength (16 bytes), lacks an ASCII letter or an ASCII digit, or is cut by the URL's own literal separators ("." between host labels, "/" between path segments, "&" or "=" in a query or fragment) into pieces each shorter than 16 bytes, IS still vetoed by FormURL — in any position, the token-like guard has no evidence to act on. This is a declared limit, not an oversight: it trades a rare short, single-class or pre-cut secret for never mistaking a long identifier (a numeric id) or a long descriptive name (`openid-configuration`) for one.
- A bare file name with a listed extension and no separator (`Hunter2024.db`) IS vetoed by FormFilePath: a secret that ends in a dot plus a known extension has the shape of a file name.