Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(media-server): redact urls from nvenc fallback reasons and keep encoder attempt details behind the secret

Richie McIlroy8c7a524a3448
diff --git a/apps/media-server/src/__tests__/lib/nvenc-encoder.test.ts b/apps/media-server/src/__tests__/lib/nvenc-encoder.test.ts
index b1fdbb827..2efaf38a6 100644
--- a/apps/media-server/src/__tests__/lib/nvenc-encoder.test.ts
+++ b/apps/media-server/src/__tests__/lib/nvenc-encoder.test.ts
@@ -137,6 +137,10 @@ describe("nvenc encoder selection", () => {
active: "libx264",
nvenc: null,
});
+ expect(getVideoEncoderStatus(enabled, false)).toEqual({
+ active: "nvenc",
+ nvenc: null,
+ });
});
test("uses p1, cq = crf + 8, no lookahead and spatial AQ by default", () => {
@@ -261,6 +265,14 @@ describe("nvenc fallback", () => {
),
).toBe("FFmpeg exited with code 1. Last stderr: No device");
expect(nvencFallbackReason("boom", false)).toBe("boom");
+ expect(
+ nvencFallbackReason(
+ new Error(
+ "https://bucket.s3.amazonaws.com/u/v/raw.mp4?X-Amz-Signature=abc: Server returned 403",
+ ),
+ false,
+ ),
+ ).toBe("<url> Server returned 403");
expect(nvencFallbackReason(new Error(""), false)).toBe("unknown error");
expect(
nvencFallbackReason(new Error("x".repeat(2000)), false),
diff --git a/apps/media-server/src/lib/nvenc-encoder.ts b/apps/media-server/src/lib/nvenc-encoder.ts
index a6d016599..8cd07b76b 100644
--- a/apps/media-server/src/lib/nvenc-encoder.ts
+++ b/apps/media-server/src/lib/nvenc-encoder.ts
@@ -181,7 +181,9 @@ export function nvencFallbackReason(
aborted: boolean,
): string | null {
if (aborted) return null;
- const message = error instanceof Error ? error.message : String(error);
+ const message = (
+ error instanceof Error ? error.message : String(error)
+ ).replace(/[a-z][a-z0-9+.-]*:\/\/\S+/gi, "<url>");
return message.slice(-MAX_FALLBACK_REASON_LENGTH) || "unknown error";
}
@@ -214,12 +216,15 @@ export function logNvencFallback(details: {
);
}
-export function getVideoEncoderStatus(env: Env = process.env) {
+export function getVideoEncoderStatus(
+ env: Env = process.env,
+ includeDetails = true,
+) {
const active = selectedVideoEncoder(env);
return {
active,
nvenc:
- active === "nvenc"
+ active === "nvenc" && includeDetails
? {
attempts: nvencStatus.attempts,
fallbacks: nvencStatus.fallbacks,
diff --git a/apps/media-server/src/routes/health.ts b/apps/media-server/src/routes/health.ts
index eed6478b5..c3fef26c6 100644
--- a/apps/media-server/src/routes/health.ts
+++ b/apps/media-server/src/routes/health.ts
@@ -21,6 +21,7 @@ health.get("/", async (c) => {
);
const resources = getSystemResources();
const draining = isDraining();
+ const authenticated = hasMediaServerSecret(c);
return c.json(
{
@@ -34,7 +35,7 @@ health.get("/", async (c) => {
available: mediaEngine.available,
version: mediaEngine.version,
},
- videoEncoder: getVideoEncoderStatus(),
+ videoEncoder: getVideoEncoderStatus(process.env, authenticated),
system: {
...resources,
loadAvg5m,
@@ -45,7 +46,7 @@ health.get("/", async (c) => {
uptimeSeconds: Math.round(os.uptime()),
processUptimeSeconds: Math.round(process.uptime()),
},
- ...(hasMediaServerSecret(c) && { runtime: await getRuntimeReport() }),
+ ...(authenticated && { runtime: await getRuntimeReport() }),
},
draining ? 503 : 200,
);