Repository navigation
Description
Describe the bug
Closing one authenticated solver WebSocket deauthenticates every other active socket using the same signer address.
At commit 909f69023a939bd7491c42652f449d846dd51a06, AuthService stores authentication in a Set<string> keyed only by signer address. Each successful socket login adds the address, but every socket close calls logout(address), which deletes that shared entry without tracking which connection closed or how many remain.
A solver can legitimately maintain multiple independently authenticated connections with the same signing identity. After any one closes, the remaining sockets fail the server's isLoggedIn(address) check and can no longer submit prices.
To Reproduce
On the audited commit, save the following as tee-apps/sealed-bid-auction/audit-shared-auth.ts:
import { AuctionApiServer } from "./src/api/AuctionApiServer.ts";
import { AuctionService } from "./src/core/AuctionService.ts";
import { AuthService } from "./src/core/AuthService.ts";
import { SolverPriceBook } from "./src/core/SolverPriceBook.ts";
import { generatePrivateKey, signMessage } from "viem/accounts";
const mode = process.argv[2] ?? "red";
const key1 = generatePrivateKey();
const key2 = mode === "control" ? generatePrivateKey() : key1;
const auth = new AuthService();
const book = new SolverPriceBook(auth, 600);
const api = new AuctionApiServer(book, auth, new AuctionService(book));
await api.start(0, false);
const port = (api as any).server.port;
async function connect(username: string, key: `0x${string}`) {
const response = await fetch(
`http://127.0.0.1:${port}/api/currentNonce?username=${username}`,
);
const { nonce } = await response.json() as { nonce: string };
const blob = JSON.stringify({ username, nonce });
const signature = await signMessage({ message: blob, privateKey: key });
const ws = new WebSocket(`ws://127.0.0.1:${port}/`, {
headers: {
"X-Auth-Blob": blob,
"X-Auth-Signature": signature,
},
});
await new Promise<void>((resolve, reject) => {
const timer = setTimeout(() => reject(new Error("open timeout")), 3_000);
ws.onopen = () => { clearTimeout(timer); resolve(); };
ws.onerror = () => { clearTimeout(timer); reject(new Error("open error")); };
});
return ws;
}
const ws1 = await connect("first", key1);
const ws2 = await connect("second", key2);
await new Promise<void>((resolve) => {
ws1.onclose = () => resolve();
ws1.close();
});
const replyPromise = new Promise<string>((resolve) => {
const timer = setTimeout(() => resolve("timeout"), 3_000);
ws2.onmessage = (event) => {
const text = String(event.data);
if (text.startsWith("Prices updated") || text.startsWith("Error:")) {
clearTimeout(timer);
resolve(text);
}
};
});
ws2.send(JSON.stringify([{
direction: "mock",
intervals: [{
range: { min: "0", max: "10" },
rangeUnit: { token: "A", decimal: "0" },
price: "1",
priceUnit: { token: "B", decimal: "0" },
}],
srcTokenAddresses: ["0x0000000000000000000000000000000000000001"],
dstTokenAddresses: ["0x0000000000000000000000000000000000000002"],
settlementReceiverAddress: "ignored",
}]));
const reply = await replyPromise;
ws2.close();
await (api as any).server.stop(true);
const ok = reply.startsWith("Prices updated");
console.log(JSON.stringify({
mode,
sameAddress: mode === "red",
reply,
expected: "second authenticated socket remains usable",
ok,
}));
process.exit(ok ? 0 : 1);Run:
cd tee-apps/sealed-bid-auction
bun audit-shared-auth.ts control
bun audit-shared-auth.ts redObserved result:
# Control: the sockets use different signer addresses
{"mode":"control","sameAddress":false,"reply":"Prices updated: 1 entries for solver ...","expected":"second authenticated socket remains usable","ok":true}
exit 0
# Reproduction: both sockets use the same signer address
{"mode":"red","sameAddress":true,"reply":"Error: not authenticated","expected":"second authenticated socket remains usable","ok":false}
exit 1
The reproduction uses the real AuctionApiServer, AuthService, SolverPriceBook, and loopback WebSocket flow. It generates ephemeral signing keys at runtime and does not contact a blockchain network.
Expected behavior
Closing one connection should release only that connection's authentication. Other active connections for the same signer should remain authenticated until the final connection closes.
A narrow fix could track an active-connection count per normalized signer address: increment on each successful login, decrement on logout, and delete the address only when its count reaches zero. The existing boolean isLoggedIn(address) boundary can remain unchanged.
Example transactions
N/A. The issue is reproduced through an isolated loopback WebSocket server without a wallet transaction or RPC endpoint.
Screenshots
N/A.
Your Setup:
- OS: WSL2 Linux x86_64
- Runtime: Bun 1.3.6
- Repository branch:
canary - Tested commit:
909f69023a939bd7491c42652f449d846dd51a06 - Wallet: N/A; ephemeral test-only signing keys are generated at runtime
Additional context
The reproduction was rerun against the current canary source on 2026-09-19 with bounded three-second socket waits. The distinct-signer control exited 0; the same-signer case returned Error: not authenticated and exited 1.
Duplicate research covered five all-state issue/PR searches plus merged PRs #149 and #164. PR #149 introduced the current address-level authentication set but does not discuss shared-signer multi-connection behavior. Current open PRs #223, #232, #234, #236, and #238 do not modify AuthService or address this lifecycle.
Activity