Comments (5)
Possible solutions
- Handle the binary value in
props_as_map/1
, but I'm not sure what would be appropriate to return, if anything - Catch the function clause error and send the bad request
- Handle up the stack somewhere?
from rabbitmq-management.
@davydog187 can we start with how to reproduce this instead of what the solution should be?
from rabbitmq-management.
Background
We accidentally released a regression in our application code that double encoded JSON before sending it to the rabbitmq management API. This manifested itself as a 500 in our rabbitmq deployment, rather than a client error, as I would expect.
How to reproduce
Let's start by double-encoding some JSON, then send it to the queue creation API.
iex(2)> %{auto_delete: false, durable: true} |> Jason.encode!() |> Jason.encode!()
"\"{\\\"auto_delete\\\":false,\\\"durable\\\":true}\""
PUT /api/queues/my-vhost/my-queue
"\"{\\\"auto_delete\\\":false,\\\"durable\\\":true}\""
This will decode as binary rather than a map since it is still valid JSON.
from rabbitmq-management.
@davydog187 the value you have used is successfully parsed by our JSON parser (JSX):
rabbit_json:decode(<<"\"{\\\"auto_delete\\\":false,\\\"durable\\\":true}\"">>).
% => <<"{\"auto_delete\":false,\"durable\":true}">>
Same result with https://jsonlint.com. I'm afraid this double encoded JSON is still valid JSON as far as the parser goes (a string literal).
if we consider this to be only possible when we get incorrectly encoded JSON, this should be handled when the value is decoded (parsed):
with_vhost_and_props(Fun, ReqData, Context) ->
case vhost(ReqData) of
not_found ->
not_found(rabbit_data_coercion:to_binary("vhost_not_found"),
ReqData, Context);
VHost ->
{ok, Body, ReqData1} = read_complete_body(ReqData),
case decode(Body) of
{ok, Props} ->
try
Fun(VHost, props_as_map(Props), ReqData1)
catch {error, Error} ->
bad_request(Error, ReqData1, Context)
end;
{error, Reason} ->
bad_request(rabbit_mgmt_format:escape_html_tags(Reason),
ReqData1, Context)
end
end.
from rabbitmq-management.
The decoding function has a clause that indicates that the input is not considered to be valid JSON:
decode(<<"">>) ->
{ok, #{}};
decode(Body) ->
try
{ok, rabbit_json:decode(Body)}
catch error:_ -> {error, not_json}
end.
I am reluctant to base this on a type check but a new clause can be added there.
from rabbitmq-management.
Related Issues (20)
- unable to grant a user permissions to a custom topic via web ui HOT 2
- Add headers to HTTP logging HOT 2
- jquery 3.4.1 has security vulnerabilities and needs to be upgraded
- Make it possible to configure stats_event_max_backlog via new style format HOT 1
- Respect management.load_definitions for backwards compatibility
- UI fails to load with a ReferenceError: login_route is not defined in Firefox after an upgrade HOT 4
- Make it possible to configure rabbitmq_management.management_db_cache_multiplier via rabbitmq.conf
- When upgrading to a new version, JS is cached HOT 1
- Get Message can't deal unicode HOT 4
- Failed healthchecks return HTTP 200 status HOT 4
- UI: Policy definition with empty value not sent to API HOT 2
- Expose key individual health checks via HTTP API
- The 'unack' value is negative number HOT 2
- Disable HTTP OPTIONS method or make it configurable HOT 2
- unexpected_trailing_sections,{{'v1_0.delivery_annotations', HOT 1
- Missing confirm metrics from /api/exchanges/?message_stats HOT 2
- API request to aliveness-test when message-ttl is 0 results in a 500 HOT 1
- TLS listener port is reported incorrectly by `rabbitmq-diagnostics listeners` HOT 8
- Documentation: Example of Apache Reverse Proxy config does not work with 2.4+ HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rabbitmq-management.