Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: env example values

ogsamrat9c126e406f55
diff --git a/apps/server/src/context/PARITY.sha256 b/apps/server/src/context/PARITY.sha256
index 3bc26628..20bb33ce 100644
--- a/apps/server/src/context/PARITY.sha256
+++ b/apps/server/src/context/PARITY.sha256
@@ -12,8 +12,8 @@ d772119f2785b6926cd765a44589c171542d5e79b3677bfa076851775d794480 outside.ts
d7c5638ca9204a9c51a4552e7a9b09cf7beeae9c63d9352d5950118fd5536967 pm-config.ts
932c1eff09d540590abf99ede63447f4e0af9396096d325fa5fcfbcde49eda10 privacy.ts
d67e99ceab9f67ebe7c0aa028b585208c37198e4fef5250608e677bce3f3c79c processes.ts
-741f4327c70500feb644c8e0820060097e282ff1f121dba8ce1979604867bbc0 redact-policy.ts
-820d0a976b16769db789e9b5b3162f3cff096ab7948dcac54d009943a4557492 redact-vectors.json
+d26f1bc752a8cbd4b24dd9066be3b6aefd07ce69d8aef1d7aa616584581bc95b redact-policy.ts
+5a179a0ebfcaadcbda4350775d1358886941f7a7174140fd75064a7fc79d32b1 redact-vectors.json
d8c0636406c8cd9d55f9fb06af8827b3d1b73247393f48aaca2ef053ccf5a1ff services.ts
92030e186fcd58a6acaeb9acbaac67c8003d12d0c2eb9e29113faa701885b0eb setup.ts
d51d434283f757f0ed45bb6996a74fb5bf9e1d56f34146e99df3c392cde5ea19 shell-aliases.ts
diff --git a/apps/server/src/context/redact-policy.ts b/apps/server/src/context/redact-policy.ts
index d9901487..ba9b16eb 100644
--- a/apps/server/src/context/redact-policy.ts
+++ b/apps/server/src/context/redact-policy.ts
@@ -143,14 +143,15 @@ export function looksRandomName(value: string): boolean {
/**
* Credential files: any non-placeholder value of a secret-named key there is
- * a credential. `.env*` except examples and templates, `*.env`, `.npmrc`, `.pypirc`,
+ * a credential. `.env*` (templates too: a `.env.example` a user filled in holds
+ * the real values; placeholders still stay), `*.env`, `.npmrc`, `.pypirc`,
* `.netrc`, `.pgpass`, `.git-credentials`, `credentials` (`.aws/credentials`),
* kubeconfig.
*/
export function isCredentialFile(path: string | undefined): boolean {
if (!path) return false;
const name = path.split(/[\\/]/).pop()!.toLowerCase();
- if (name.startsWith(".env")) return !/(?:example|sample|template|dist|defaults?)$/.test(name);
+ if (name.startsWith(".env")) return true;
// A named env file (`prod.env`, `docker/production.env`) is a `.env` by another name.
if (/^.+\.env$/.test(name)) return true;
return [".npmrc", ".pypirc", ".netrc", "_netrc", ".pgpass", ".git-credentials", "credentials", "kubeconfig", "config.kube"].includes(name)
diff --git a/apps/server/src/context/redact-vectors.json b/apps/server/src/context/redact-vectors.json
index 00d4c0c8..808dca53 100644
--- a/apps/server/src/context/redact-vectors.json
+++ b/apps/server/src/context/redact-vectors.json
@@ -224,11 +224,23 @@
"context": "app/.env"
},
{
- "name": "env example kept",
+ "name": "env example filled in",
"input": "DB_PASSWORD=supersecretword",
- "expect": "DB_PASSWORD=supersecretword",
+ "expect": "DB_PASSWORD=[REDACTED]",
"context": "app/.env.example"
},
+ {
+ "name": "env example placeholders kept",
+ "input": "PORT=3000\nDB_PASSWORD=<your-password>\nAPI_KEY=your-api-key-here\nSECRET_KEY=changeme\nJWT_SECRET=",
+ "expect": "PORT=3000\nDB_PASSWORD=<your-password>\nAPI_KEY=your-api-key-here\nSECRET_KEY=changeme\nJWT_SECRET=",
+ "context": "app/.env.sample"
+ },
+ {
+ "name": "env template real values",
+ "input": "API_TOKEN=abcdefgh123\nDATABASE_PASSWORD=Summer2024!\nJWT_SECRET=supersecretjwt",
+ "expect": "API_TOKEN=[REDACTED]\nDATABASE_PASSWORD=[REDACTED]\nJWT_SECRET=[REDACTED]",
+ "context": "/w/api/.env.template"
+ },
{
"name": "named env file any value",
"input": "DB_PASSWORD=supersecretword",
diff --git a/apps/server/src/redact-policy.test.ts b/apps/server/src/redact-policy.test.ts
index 4fdbf388..a31b1080 100644
--- a/apps/server/src/redact-policy.test.ts
+++ b/apps/server/src/redact-policy.test.ts
@@ -88,3 +88,31 @@ test("the archive policy carries the server's switch", () => {
assert.equal(parseArchivePolicy({ policy: {} }).redactionV3, undefined);
assert.equal(parseArchivePolicy({}).redactionV3, undefined);
});
+
+test("a filled-in .env template in a file tool's output or input is scrubbed as its .env, under both rule sets", () => {
+ const filled = "PORT=3000\nAPI_TOKEN=abcdefgh123\nDATABASE_PASSWORD=Summer2024!\nJWT_SECRET=supersecretjwt\nAPI_KEY=<your-api-key>\n";
+ const numbered = filled.split("\n").filter(Boolean).map((line, i) => `${String(i + 1).padStart(5, "0")}| ${line}\n`).join("");
+ const document = {
+ events: [{
+ type: "turn.messages",
+ data: {
+ messages: [{
+ role: "assistant",
+ parts: [
+ { type: "tool", tool: "read", state: { status: "completed", input: { filePath: "/w/app/.env.example" }, output: `<file>\n${numbered}</file>` } },
+ { type: "tool", tool: "write", state: { status: "completed", input: { filePath: "/w/api/.env.sample", content: filled }, output: "Wrote file successfully." } },
+ ],
+ }],
+ },
+ }],
+ };
+ for (const name of ["client-v3", "legacy"]) {
+ const out = withPolicy(name, () => plain(uploader.redactUploadJson(document, { fileAware: true }).value));
+ const [read, write] = out.events[0].data.messages[0].parts;
+ for (const secret of ["abcdefgh123", "Summer2024!", "supersecretjwt"]) {
+ assert.ok(!JSON.stringify(out).includes(secret), `${name} ${secret}`);
+ }
+ assert.match(read.state.output, /00001\| PORT=3000\n00002\| API_TOKEN=\[REDACTED[^\n]*\n00003\| DATABASE_PASSWORD=\[REDACTED[^\n]*\n00004\| JWT_SECRET=\[REDACTED[^\n]*\n00005\| API_KEY=<your-api-key>\n/, name);
+ assert.match(write.state.input.content, /^PORT=3000\nAPI_TOKEN=\[REDACTED[^\n]*\n[\s\S]*API_KEY=<your-api-key>\n$/, name);
+ }
+});
diff --git a/apps/server/src/session-uploader.ts b/apps/server/src/session-uploader.ts
index bd61aa00..477565b9 100644
--- a/apps/server/src/session-uploader.ts
+++ b/apps/server/src/session-uploader.ts
@@ -1337,11 +1337,11 @@ function isNamedEnvFile(lowerName: string): boolean {
}
/**
- * The scrub context of a file kept in the snapshot or the git block. A `.env`
- * template is scrubbed as its `.env`: redact-policy's isCredentialFile exempts
- * templates, so without this a secret-named value that does not look
- * generated (`DB_PASSWORD=Summer2024!`) would leave in a template that a
- * user filled with real values.
+ * The scrub context of a file's text (a snapshot file, its git block section,
+ * a file tool's input or output in the main log). A `.env` template is scrubbed
+ * as its `.env`, so a secret-named value that does not look generated
+ * (`DB_PASSWORD=Summer2024!`) never stays in a template a user filled with
+ * real values (redact-policy's isCredentialFile agrees for templates too).
*/
function snapshotScrubContext(path: string): string {
return isEnvTemplate(pathComponents(path)) ? path.replace(/\.[^./\\]+$/, "") : path;
@@ -2067,9 +2067,9 @@ function diffSegmentPath(segment: string, fallback: string | null): string | nul
return fallback;
}
-/** Scrubs `text` as a file's text: the mode the path selects, CONFIG with no path. */
+/** Scrubs `text` as a file's text: the mode the path selects, CONFIG with no path, under the file's scrub context (snapshotScrubContext). */
function redactFileText(text: string, path: string | null, tally: { count: number }): string {
- const result = path === null ? redactUploadText(text) : redactUploadText(text, { context: path, mode: redactModeForPath(path) });
+ const result = path === null ? redactUploadText(text) : redactUploadText(text, { context: snapshotScrubContext(path), mode: redactModeForPath(path) });
tally.count += result.count;
return result.text;
}