Skip to content

A modern and easy to use dashboard. 80+ integrations. 20K+ icons built in. Authentication out of the box. No YAML, drag and drop configuration.

fix(nzbget): keep RPC credentials out of Addresses

ajnart8b0a88d129ff
diff --git a/packages/api/src/test/nzbget-privacy.spec.ts b/packages/api/src/test/nzbget-privacy.spec.ts
new file mode 100644
index 000000000..4b8d8712b
--- /dev/null
+++ b/packages/api/src/test/nzbget-privacy.spec.ts
@@ -0,0 +1,122 @@
+import type { MockAgent } from "undici";
+import { MockAgent as UndiciMockAgent } from "undici";
+import { transports } from "winston";
+import { afterEach, beforeEach, expect, test, vi } from "vitest";
+
+import { createIntegrationAsync } from "@homarr/integrations/factory";
+import type * as HttpInfrastructure from "@homarr/core/infrastructure/http";
+
+import { RedisTransport } from "../../../core/src/infrastructure/logs/transports/redis-transport";
+import { settleIntegrationQueries, toPublicIntegrationError } from "../settle-integrations";
+
+const fixture = vi.hoisted(() => {
+ process.env.SKIP_ENV_VALIDATION = "true";
+ process.env.LOG_LEVEL = "debug";
+ const serialized: string[] = [];
+ const pipeline = { lpush: vi.fn(), ltrim: vi.fn(), publish: vi.fn(), exec: vi.fn().mockResolvedValue([]) };
+ pipeline.lpush.mockImplementation((_key: string, value: string) => {
+ serialized.push(value);
+ return pipeline;
+ });
+ pipeline.ltrim.mockImplementation(() => pipeline);
+ pipeline.publish.mockImplementation((_key: string, value: string) => {
+ serialized.push(value);
+ return pipeline;
+ });
+ return {
+ agent: null as MockAgent | null,
+ console: [] as string[],
+ serialized,
+ redis: { options: {}, on: vi.fn(), multi: vi.fn(() => pipeline) },
+ };
+});
+
+vi.mock("@homarr/core/infrastructure/redis", () => ({ createRedisClient: () => fixture.redis }));
+vi.mock("@homarr/core/infrastructure/certificates", () => ({
+ getAllTrustedCertificatesAsync: async () => [],
+ getTrustedCertificateHostnamesAsync: async () => [],
+}));
+vi.mock("@homarr/core/infrastructure/http", async (importActual) => {
+ const actual = await importActual<typeof HttpInfrastructure>();
+ return {
+ ...actual,
+ fetchWithTrustedCertificatesAsync: (
+ url: Parameters<typeof actual.fetchWithTrustedCertificatesAsync>[0],
+ init: Parameters<typeof actual.fetchWithTrustedCertificatesAsync>[1],
+ ) => actual.fetchWithTrustedCertificatesAsync(url, { ...init, dispatcher: fixture.agent ?? undefined }),
+ };
+});
+
+const input = {
+ id: "owned-nzbget",
+ kind: "nzbGet" as const,
+ name: "Owned NZBGet",
+ url: "https://nzbget.example.com",
+ externalUrl: null,
+ decryptedSecrets: [
+ { kind: "username" as const, value: "fixture-private-user" },
+ { kind: "password" as const, value: "fixture-private-password/:?" },
+ ],
+};
+
+beforeEach(() => {
+ fixture.console.length = 0;
+ fixture.serialized.length = 0;
+ fixture.agent = new UndiciMockAgent();
+ fixture.agent.disableNetConnect();
+ const redisTransport = new RedisTransport({ level: "debug" });
+ vi.spyOn(transports.Console.prototype, "log").mockImplementation((info, callback) => {
+ const entry = info as Parameters<RedisTransport["log"]>[0];
+ fixture.console.push(Reflect.get(entry, Symbol.for("message")) as string);
+ redisTransport.log(entry, callback as () => void);
+ });
+});
+
+afterEach(async () => {
+ await fixture.agent?.close();
+ vi.restoreAllMocks();
+});
+
+test.each([401, 403, 500])(
+ "keeps rejected RPC credentials out of original errors, Console and Redis history/live messages (HTTP %i)",
+ async (status) => {
+ fixture.agent?.get(input.url).intercept({ path: /.*/, method: "POST" }).reply(status, "").persist();
+ const client = await createIntegrationAsync(input);
+ let failure: unknown;
+ const results = await settleIntegrationQueries(
+ [input],
+ async () => {
+ return await client.getClientJobsAndStatusAsync({ limit: 10 });
+ },
+ {
+ fallback: (_integration, error) => {
+ failure = error;
+ return toPublicIntegrationError(error);
+ },
+ },
+ );
+ expect(results).toEqual(["INTEGRATION_REQUEST_FAILED"]);
+ expect(failure).toBeInstanceOf(Error);
+ expect((failure as Error).cause).toMatchObject({ statusCode: status, url: "https://nzbget.example.com/jsonrpc" });
+ await vi.waitFor(() => {
+ expect(fixture.console.some((line) => line.includes("Integration query failed"))).toBe(true);
+ expect(fixture.serialized.some((line) => line.includes("Integration query failed"))).toBe(true);
+ });
+ const destinations = [
+ JSON.stringify(failure),
+ JSON.stringify((failure as Error).cause),
+ ...fixture.console,
+ ...fixture.serialized,
+ ];
+ for (const destination of destinations) {
+ for (const credential of input.decryptedSecrets) {
+ expect(destination).not.toContain(credential.value);
+ expect(destination).not.toContain(encodeURIComponent(credential.value));
+ }
+ expect(destination).not.toContain(
+ Buffer.from("fixture-private-user:fixture-private-password/:?").toString("base64"),
+ );
+ expect(destination).not.toContain("Authorization");
+ }
+ },
+);
diff --git a/packages/integrations/src/download-client/nzbget/nzbget-integration.ts b/packages/integrations/src/download-client/nzbget/nzbget-integration.ts
index 889a29754..d0173d001 100644
--- a/packages/integrations/src/download-client/nzbget/nzbget-integration.ts
+++ b/packages/integrations/src/download-client/nzbget/nzbget-integration.ts
@@ -115,9 +115,13 @@ export class NzbGetIntegration extends Integration implements IDownloadClientInt
): Promise<ReturnType<NzbGetClient[CallType]>> {
const username = this.getSecretValue("username");
const password = this.getSecretValue("password");
- const url = this.url(`/${encodeURIComponent(username)}:${encodeURIComponent(password)}/jsonrpc`);
+ const url = this.url("/jsonrpc");
+ const headers = {
+ Authorization: `Basic ${Buffer.from(`${username}:${password}`).toString("base64")}`,
+ "Content-Type": "application/json",
+ };
const body = JSON.stringify({ method, params });
- return await fetchAsync(url, { method: "POST", body })
+ return await fetchAsync(url, { method: "POST", body, headers })
.then(async (response) => {
if (!response.ok) {
throw new ResponseError(response);
diff --git a/packages/integrations/src/download-client/nzbget/test/nzbget-integration.spec.ts b/packages/integrations/src/download-client/nzbget/test/nzbget-integration.spec.ts
index 4f84db932..11fd1a648 100644
--- a/packages/integrations/src/download-client/nzbget/test/nzbget-integration.spec.ts
+++ b/packages/integrations/src/download-client/nzbget/test/nzbget-integration.spec.ts
@@ -11,6 +11,7 @@ vi.hoisted(() => {
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
import type { IntegrationSecret } from "../../../base/types";
+import type { IntegrationTestingInput } from "../../../base/integration";
import { NzbGetIntegration } from "../nzbget-integration";
vi.mock("@homarr/core/infrastructure/http", () => ({
@@ -72,4 +73,32 @@ describe("NzbGetIntegration.getClientJobsAndStatusAsync", () => {
items: [],
});
});
+
+ test("authenticates every RPC through headers with a credential-free Address", async () => {
+ const results = { listgroups: [], history: [], status: { DownloadPaused: false, DownloadRate: 0 } };
+ mockFetch.mockImplementation(async (_url, init) => {
+ const { method } = JSON.parse(String(init?.body)) as { method: keyof typeof results };
+ return Response.json({ result: results[method] });
+ });
+ await createIntegration().getClientJobsAndStatusAsync({ limit: 10 });
+ for (const [url, init] of mockFetch.mock.calls) {
+ expect(url.toString()).toBe("https://nzbget.example.com/jsonrpc");
+ expect(new Headers(init?.headers as HeadersInit).get("Authorization")).toBe(
+ `Basic ${Buffer.from("test-user:test-password").toString("base64")}`,
+ );
+ }
+ });
+
+ test("uses the same header transport for connection testing", async () => {
+ const fetchAsync = vi.fn().mockResolvedValue(Response.json({ result: "26.3" }));
+ const integration = createIntegration();
+ const input = { fetchAsync } as unknown as IntegrationTestingInput;
+ const testing = integration as unknown as {
+ testingAsync: (input: IntegrationTestingInput) => Promise<{ success: boolean }>;
+ };
+ await expect(testing.testingAsync(input)).resolves.toEqual({ success: true });
+ const [url, init] = fetchAsync.mock.calls[0] as [URL, { headers: Record<string, string> }];
+ expect(url.toString()).toBe("https://nzbget.example.com/jsonrpc");
+ expect(init.headers.Authorization).toBe(`Basic ${Buffer.from("test-user:test-password").toString("base64")}`);
+ });
});