Pairing code rejected with close reason 401 at link registration (official client links fine from same phone/IP)
Expected Behavior
sock.requestPairingCode(jid) returns a code; the user enters it on the phone within seconds and the device links (connection: "open"), or the rejection reason is documented.
Current Behavior
Code is issued normally, but entering it on the phone always shows "Could not link device", and the socket closes with reason 401 (once preceded by 500). Loop:
{"event":"pairing_code","code":"3Z9EYNBG"}
{"event":"closed","reason":500}
{"event":"closed","reason":401} x N (reconnect loop)Steps to Reproduce
- Clean session dir (no stale creds).
node pair-code.js <own-number-e164>(script below, minimal:fetchLatestWaWebVersion+Browsers.windows('Chrome'),requestPairingCode(jid)on firstqrevent).- Phone: Settings → Linked devices → Link a device → "Link with phone number instead" → own number → paste code within ~10s.
Environment
- Baileys:
@whiskeysockets/[email protected](also observed with defaultfetchLatestBaileysVersion+ default browser) - Node: v26.9.0, Linux arm64
- WhatsApp Android, current store version, no VPN
- Residential home IP (not a datacenter range)
- Affected number: personal account, single device link attempt
Control test (why this is not account/IP/expiry)
Minutes after a failed code attempt, on the same phone, account, number, and IP, the official WhatsApp Web client linked successfully via QR (Firefox, same host machine). The rejection is therefore specific to the unofficial-client link registration, not the account, number, network, or code entry.
Ruled out
- Code expiry — entered within 10-30s, fresh process + fresh session dir each attempt
- Wrong number binding — code requested for the same number entered on phone
- Rate-limit cooldown — identical 401 after >23h with zero attempts in between
- Stale creds — session dir wiped before every attempt
- VPN / datacenter IP / outdated app
- Fingerprint — default vs web-version + Chrome browser fingerprint: identical 401
Notes
Related: #1156 (405/428 family on pairing codes). This looks like the same class of failure surfacing as 401, consistent with link-registration attestation checks that official clients satisfy. Full repro report + tool: https://github.com/jamilmina/whatsapp-pair-tool
Would a maintainer confirm whether 401 at link registration is a known attestation enforcement, and whether there is a recommended workaround or release branch to track?
Minimal repro script
import { makeWASocket, useMultiFileAuthState, fetchLatestWaWebVersion, Browsers } from '@whiskeysockets/baileys';
import pino from 'pino';
const phone = process.argv[2];
const { state, saveCreds } = await useMultiFileAuthState('./session-clean');
let version; try { ({ version } = await fetchLatestWaWebVersion()); } catch { version = undefined; }
async function run() {
const sock = makeWASocket({ version, auth: state, browser: Browsers.windows('Chrome'), logger: pino({level:'silent'}) });
sock.ev.on('creds.update', saveCreds);
const jid = `${phone.replace(/\D/g,'')}@s.whatsapp.net`;
sock.ev.on('connection.update', async (u) => {
if (u.pairingCode) console.log(JSON.stringify({event:'pairing_code', code:u.pairingCode}));
if (u.connection === 'open') { console.log('CONNECTED'); process.exit(0); }
if (u.qr) { try { const code = await sock.requestPairingCode(jid); console.log(JSON.stringify({event:'pairing_code', code})); } catch {} }
if (u.connection === 'close') {
console.log(JSON.stringify({event:'closed', reason:u.lastDisconnect?.error?.output?.statusCode ?? 'unknown'}));
setTimeout(run, 2000);
}
});
}
await run();Source: WhiskeySockets/Baileys