From 5b75a82613c3e35c6310b77f8c501f5734fe0ea4 Mon Sep 17 00:00:00 2001 From: Rex Raphael Date: Tue, 10 Nov 2026 08:14:14 -0600 Subject: [PATCH 1/2] fix(perception): stop flagging typeids as high-entropy secrets A TypeID with a prefix of five or more letters is 32 characters or longer, so high_entropy checked it like any other token and often flagged it. Loomplane's release review stopped about 1 run in 20 because a tool result held atask_01m71vem2ge808nc95ad4hj3bq. The suffix is a UUID in base32, and UUIDs are already skipped, so TypeIDs now are too. Tokens close to the format (upper case, a first suffix character past 7, a letter outside Crockford base32, a prefix starting with '_') are still checked. --- awareness/perception/entropy.go | 30 +++++++++++++++++++++++-- awareness/perception/perception_test.go | 26 +++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/awareness/perception/entropy.go b/awareness/perception/entropy.go index 9d062c3..72291c1 100644 --- a/awareness/perception/entropy.go +++ b/awareness/perception/entropy.go @@ -55,7 +55,7 @@ var sriPrefixes = []string{"sha1-", "sha256-", "sha384-", "sha512-"} // highEntropy records standalone tokens of 32 or more characters from // [A-Za-z0-9+/_\-=.] that mix at least three of lower case, upper case, // digits and symbols and carry at least 4.5 bits of entropy per character. -// Hashes after a digest prefix, SRI hashes, pure hex, UUIDs, numbers, tokens +// Hashes after a digest prefix, SRI hashes, pure hex, UUIDs, TypeIDs, numbers, tokens // made of words (identifiers, import paths), Kubernetes-style names and SSH // public keys are never flagged. A URL or path is checked one segment at a // time. A base64 token is judged by what it decodes to (see encodedSecret). @@ -106,7 +106,7 @@ func entropyToken(c *collector, start, end int) { return } } - if len(tok) < 32 || afterDigestPrefix(s, start) || afterSSHKeyType(s, start) || isHex(tok) || isNumber(tok) || isUUID(tok) { + if len(tok) < 32 || afterDigestPrefix(s, start) || afterSSHKeyType(s, start) || isHex(tok) || isNumber(tok) || isUUID(tok) || isTypeID(tok) { return } if isPathLike(tok) { @@ -304,6 +304,32 @@ func isUUID(v string) bool { return true } +// isTypeID reports whether v is a TypeID such as user_01h455vb4pex5vsknk084sn02q: +// a prefix of up to 63 lower-case letters and '_' that starts and ends with a +// letter, '_', then a UUID in 26 characters of lower-case Crockford base32, +// the first of them 0 to 7. +func isTypeID(v string) bool { + k := strings.LastIndexByte(v, '_') + if k < 1 || k > 63 || len(v)-k-1 != 26 { + return false + } + prefix, suffix := v[:k], v[k+1:] + if suffix[0] > '7' || prefix[0] == '_' || prefix[k-1] == '_' { + return false + } + for i := range len(prefix) { + if b := prefix[i]; b != '_' && (b < 'a' || b > 'z') { + return false + } + } + for i := range len(suffix) { + if strings.IndexByte("0123456789abcdefghjkmnpqrstvwxyz", suffix[i]) < 0 { + return false + } + } + return true +} + // charClasses counts which of lower case, upper case, digits and symbols v // holds. func charClasses(v string) int { diff --git a/awareness/perception/perception_test.go b/awareness/perception/perception_test.go index 799575e..bffef3b 100644 --- a/awareness/perception/perception_test.go +++ b/awareness/perception/perception_test.go @@ -21,6 +21,7 @@ const ( digits = "0123456789" stdB64 = alnum + "+/" urlB64 = alnum + "-_" + crockford = "0123456789abcdefghjkmnpqrstvwxyz" ) // fake returns n characters drawn from alphabet by a fixed generator, so the @@ -346,6 +347,31 @@ func TestBenignInfraTokensAreNotSecrets(t *testing.T) { } } +func TestTypeIDsAreNotSecrets(t *testing.T) { + // A TypeID's suffix is a UUID in base32, but with a prefix of five or + // more letters the whole ID is long enough to be checked. + for _, text := range []string{ + "task atask_01m71vem2ge808nc95ad4hj3bq finished", + "release atask_0" + fake(167, 25, crockford), + `{"id":"provider_key_3` + fake(53, 25, crockford) + `"}`, + } { + if got := perception.Secrets(text, nil); len(got) != 0 { + t.Errorf("Secrets(%q) = %+v, want none", text, got) + } + } + // Close to a TypeID but not one, so still checked. + for _, text := range []string{ + "atask_8" + fake(88, 25, crockford), // first suffix character past 7 + "aTask_0" + fake(53, 25, crockford), // upper case in the prefix + "atask_0" + fake(53, 24, crockford) + "u", // u is not in the alphabet + "_atask_0" + fake(167, 25, crockford), // prefix starts with '_' + } { + if got := perception.Secrets(text, nil); len(got) != 1 { + t.Errorf("Secrets(%q) = %+v, want one match", text, got) + } + } +} + func TestEncodedSecretIsStillFlagged(t *testing.T) { encoded := base64.StdEncoding.EncodeToString([]byte("GITHUB_TOKEN=ghp_" + fake(3, 36, alnum))) got := perception.Secrets("data: "+encoded, nil) From 49ea7786a2e5ce14f6fde15a0ed8ecc118804772 Mon Sep 17 00:00:00 2001 From: Rex Raphael Date: Tue, 10 Nov 2026 08:58:13 -0600 Subject: [PATCH 2/2] fix(deps): move to klauspost/compress v1.20.2 GO-2026-6865 (a panic on two-block frames) reaches shield through the mongo store's Migrate, so govulncheck fails the Security job. v1.20.2 fixes it. --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 977b1b4..b9cb49f 100644 --- a/go.mod +++ b/go.mod @@ -77,7 +77,7 @@ require ( github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect github.com/jackc/puddle/v2 v2.2.2 // indirect github.com/json-iterator/go v1.1.12 // indirect - github.com/klauspost/compress v1.19.1 // indirect + github.com/klauspost/compress v1.20.2 // indirect github.com/leodido/go-urn v1.5.0 // indirect github.com/mattn/go-colorable v0.1.15 // indirect github.com/mattn/go-isatty v0.0.24 // indirect diff --git a/go.sum b/go.sum index 69cf921..f360a3f 100644 --- a/go.sum +++ b/go.sum @@ -211,8 +211,8 @@ github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/u github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= -github.com/klauspost/compress v1.19.1 h1:VsB4HPswih7mmZ8WleSFQ75c/Ui1M4trX5oAsJnhSlk= -github.com/klauspost/compress v1.19.1/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ= +github.com/klauspost/compress v1.20.2 h1:v5tiZvm1KGLyg5d5oXdXe3lsSPrbEUiKoXGia//I7Qo= +github.com/klauspost/compress v1.20.2/go.mod h1:LUdAzn7YLVvxLpc7y3V1m40wESHTgc1422pwwBSKYuI= github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE= github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=