Skip to content

Commit 0cb114d

Browse files
authored
fix(web): keep install passwords and pairing PINs out of browser logs (#201)
The install and pairing pages dumped complete outgoing WebSocket messages to the console, including Apple ID passwords and pairing PINs. Remove these payload logs without changing what is sent to the server. Add regression coverage asserting both secrets reach their intended WebSocket endpoint but never appear in browser console logging.
1 parent 6e8a69f commit 0cb114d

4 files changed

Lines changed: 51 additions & 4 deletions

File tree

‎web/static/src/page/install/index.vue‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1475,7 +1475,6 @@ export default {
14751475
data = JSON.stringify(data);
14761476
}
14771477
const json = JSON.stringify({ t: t, d: data });
1478-
console.log("--> ", json);
14791478
if (_this.websock.readyState !== WebSocket.OPEN) {
14801479
throw new Error(this.$t("install.toast.connection_closed"));
14811480
}

‎web/static/src/page/pair/index.vue‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ export default {
203203
data = JSON.stringify(data);
204204
}
205205
const json = JSON.stringify({ t: t, d: data });
206-
console.log("--> ", json);
207206
_this.websock.send(json);
208207
},
209208

‎web/static/test/install-websocket.test.mjs‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const script = source.match(/<script>([\s\S]*?)<\/script>/)[1]
1717
function page(upload = async () => [{ name: "app.ipa", path: "/tmp/app.ipa" }], checkAfcService, certificates = async () => ({ data: [] })) {
1818
const sockets = [];
1919
const errors = [];
20+
const consoleMessages = [];
2021
class WebSocket {
2122
static CONNECTING = 0;
2223
static OPEN = 1;
@@ -37,7 +38,7 @@ function page(upload = async () => [{ name: "app.ipa", path: "/tmp/app.ipa" }],
3738
location: { protocol: "http:", host: "localhost" },
3839
api: { upload, checkAfcService, getCertificates: certificates },
3940
toast: { error: (message) => errors.push(message), success() {} },
40-
console: { log() {} },
41+
console: { log: (...args) => consoleMessages.push(args.join(" ")) },
4142
});
4243
vm.runInContext(script, context);
4344
const component = context.component;
@@ -52,11 +53,25 @@ function page(upload = async () => [{ name: "app.ipa", path: "/tmp/app.ipa" }],
5253
$t: (key) => key, validateForm: () => true, startUpdateLog() {}, stopUpdateLog() {},
5354
});
5455
component.mounted?.call(state);
55-
return { state, sockets, errors };
56+
return { state, sockets, errors, consoleMessages };
5657
}
5758

5859
const settle = () => new Promise(setImmediate);
5960

61+
test("does not log Apple ID credentials when submitting an install", async () => {
62+
const { state, sockets, consoleMessages } = page();
63+
const password = "secret-only-for-the-websocket";
64+
state.form.account = "user@example.com";
65+
state.form.password = password;
66+
const pending = state.onSubmit();
67+
sockets[0].open();
68+
await pending;
69+
70+
const sent = JSON.parse(sockets[0].sent[0].d);
71+
assert.equal(sent.password, password);
72+
assert.equal(consoleMessages.some((message) => message.includes(password)), false);
73+
});
74+
6075
test("waits for the install socket to open before sending", async () => {
6176
const { state, sockets } = page();
6277
const pending = state.onSubmit();
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import assert from "node:assert/strict";
2+
import { readFileSync } from "node:fs";
3+
import test from "node:test";
4+
import vm from "node:vm";
5+
6+
const source = readFileSync(new URL("../src/page/pair/index.vue", import.meta.url), "utf8");
7+
const script = source.match(/<script>([\s\S]*?)<\/script>/)?.[1];
8+
assert.ok(script, "pair page script exists");
9+
10+
test("pairing PIN reaches the WebSocket without being logged", () => {
11+
const consoleMessages = [];
12+
const sent = [];
13+
const context = vm.createContext({
14+
console: { log: (...args) => consoleMessages.push(args.join(" ")) },
15+
});
16+
vm.runInContext(
17+
script.replace(/^import .*;\s*$/gm, "").replace("export default", "globalThis.component ="),
18+
context,
19+
);
20+
const state = context.component.data();
21+
for (const [name, method] of Object.entries(context.component.methods)) {
22+
state[name] = method.bind(state);
23+
}
24+
state.websock = { send: (message) => sent.push(JSON.parse(message)) };
25+
26+
const pin = "314159";
27+
state.pin = pin;
28+
state.confirmPin();
29+
30+
assert.equal(sent.length, 1);
31+
assert.equal(sent[0].t, 2);
32+
assert.equal(sent[0].d, pin);
33+
assert.equal(consoleMessages.some((message) => message.includes(pin)), false);
34+
});

0 commit comments

Comments
 (0)
⌂ 换网址