Skip to content

Commit 384d21b

Browse files
committed
fix(rabbitmq): strip auth on redirect, require https, and bound the retrieval response
1 parent 7ef374e commit 384d21b

30 files changed

Lines changed: 289 additions & 173 deletions

apps/docs/content/docs/en/integrations/rabbitmq.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Sim talks to RabbitMQ over its **Management HTTP API** — the same interface be
3434
**Before you start**
3535

3636
- The **management plugin must be enabled and reachable** from Sim. It listens on port `15672` by default and is separate from the AMQP port (`5672`). Self-hosted brokers enable it with `rabbitmq-plugins enable rabbitmq_management`; managed providers expose it as a management or console URL.
37+
- The management URL **must use `https`** unless the broker is on a loopback host. Credentials travel on every request as HTTP basic auth, so plain `http` to a remote broker would put them on the wire in the clear — Sim rejects it rather than sending them.
3738
- The user you authenticate as needs the **`management` tag** at minimum, plus read and write permissions on the virtual host you target. Administrative operations require broader permissions.
3839
- Publishing and reading messages over the HTTP API is **convenient but not a high-throughput transport** — RabbitMQ opens a new connection per request. It is well suited to workflow-rate traffic, inspection, and operational automation; a service consuming thousands of messages per second should use an AMQP client instead.
3940
- Queue statistics such as message and consumer counts are **collected on an interval**, so a queue declared moments ago may report them as empty until the broker's next sample.
@@ -83,7 +84,7 @@ Retrieve messages from a RabbitMQ queue. Defaults to requeueing the messages so
8384
| `count` | number | No | Maximum number of messages to retrieve, from 1 to $\{MAX_MESSAGE_COUNT\}. Defaults to 1 |
8485
| `ackmode` | string | No | How retrieved messages are handled: ack_requeue_true \(default, leaves messages in the queue\), ack_requeue_false \(removes them\), reject_requeue_true, or reject_requeue_false |
8586
| `encoding` | string | No | auto \(default\) returns readable text where possible, base64 always returns base64 |
86-
| `truncate` | number | No | Truncate payloads longer than this many bytes. Defaults to $\{DEFAULT_TRUNCATE_BYTES\}; each message reports whether it was truncated |
87+
| `truncate` | number | No | Truncate payloads longer than this many bytes. Defaults to $\{DEFAULT_TRUNCATE_BYTES\} and is capped at $\{MAX_TRUNCATE_BYTES\}, and lowered further when a large count would push the response past the transport limit. Each message reports whether it was truncated |
8788

8889
#### Output
8990

apps/sim/blocks/blocks/rabbitmq.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ export const RabbitmqBlock: BlockConfig<RabbitmqResponse> = {
157157
title: 'Management URL',
158158
type: 'short-input',
159159
placeholder: 'https://rabbit.example.com:15672',
160-
description: 'Base URL of the RabbitMQ management plugin, including scheme and port',
160+
description:
161+
'Base URL of the RabbitMQ management plugin, including scheme and port. Must use https unless the broker is on a loopback host',
161162
required: true,
162163
},
163164
{

apps/sim/tools/generated/tool-metadata.ts

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

apps/sim/tools/rabbitmq/create_binding.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,21 @@ export const rabbitmqCreateBindingTool: ToolConfig<
7878
},
7979

8080
request: {
81-
url: (params) =>
82-
buildManagementUrl(params, [
81+
url: ({ host, vhost, destinationType, exchange, queue }) =>
82+
buildManagementUrl(host, [
8383
'bindings',
84-
resolveVhost(params),
84+
resolveVhost(vhost),
8585
'e',
86-
params.exchange,
87-
params.destinationType === 'exchange' ? 'e' : 'q',
88-
params.queue,
86+
exchange,
87+
destinationType === 'exchange' ? 'e' : 'q',
88+
queue,
8989
]),
9090
method: 'POST',
91-
headers: (params) => buildAuthHeaders(params),
92-
body: (params) => ({
93-
routing_key: params.routingKey ?? '',
94-
arguments: parseJsonObjectParam(params.arguments, 'arguments') ?? {},
91+
headers: ({ username, password }) => buildAuthHeaders(username, password),
92+
stripAuthOnRedirect: true,
93+
body: ({ arguments: bindingArguments, routingKey }) => ({
94+
routing_key: routingKey ?? '',
95+
arguments: parseJsonObjectParam(bindingArguments, 'arguments') ?? {},
9596
}),
9697
},
9798

apps/sim/tools/rabbitmq/create_exchange.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,23 @@ export const rabbitmqCreateExchangeTool: ToolConfig<
6868
},
6969

7070
request: {
71-
url: (params) =>
72-
buildManagementUrl(params, ['exchanges', resolveVhost(params), params.exchange]),
71+
url: ({ host, vhost, exchange }) =>
72+
buildManagementUrl(host, ['exchanges', resolveVhost(vhost), exchange]),
7373
method: 'PUT',
74-
headers: (params) => buildAuthHeaders(params),
75-
body: (params) => ({
76-
type: EXCHANGE_TYPES.has(params.exchangeType ?? '') ? params.exchangeType : 'direct',
77-
durable: params.durable !== false,
78-
auto_delete: params.autoDelete === true,
79-
internal: params.internal === true,
80-
arguments: parseJsonObjectParam(params.arguments, 'arguments') ?? {},
74+
headers: ({ username, password }) => buildAuthHeaders(username, password),
75+
stripAuthOnRedirect: true,
76+
body: ({ arguments: exchangeArguments, autoDelete, durable, exchangeType, internal }) => ({
77+
type: EXCHANGE_TYPES.has(exchangeType ?? '') ? exchangeType : 'direct',
78+
durable: durable !== false,
79+
auto_delete: autoDelete === true,
80+
internal: internal === true,
81+
arguments: parseJsonObjectParam(exchangeArguments, 'arguments') ?? {},
8182
}),
8283
},
8384

8485
transformResponse: async (response, params) => {
8586
const exchangeName = params?.exchange ?? ''
86-
const vhost = params ? resolveVhost(params) : ''
87+
const vhost = params ? resolveVhost(params.vhost) : ''
8788

8889
if (!response.ok) {
8990
const error = await extractErrorMessage(response)

apps/sim/tools/rabbitmq/create_policy.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,22 @@ export const rabbitmqCreatePolicyTool: ToolConfig<
7070
},
7171

7272
request: {
73-
url: (params) =>
74-
buildManagementUrl(params, ['policies', resolveVhost(params), params.policyName]),
73+
url: ({ host, vhost, policyName }) =>
74+
buildManagementUrl(host, ['policies', resolveVhost(vhost), policyName]),
7575
method: 'PUT',
76-
headers: (params) => buildAuthHeaders(params),
77-
body: (params) => ({
78-
pattern: params.pattern,
79-
definition: parseJsonObjectParam(params.definition, 'definition') ?? {},
80-
priority: params.priority ?? 0,
81-
'apply-to': APPLY_TO.has(params.applyTo ?? '') ? params.applyTo : 'queues',
76+
headers: ({ username, password }) => buildAuthHeaders(username, password),
77+
stripAuthOnRedirect: true,
78+
body: ({ applyTo, definition, pattern, priority }) => ({
79+
pattern: pattern,
80+
definition: parseJsonObjectParam(definition, 'definition') ?? {},
81+
priority: priority ?? 0,
82+
'apply-to': APPLY_TO.has(applyTo ?? '') ? applyTo : 'queues',
8283
}),
8384
},
8485

8586
transformResponse: async (response, params) => {
8687
const policyName = params?.policyName ?? ''
87-
const vhost = params ? resolveVhost(params) : ''
88+
const vhost = params ? resolveVhost(params.vhost) : ''
8889

8990
if (!response.ok) {
9091
const error = await extractErrorMessage(response)

apps/sim/tools/rabbitmq/create_queue.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,21 @@ export const rabbitmqCreateQueueTool: ToolConfig<
4949
},
5050

5151
request: {
52-
url: (params) => buildManagementUrl(params, ['queues', resolveVhost(params), params.queue]),
52+
url: ({ host, vhost, queue }) =>
53+
buildManagementUrl(host, ['queues', resolveVhost(vhost), queue]),
5354
method: 'PUT',
54-
headers: (params) => buildAuthHeaders(params),
55-
body: (params) => ({
56-
durable: params.durable !== false,
57-
auto_delete: params.autoDelete === true,
58-
arguments: parseJsonObjectParam(params.arguments, 'arguments') ?? {},
55+
headers: ({ username, password }) => buildAuthHeaders(username, password),
56+
stripAuthOnRedirect: true,
57+
body: ({ arguments: queueArguments, autoDelete, durable }) => ({
58+
durable: durable !== false,
59+
auto_delete: autoDelete === true,
60+
arguments: parseJsonObjectParam(queueArguments, 'arguments') ?? {},
5961
}),
6062
},
6163

6264
transformResponse: async (response, params) => {
6365
const queueName = params?.queue ?? ''
64-
const vhost = params ? resolveVhost(params) : ''
66+
const vhost = params ? resolveVhost(params.vhost) : ''
6567

6668
if (!response.ok) {
6769
const error = await extractErrorMessage(response)

apps/sim/tools/rabbitmq/delete_binding.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,19 @@ export const rabbitmqDeleteBindingTool: ToolConfig<
5151
},
5252

5353
request: {
54-
url: (params) =>
55-
buildManagementUrl(params, [
54+
url: ({ host, vhost, destination, destinationType, exchange, propertiesKey }) =>
55+
buildManagementUrl(host, [
5656
'bindings',
57-
resolveVhost(params),
57+
resolveVhost(vhost),
5858
'e',
59-
params.exchange,
60-
params.destinationType === 'exchange' ? 'e' : 'q',
61-
params.destination,
62-
params.propertiesKey,
59+
exchange,
60+
destinationType === 'exchange' ? 'e' : 'q',
61+
destination,
62+
propertiesKey,
6363
]),
6464
method: 'DELETE',
65-
headers: (params) => buildAuthHeaders(params),
65+
headers: ({ username, password }) => buildAuthHeaders(username, password),
66+
stripAuthOnRedirect: true,
6667
},
6768

6869
transformResponse: async (response, params) => {

apps/sim/tools/rabbitmq/delete_exchange.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,18 @@ export const rabbitmqDeleteExchangeTool: ToolConfig<
3838
},
3939

4040
request: {
41-
url: (params) =>
42-
buildManagementUrl(params, ['exchanges', resolveVhost(params), params.exchange], {
43-
'if-unused': params.ifUnused ? 'true' : undefined,
41+
url: ({ host, vhost, exchange, ifUnused }) =>
42+
buildManagementUrl(host, ['exchanges', resolveVhost(vhost), exchange], {
43+
'if-unused': ifUnused ? 'true' : undefined,
4444
}),
4545
method: 'DELETE',
46-
headers: (params) => buildAuthHeaders(params),
46+
headers: ({ username, password }) => buildAuthHeaders(username, password),
47+
stripAuthOnRedirect: true,
4748
},
4849

4950
transformResponse: async (response, params) => {
5051
const exchangeName = params?.exchange ?? ''
51-
const vhost = params ? resolveVhost(params) : ''
52+
const vhost = params ? resolveVhost(params.vhost) : ''
5253

5354
if (!response.ok) {
5455
const error = await extractErrorMessage(response)

apps/sim/tools/rabbitmq/delete_policy.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,16 @@ export const rabbitmqDeletePolicyTool: ToolConfig<
3232
},
3333

3434
request: {
35-
url: (params) =>
36-
buildManagementUrl(params, ['policies', resolveVhost(params), params.policyName]),
35+
url: ({ host, vhost, policyName }) =>
36+
buildManagementUrl(host, ['policies', resolveVhost(vhost), policyName]),
3737
method: 'DELETE',
38-
headers: (params) => buildAuthHeaders(params),
38+
headers: ({ username, password }) => buildAuthHeaders(username, password),
39+
stripAuthOnRedirect: true,
3940
},
4041

4142
transformResponse: async (response, params) => {
4243
const policyName = params?.policyName ?? ''
43-
const vhost = params ? resolveVhost(params) : ''
44+
const vhost = params ? resolveVhost(params.vhost) : ''
4445

4546
if (!response.ok) {
4647
const error = await extractErrorMessage(response)

0 commit comments

Comments
 (0)