Skip to content

Commit 081b0e6

Browse files
committed
fix(cli): redact environment values from build debug logs
1 parent a81ad49 commit 081b0e6

4 files changed

Lines changed: 64 additions & 4 deletions

File tree

.changeset/silent-build-logs.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"trigger.dev": patch
3+
---
4+
5+
Prevent build debug logs from including environment variable values.

packages/cli-v3/src/build/buildWorker.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ import { join, relative, sep } from "node:path";
1515
import { generateContainerfile } from "../deploy/buildImage.js";
1616
import { writeFile } from "node:fs/promises";
1717
import { buildManifestToJSON } from "../utilities/buildManifest.js";
18+
import { logger } from "../utilities/logger.js";
1819
import { readPackageJSON } from "pkg-types";
1920
import { writeJSONFile } from "../utilities/fileSystem.js";
2021
import { isWindows } from "std-env";
2122
import { pathToFileURL } from "node:url";
22-
import { logger } from "../utilities/logger.js";
23+
import { logBuildWorkerStart } from "./buildWorkerLogging.js";
2324
import { SdkVersionExtractor } from "./plugins.js";
2425
import { spinner } from "../utilities/windows.js";
2526

@@ -42,9 +43,7 @@ export type BuildWorkerOptions = {
4243
};
4344

4445
export async function buildWorker(options: BuildWorkerOptions) {
45-
logger.debug("Starting buildWorker", {
46-
options,
47-
});
46+
logBuildWorkerStart(options);
4847

4948
const resolvedConfig = options.resolvedConfig;
5049

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { describe, expect, it, vi } from "vitest";
2+
import { logBuildWorkerStart } from "./buildWorkerLogging.js";
3+
import { logger } from "../utilities/logger.js";
4+
5+
const secret = "build-worker-secret-value";
6+
7+
describe("logBuildWorkerStart", () => {
8+
it.each(["deploy", "unmanaged"] as const)(
9+
"does not log environment values for %s builds",
10+
(target) => {
11+
const debug = vi.spyOn(logger, "debug").mockImplementation(() => {});
12+
13+
logBuildWorkerStart({
14+
target,
15+
branch: "main",
16+
envVars: { BUILD_SECRET: secret },
17+
rewritePaths: true,
18+
forcedExternals: ["example-package"],
19+
});
20+
21+
expect(debug).toHaveBeenCalledOnce();
22+
expect(JSON.stringify(debug.mock.calls)).not.toContain(secret);
23+
expect(debug).toHaveBeenCalledWith("Starting buildWorker", {
24+
target,
25+
hasBranch: true,
26+
envVarCount: 1,
27+
rewritePaths: true,
28+
forcedExternalsCount: 1,
29+
plain: false,
30+
});
31+
32+
debug.mockRestore();
33+
}
34+
);
35+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { logger } from "../utilities/logger.js";
2+
3+
type BuildWorkerLogOptions = {
4+
target: string;
5+
branch?: string;
6+
envVars?: Record<string, string>;
7+
rewritePaths?: boolean;
8+
forcedExternals?: string[];
9+
plain?: boolean;
10+
};
11+
12+
export function logBuildWorkerStart(options: BuildWorkerLogOptions) {
13+
logger.debug("Starting buildWorker", {
14+
target: options.target,
15+
hasBranch: options.branch !== undefined,
16+
envVarCount: Object.keys(options.envVars ?? {}).length,
17+
rewritePaths: options.rewritePaths ?? false,
18+
forcedExternalsCount: options.forcedExternals?.length ?? 0,
19+
plain: options.plain ?? false,
20+
});
21+
}

0 commit comments

Comments
 (0)