A desktop coding agent with free access to frontier models.
TypeScript
fix: stricter literal check
ogsamrat2be134d8f30f
diff --git a/apps/server/src/context/PARITY.sha256 b/apps/server/src/context/PARITY.sha256index 1bfbdfd4..89541ddd 100644--- a/apps/server/src/context/PARITY.sha256+++ b/apps/server/src/context/PARITY.sha256@@ -9,8 +9,8 @@ d772119f2785b6926cd765a44589c171542d5e79b3677bfa076851775d794480 outside.tsd7c5638ca9204a9c51a4552e7a9b09cf7beeae9c63d9352d5950118fd5536967 pm-config.tsd13231905671ad40fdd73e3fe7af81e44dcc909ace606f45a79c215984b6b35d privacy.ts0e04845a2d0ad2136c01a61d3ed1193b62ef99f5b82e1f555b7c97bb6dc18773 processes.ts-dfe4efad20d114462bc0f9e3f3178eb7e44c4241d119b7deb1524183bf08b481 redact-policy.ts-16f6bbf34934e279bd1ff3f6db5841bcd3e9f5a9ec05363dc39f5e7108a16e6a redact-vectors.json+0c831e9c763e9fd5504fa76ad3863f15693b5c6b5da0b25e1669c2593702737b redact-policy.ts+87f77398205e7427136ab9e3199352e3b878532671ffd19d8fbe2e889b03e2e8 redact-vectors.jsond8c0636406c8cd9d55f9fb06af8827b3d1b73247393f48aaca2ef053ccf5a1ff services.ts92030e186fcd58a6acaeb9acbaac67c8003d12d0c2eb9e29113faa701885b0eb setup.tsd51d434283f757f0ed45bb6996a74fb5bf9e1d56f34146e99df3c392cde5ea19 shell-aliases.tsdiff --git a/apps/server/src/context/redact-policy.ts b/apps/server/src/context/redact-policy.tsindex 9cacd2d9..017a5fec 100644--- a/apps/server/src/context/redact-policy.ts+++ b/apps/server/src/context/redact-policy.ts@@ -89,13 +89,29 @@ export function shannonEntropy(value: string): number {return entropy;}-function charClasses(value: string): number {- return [/[a-z]/, /[A-Z]/, /[0-9]/, /[^A-Za-z0-9]/].filter((pattern) => pattern.test(value)).length;-}+// Code and template characters: a value holding one is an expression+// (`response.data?.[KEY]`, `{apiKey}`, `settings.KEY)`), never a literal.+const CODE_CHARS = /[\s[\]{}()<>`\\]|\?[.[]|\$[{(]/;+const CONSTANT_NAME = /^[A-Z]+(?:_[A-Z0-9]+)*$/;+const DOTTED_NAME = /^[A-Za-z_][\w$]*(?:\.[A-Za-z_][\w$]*)+$/;-/** 12+ characters, two or more character classes and 3.0+ bits per character. */+/**+ * A generated-looking literal: 12+ characters with no code or template+ * characters, letters and digits both (or 20+ characters with both cases+ * about equally), 3.0+ bits per character, and not a constant's name+ * (`OPENAI_API_KEY`) or a dotted name (`settings.token`). Words joined by+ * dashes (`dev-password`) are not generated.+ */export function looksRandom(value: string): boolean {- return value.length >= 12 && charClasses(value) >= 2 && shannonEntropy(value) >= 3.0;+ if (value.length < 12 || CODE_CHARS.test(value) || CONSTANT_NAME.test(value) || DOTTED_NAME.test(value)) return false;+ const digits = /[0-9]/.test(value);+ const upper = value.replace(/[^A-Z]/g, "").length;+ const lower = value.replace(/[^a-z]/g, "").length;+ // Without digits, only a long run whose case is balanced like random+ // text (a camelCase name is mostly lower case).+ const balanced = value.length >= 20 && upper >= 0.3 * (upper + lower) && lower >= 0.3 * (upper + lower);+ if (!((upper + lower > 0 && digits) || balanced)) return false;+ return shannonEntropy(value) >= 3.0;}/**@@ -354,6 +370,21 @@ function redactAssignments(const ASSIGNMENT_GATE = /secret|passw|pwd|token|credential|auth|key/i;+// A label on its own line and the value alone on the next one (notes,+// READMEs, `.txt` files): `API_KEY:` then `abc123...`. The whole next line+// must be one token; it is judged like any other value.+const NEXT_LINE_VALUE = /(^|\n)([^\S\n]*[-*#>]*[^\S\n]*[*_`"']*)([A-Za-z_][\w.-]{0,63})([*_`"']*[^\S\n]*[:=][^\S\n]*[*_`"']*\r?\n[^\S\n]*)([`"']?)([^\s`"']{12,})\5(?=[^\S\n]*(?:\r?\n|$))/g;++function redactNextLineValues(text: string, hidden: string, tally: Tally, credentialFile: boolean, spans: Array<[number, number]>): string {+ NEXT_LINE_VALUE.lastIndex = 0;+ return text.replace(NEXT_LINE_VALUE, (match: string, start: string, lead: string, key: string, sep: string, quote: string, value: string, offset: number) => {+ if (insideOpaque(spans, offset, offset + match.length) || !isSecretKey(key)) return match;+ if (!isSecretValue(value, { mode: "config", quoted: true, credentialFile })) return match;+ note(tally, "secret_assignment");+ return `${start}${lead}${key}${sep}${quote}${hidden}${quote}`;+ });+}+const AWS_ID = /(?:AKIA|ASIA)[0-9A-Z]{16}/;const AWS_CONTEXT = /(?:AKIA|ASIA)[0-9A-Z]{16}|aws[_ .-]?secret[_ .-]?access[_ .-]?key/i;const AWS_SECRET = token(String.raw`[A-Za-z0-9/+]{40}(?![A-Za-z0-9/+])`);@@ -433,7 +464,10 @@ export function redactCredentials(input: string, options: CredentialOptions = {}const credentialFile = isCredentialFile(options.context);let text = input.includes("-----BEGIN ") ? redactPrivateKeys(input, hidden, tally) : input;if (text.includes("://")) text = redactUrlPasswords(text, hidden, tally, opaqueSpans(text));- if (ASSIGNMENT_GATE.test(text)) text = redactAssignments(text, hidden, tally, options.mode ?? "config", credentialFile, opaqueSpans(text));+ if (ASSIGNMENT_GATE.test(text)) {+ text = redactAssignments(text, hidden, tally, options.mode ?? "config", credentialFile, opaqueSpans(text));+ if (text.includes("\n") && options.mode !== "source") text = redactNextLineValues(text, hidden, tally, credentialFile, opaqueSpans(text));+ }const nearAws = options.awsContext === true || (options.context !== undefined && AWS_CONTEXT.test(options.context));text = redactAwsSecrets(text, hidden, tally, nearAws, opaqueSpans(text));text = redactTokens(text, hidden, tally, opaqueSpans(text));diff --git a/apps/server/src/context/redact-vectors.json b/apps/server/src/context/redact-vectors.jsonindex dcb076d2..911f59e9 100644--- a/apps/server/src/context/redact-vectors.json+++ b/apps/server/src/context/redact-vectors.json@@ -267,6 +267,73 @@"name": "token after escaped newline","input": "line\\ngh⟨+⟩p_b4z0PMbDeCxAqT4kiRhFv5FnMXlMWbiohfGV","expect": "line\\n[REDACTED]"+ },+ {+ "name": "code expression kept",+ "input": "const token = response.data?.[TOKEN_FIELD]",+ "expect": "const token = response.data?.[TOKEN_FIELD]"+ },+ {+ "name": "quoted dotted name kept",+ "input": "const x = { token: \"settings.token\" }",+ "expect": "const x = { token: \"settings.token\" }"+ },+ {+ "name": "constant name kept",+ "input": "client(api_key_env=\"OPENAI_API_KEY\")",+ "expect": "client(api_key_env=\"OPENAI_API_KEY\")"+ },+ {+ "name": "jsx expression kept",+ "input": "<Client apiKey={apiKey} secret={props.clientSecret} />",+ "expect": "<Client apiKey={apiKey} secret={props.clientSecret} />"+ },+ {+ "name": "call argument kept",+ "input": "OpenAI(api_key=settings.OPENAI_API_KEY)",+ "expect": "OpenAI(api_key=settings.OPENAI_API_KEY)"+ },+ {+ "name": "dashed words kept",+ "input": "login({ username: 'admin-user', password: 'demo-password-reset' })",+ "expect": "login({ username: 'admin-user', password: 'demo-password-reset' })"+ },+ {+ "name": "template braces kept",+ "input": "headers += f\"Authorization: {auth_header_value}\"",+ "expect": "headers += f\"Authorization: {auth_header_value}\""+ },+ {+ "name": "strong password kept out",+ "input": "DB_PASSWORD = 'Tr0ub4dor&3-horse!'",+ "expect": "DB_PASSWORD = '[REDACTED]'"+ },+ {+ "name": "long mixed-case literal",+ "input": "client_secret: \"tMSXumEUddzLinslpqaTvtBKRiKG\"",+ "expect": "client_secret: \"[REDACTED]\""+ },+ {+ "name": "value on the line after its label",+ "input": "Keys for the demo\nAPI_KEY:\nT7NT4WVI4P0F9L7B9222LGV4TMQ\nUse it once.",+ "expect": "Keys for the demo\nAPI_KEY:\n[REDACTED]\nUse it once.",+ "context": "notes.txt"+ },+ {+ "name": "markdown label then value",+ "input": "**OpenAI API key:**\n`qFJOBNCEPquXOrK4zDVhNomPXW9rmphDvduwHcBE`\n",+ "expect": null,+ "same": true+ },+ {+ "name": "label then prose kept",+ "input": "password:\nask the admin for it\n",+ "expect": "password:\nask the admin for it\n"+ },+ {+ "name": "yaml mapping under a label kept",+ "input": "token:\n value: abcdefgh12345678\n",+ "expect": "token:\n value: abcdefgh12345678\n"}]}\ No newline at end of file