Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/UrlParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { Config } from "./config/Config";
import { type EncryptionSystem } from "./e2ee/sharedKeyManagement";
import { E2eeType } from "./e2ee/e2eeType";
import { platform } from "./Platform";
import { redact } from "./utils/redact";

interface RoomIdentifier {
roomAlias: string | null;
Expand Down Expand Up @@ -494,7 +495,7 @@ export const computeUrlParams = (search = "", hash = ""): UrlParams => {
"intent:",
intent,
"\nproperties:",
properties,
redact(properties, "password"),
"configuration:",
configuration,
);
Expand Down
58 changes: 58 additions & 0 deletions src/utils/redact.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
Copyright 2026 New Vector Ltd.

SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
*/

import { expect, test } from "vitest";

import { redact } from "./redact";

test("empty object", () => {
expect(redact({})).toEqual({});
});

test("no keys", () => {
expect(redact({ foo: "bar" })).toEqual({ foo: "bar" });
});

test("redact one key", () => {
expect(redact({ foo: "bar" }, "foo")).toEqual({ foo: "<redacted>" });
});

test("redact two keys", () => {
expect(redact({ foo: "bar", bar: "foo" }, "foo", "bar")).toEqual({
foo: "<redacted>",
bar: "<redacted>",
});
});

test("no redaction of unrelated keys", () => {
expect(redact({ foo: "bar", bar: "foo" }, "foo")).toEqual({
foo: "<redacted>",
bar: "foo",
});
});

test("no redaction of missing keys", () => {
expect(
redact({ foo: "bar" } as { foo: string; bar: string | undefined }, "bar"),
).toEqual({
foo: "bar",
});
});

test("no redaction of null values", () => {
expect(redact({ foo: "bar", bar: null }, "bar")).toEqual({
foo: "bar",
bar: null,
});
});

test("no redaction of undefined values", () => {
expect(redact({ foo: "bar", bar: undefined }, "bar")).toEqual({
foo: "bar",
bar: undefined,
});
});
25 changes: 25 additions & 0 deletions src/utils/redact.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
Copyright 2026 New Vector Ltd.

SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
*/

/**
* Redacts properties in the supplied object by replacing them with
* a constant value.
* @param obj Object in which to perform redaction
* @param keys Keys to be redacted in the object
* @returns A new object with the specified properties redacted
*/
export function redact<T extends object>(
obj: T,
...keys: (keyof T)[]
): Record<keyof T, unknown> {
const result: Record<keyof T, unknown> = { ...obj };
for (const key of keys)
if (key in result && result[key] != null) {
result[key] = "<redacted>";
}
return result;
}
Loading