mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-03 23:37:53 +01:00
fix: pre-landing review fixes (GST-1064: passphrases passed to a call still report; only file names and short snake_case keys are names)
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
098e2837d1
commit
2ed0622edc
3 files changed
+13
-8
No files matched your search
@@ -1,2 +1,2 @@
|
||||
### Fixed
|
||||
- **The secrets check no longer reads a file name or dict key inside a call as a credential (GST-1064).** `key = json.loads(files.get("key.json", ""))` failed pregate with `PREGATE_SECRETS` (`env.kv`): eight distinct letters in `"key.json"` reach the entropy bar, so the call's argument looked like a secret. So did `token = resp.json().get("access_token")` and a `getenv` default like `"change-me-later"`. A quoted argument made only of lowercase words joined by `_`, `.` or `-` now counts as a name. A real key in quotes, in a `.env` line, or passed to a call (`decrypt("<key>")`) still reports, and the entropy bar is unchanged.
|
||||
- **The secrets check no longer reads a file name or dict key inside a call as a credential (GST-1064).** `key = json.loads(files.get("key.json", ""))` failed pregate with `PREGATE_SECRETS` (`env.kv`): eight distinct letters in `"key.json"` reach the entropy bar, so the call's argument looked like a secret. So did `token = resp.json().get("access_token")`. A quoted argument that is a lowercase file name or a snake_case key of two or three words now counts as a name. A real key in quotes, in a `.env` line, or passed to a call still reports, and so does a passphrase (`decrypt("prod-signing-key")`, a `getenv` default like `"correct-horse-battery-staple"`). The entropy bar is unchanged.
|
||||
@@ -629,13 +629,14 @@ function isBareEnvRead(span: string, match: RegExpExecArray): boolean {
|
||||
|
||||
/**
|
||||
* True when `text` holds a quoted, non-placeholder, high-entropy literal.
|
||||
* GST-1064: lowercase letter words joined by `_`, `.` or `-` name a file, dict
|
||||
* key or default (`"key.json"`, `"access_token"`, `"change-me-later"`); eight
|
||||
* distinct letters already reach 3.0 bits, so entropy alone cannot tell them
|
||||
* from a secret. A literal with a digit, an uppercase letter or one unbroken
|
||||
* run still counts.
|
||||
* GST-1064: a lowercase file name (`"key.json"`) or a snake_case key of two or
|
||||
* three words (`"access_token"`) names what the call reads; eight distinct
|
||||
* letters already reach 3.0 bits, so entropy alone cannot tell them from a
|
||||
* secret. A passphrase still counts: kebab or dotted words
|
||||
* (`"correct-horse-battery-staple"`), four or more snake_case words, a digit,
|
||||
* an uppercase letter or one unbroken run.
|
||||
*/
|
||||
const NAME_SHAPED_LITERAL = /^[a-z]+(?:[_.-][a-z]+)+$/;
|
||||
const NAME_SHAPED_LITERAL = /^(?:[a-z]+(?:_[a-z]+){1,2}|[a-z]+(?:[_-][a-z]+)*\.[a-z]{2,5})$/;
|
||||
function carriesSecretLiteral(text: string): boolean {
|
||||
for (const [, literal] of text.matchAll(/["']([^\s'"]{8,})["']/g))
|
||||
if (!isPlaceholderSpan(literal) && !NAME_SHAPED_LITERAL.test(literal) && shannonEntropy(literal) >= 3.0) return true;
|
||||
|
||||
@@ -116,7 +116,7 @@ describe("env.kv: a name-shaped literal inside a call is a file or dict key, not
|
||||
String.raw`key = json.loads(files.get("key.json", ""))`,
|
||||
String.raw`token = resp.json().get("access_token")`,
|
||||
String.raw` session = store.load('session.cookie')`,
|
||||
String.raw`password = os.getenv("DB_PASSWORD", "change-me-later")`,
|
||||
String.raw`secret = vault.read("client_secret")`,
|
||||
],
|
||||
[
|
||||
String.raw`key = "${FAKE_KEY}"`,
|
||||
@@ -125,6 +125,10 @@ describe("env.kv: a name-shaped literal inside a call is a file or dict key, not
|
||||
String.raw`token = resp.json().get("access_token", "${FAKE_KEY}")`,
|
||||
String.raw`password = os.getenv("DB_PASSWORD", "hunter2.Zx9Qw8")`,
|
||||
String.raw`key = json.loads(files.get("key.json")) or "${FAKE_KEY}"`,
|
||||
String.raw`password = os.getenv("DB_PASSWORD", "correct-horse-battery-staple")`,
|
||||
String.raw`api_key = decrypt("prod-signing-key")`,
|
||||
String.raw`token = decrypt("correct_horse_battery_staple")`,
|
||||
String.raw`key = decrypt("qwhzxkvbnmplor")`,
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user