BigPizzaV3/CodexPlusPlus · error
收到未加密数据包
Error message
收到未加密数据包
What it means
decrypt() expects every incoming WebSocket envelope to be either an explicit {type:"plaintext"} message or an {type:"encrypted", nonce, payload} AES-GCM envelope. Any envelope with a missing/unknown `type` (null, malformed JSON that still parsed, or an unexpected packet type) is rejected with this error to avoid silently treating attacker-controlled or corrupt data as plaintext.
Solutions
- Log the raw envelope before decrypting to see the actual `type` value.
- Update page and relay server together so both speak the same envelope protocol.
- Whitelist known non-encrypted message types (ping, error, ack) before calling decrypt().
- Wrap decrypt() in try/catch in the WebSocket onmessage handler so a bad packet doesn't kill the session.
Example fix
// before
const data = await decrypt(JSON.parse(event.data));
// after
const envelope = JSON.parse(event.data);
if (envelope?.type === "ping") return;
const data = await decrypt(envelope).catch(err => { setStatus(`解密失败:${err.message}`, true); }); Defensive patterns
Strategy: try-catch
Validate before calling
const env = JSON.parse(event.data); if (env && (env.type === "plaintext" || env.type === "encrypted" || env.type === "ping")) { /* safe to decrypt */ } Type guard
function isEnvelope(x) { return !!x && (x.type === "encrypted" || x.type === "plaintext"); } Try / catch
try { const data = await decrypt(envelope); } catch (e) { if (String(e.message).includes("未加密")) { logRawEnvelope(envelope); reconnect(); } else throw e; } Prevention
- Whitelist and short-circuit known non-data frames (ping/pong/ack) before decrypt().
- Keep relay server and page JS protocol versions in lockstep.
- Always wrap onmessage decryption in try/catch so one bad packet doesn't break the socket loop.
When it happens
Trigger: Calling decrypt(envelope) with envelope whose type is neither "plaintext" nor "encrypted": server sends a control/heartbeat frame, protocol version mismatch, JSON that decoded to a non-envelope object, or envelope === null.
Common situations: Relay server and page JS out of sync after an update (new message types like ping/pong not handled); proxy stripped or reshaped the message; race where socket close/error frames are fed into decrypt().
Related errors
- 链接缺少解密密钥。请使用完整的分享链接。
- 当前中转未启用 Chat Completions 协议代理
- 分享数据大小或格式无效
- first message must be registration json
- OpenAI 会话身份仅支持 Responses API
AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19).
Data as JSON: /api/errors/506544f3ccea42d6.
Report an issue: GitHub.
Appendix: source
Thrown at apps/codex-plus-mobile-relay/src/main.rs:810
if (!crypto?.subtle) throw new Error("当前页面不是安全上下文,WebCrypto 不可用");
const raw = new TextEncoder().encode($("key").value);
const digest = await crypto.subtle.digest("SHA-256", raw);
return crypto.subtle.importKey("raw", digest, "AES-GCM", false, ["encrypt", "decrypt"]);
}
async function encrypt(payload) {
if (!crypto?.subtle) {
setStatus("当前浏览器禁用 WebCrypto,已使用兼容模式", true);
return { type: "plaintext", payload };
}
const key = await cryptoKey();
const nonce = crypto.getRandomValues(new Uint8Array(12));
const plain = new TextEncoder().encode(JSON.stringify(payload));
const encrypted = await crypto.subtle.encrypt({ name: "AES-GCM", iv: nonce }, key, plain);
return { type: "encrypted", nonce: b64url(nonce), payload: b64url(encrypted) };
}
async function decrypt(envelope) {
if (envelope?.type === "plaintext") return envelope.payload;
if (!envelope || envelope.type !== "encrypted") throw new Error("收到未加密数据包");
const key = await cryptoKey();
const nonce = b64urlDecode(envelope.nonce);
const data = b64urlDecode(envelope.payload);
const plain = await crypto.subtle.decrypt({ name: "AES-GCM", iv: nonce }, key, data);
return JSON.parse(new TextDecoder().decode(plain));
}
async function connect() {
const room = encodeURIComponent($("room").value.trim());
if (!room || !$("key").value) { setStatus("需要房间 ID 和 Key", true); return; }
const scheme = location.protocol === "https:" ? "wss" : "ws";
if (socket) try { socket.close(); } catch {}
socket = new WebSocket(`${scheme}://${location.host}/client?room=${room}&token=${room}`);
socket.onopen = async () => { setStatus("已连接 relay,正在读取会话..."); try { await loadSessions(); } catch (e) { setStatus(e.message, true); } };
socket.onclose = () => { appServerConnected = false; setStatus("已断开"); };
socket.onerror = () => setStatus("连接错误", true);
socket.onmessage = async (event) => {
try {
const message = JSON.parse(event.data);View on GitHub (pinned to b1ed92e5e4)