mirror of
https://github.com/vector-im/element-call.git
synced 2026-06-30 18:02:56 +00:00
Restrain logging of URL properties
This commit is contained in:
@@ -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;
|
||||
@@ -494,7 +495,7 @@ export const computeUrlParams = (search = "", hash = ""): UrlParams => {
|
||||
"intent:",
|
||||
intent,
|
||||
"\nproperties:",
|
||||
properties,
|
||||
redact(properties, "password"),
|
||||
"configuration:",
|
||||
configuration,
|
||||
);
|
||||
|
||||
36
src/utils/redact.test.ts
Normal file
36
src/utils/redact.test.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
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({})).to.deep.equal({});
|
||||
});
|
||||
|
||||
test("no keys", () => {
|
||||
expect(redact({ foo: "bar" })).to.deep.equal({ foo: "bar" });
|
||||
});
|
||||
|
||||
test("redact one key", () => {
|
||||
expect(redact({ foo: "bar" }, "foo")).to.deep.equal({ foo: "<redacted>" });
|
||||
});
|
||||
|
||||
test("redact two keys", () => {
|
||||
expect(redact({ foo: "bar", bar: "foo" }, "foo", "bar")).to.deep.equal({
|
||||
foo: "<redacted>",
|
||||
bar: "<redacted>",
|
||||
});
|
||||
});
|
||||
|
||||
test("no redaction of unrelated keys", () => {
|
||||
expect(redact({ foo: "bar", bar: "foo" }, "foo")).to.deep.equal({
|
||||
foo: "<redacted>",
|
||||
bar: "foo",
|
||||
});
|
||||
});
|
||||
17
src/utils/redact.ts
Normal file
17
src/utils/redact.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
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)[]): T {
|
||||
return { ...obj, ...Object.fromEntries(keys.map((k) => [k, "<redacted>"])) };
|
||||
}
|
||||
Reference in New Issue
Block a user