Skip to content
Access control Disclosed report Beginner

Any authenticated user can download full list of users, including email

The CSV export controller's permission check only verified that the requested entity type was not "admin", but no such entity type exists, so the check effectively only limited how often a user could export. Any authenticated user could therefore export sensitive data such as the full user list with email addresses and admin status.

arkadiyt Follow

Originally disclosed on HackerOne

Bounty$256 Medium 5.0 View original
  • Fixed in 3 days
  • Paid in 3 days
  • Disclosed after 33 days

The ExportCsvController allows users to export different types of entities, if one has guardian access: https://github.com/discourse/discourse/blob/master/app/controllers/export_csv_controller.rb#L6

However, the guardian check only checks that the entity type is not "admin": https://github.com/discourse/discourse/blob/master/lib/guardian.rb#L296

But the entity type "admin" does not exist anyway, so the check boils down to whether or not a user has made an export on that day. This means that once a day a user can export any of the entity types in the ExportCsvFile job: https://github.com/discourse/discourse/blob/master/app/jobs/regular/export_csv_file.rb

Including: A full user list export (names, email addresses, admin status, etc) Staff actions etc

As a proof of concept I was able to download a full list of users on https://try.discourse.org

Attachments

Screen_Shot_2017-05-14_at_6.04.04_PM.png
Screen_Shot_2017-05-14_at_6.04.04_PM.png From the original on HackerOne
Screen_Shot_2017-05-14_at_6.06.00_PM.png
Screen_Shot_2017-05-14_at_6.06.00_PM.png

The original report as published on HackerOne, by arkadiyt. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 4 min read.

Context

Discourse is a forum platform, and this report concerns its CSV export feature. The ExportCsvController lets a user export different types of entities as CSV files, provided the user has guardian access. The guardian is the object that answers permission questions about a user, and the controller is supposed to consult it before starting an export.

The export itself is performed by a background job, ExportCsvFile, which knows how to produce several kinds of export: a full user list (names, email addresses, admin status and so on), staff actions, and other entity types.

Setup

The report does not describe any special account, role or tooling. The precondition is simply an authenticated user on a Discourse instance. The proof of concept was run against the public instance at https://try.discourse.org.

Finding it

The researcher read the controller and the guardian check side by side. The controller's entry point is here:

Text
https://github.com/discourse/discourse/blob/master/app/controllers/export_csv_controller.rb#L6

The guardian check that gates it is here:

Text
https://github.com/discourse/discourse/blob/master/lib/guardian.rb#L296

The check only verifies that the requested entity type is not "admin". That looked wrong for two reasons. First, the entity type "admin" does not exist at all, so the comparison can never reject a legitimate export type. Second, the check says nothing about who the user is or what they are allowed to export. The researcher concluded that the check effectively boils down to whether the user has already made an export on that day, which is a rate limit rather than an authorisation decision.

Exploitation

Step 1: Identify the reachable export types

The researcher enumerated the entity types handled by the ExportCsvFile job:

Text
https://github.com/discourse/discourse/blob/master/app/jobs/regular/export_csv_file.rb

Because the guardian check only excludes the non-existent "admin" type, every type listed in that job is reachable by any authenticated user, once per day. The report names two of them explicitly:

  1. A full user list export (names, email addresses, admin status, etc).
  2. Staff actions.

Step 2: Request the user list export

As a proof of concept, the researcher downloaded a full list of users on https://try.discourse.org. The report does not include the request itself, only the result.

Step 3: Inspect the downloaded file

The downloaded export contained the full user list. The two screenshots below show the result.

Screen_Shot_2017-05-14_at_6.04.04_PM.png
Screen_Shot_2017-05-14_at_6.04.04_PM.png From the original on HackerOne
Screen_Shot_2017-05-14_at_6.06.00_PM.png
Screen_Shot_2017-05-14_at_6.06.00_PM.png

Root cause

The authorisation check in the guardian is ineffective: it tests the entity type against a value ("admin") that is not a valid export type, so it never denies a real request. The only remaining constraint is the once-per-day limit on exports, which is a throttling control, not an access control. The controller therefore starts the ExportCsvFile job for any authenticated user, and the job happily produces exports that contain data the user should not see, such as other users' email addresses and admin status.

Impact

Any authenticated user can, once per day, export the full user list of the instance, including names, email addresses and admin status, as well as staff actions and the other entity types supported by the job. On the public instance https://try.discourse.org the researcher downloaded a full list of users. The report does not discuss what an attacker would do with the data beyond obtaining it.

Fix

The report does not describe the fix that was applied.

Variants to test

  1. Enumerate every entity type accepted by the export job and request each one as a low-privileged user. A positive result is a CSV containing data the user's role should not grant access to.
  2. Look for other controllers that delegate permission decisions to a guardian method whose comparison value is not a real enum member. A positive result is a method that always returns true for valid inputs.
  3. Check whether the once-per-day limit can be bypassed by changing the entity type, a second account, or a different parameter, which would turn a throttled leak into a repeatable one.
  4. Test the same export endpoint on instances with different plugin or version configurations, since the set of entity types handled by the job may differ.

Hunting notes

This kind of bug hides in authorisation helpers that compare a user-supplied value against a constant that is never actually used, so the check is dead code. During recon, look for export, report and download endpoints that accept a type or format parameter, and read the guardian or policy method that gates them. If the method only excludes a value that does not appear in the job or model that handles the request, the gate is likely ineffective. The researcher downloaded a full list of users on https://try.discourse.org.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 9 min read.

What happened, in plain words

Discourse is a piece of software for running online discussion forums. There is also a public instance at https://try.discourse.org.

Discourse has a feature that lets a user download data as a CSV file. CSV stands for comma-separated values: it is a plain text file where each line is a row of a table and commas separate the columns. You can open one in a spreadsheet program and it looks like a table.

A normal user should not be able to download the full list of everyone registered on the forum, because that list contains personal data such as names and email addresses. The report shows that, because of a mistake in how the permission check was written, any logged-in user could download that full list anyway, once per day.

The researcher found this by reading the source code of Discourse, which is published openly on GitHub. GitHub is a website where software projects keep their code and its history. Reading code is a legitimate way to look for security problems: you look for places where the program decides whether someone is allowed to do something, and you check whether that decision is made correctly.

The pieces involved

Before the details, three terms from the code need explaining.

A controller is the part of a web application that receives an incoming request, such as a click on a download button, and decides what to do with it. In Discourse the relevant one is called ExportCsvController, and its job is to handle requests to export data as CSV.

A guardian is Discourse's name for a helper object that answers questions of the form "is this user allowed to do this?". Other parts of the program ask the guardian before acting. The guardian is where permission rules live, so it is exactly the kind of place a security researcher reads first.

A background job is work that the server does out of sight of the user, after the request has been accepted. Instead of making the visitor wait while a large file is built, the server notes the task and a worker process does it later. In Discourse the export work is done by a job called ExportCsvFile, and that job knows how to produce several different kinds of export: a full user list (names, email addresses, admin status and so on), staff actions, and other entity types. An entity type here simply means "which kind of data do you want exported".

Setup

Nothing special was needed to try this. The only precondition is an authenticated user on a Discourse instance: that is, someone who has created an account and is logged in. The proof of concept was run against the public instance at https://try.discourse.org.

Finding it

The researcher read the controller and the guardian check next to each other. The controller's entry point, the line where it starts handling an export request, is here:

Text
https://github.com/discourse/discourse/blob/master/app/controllers/export_csv_controller.rb#L6

This is a link to a file in the Discourse source code on GitHub. The #L6 at the end means "line 6 of that file", so opening the link takes you straight to the relevant line. Reading it tells you what the controller does when an export is requested.

The guardian check that gates it, meaning the check that is supposed to decide whether the request may proceed, is here:

Text
https://github.com/discourse/discourse/blob/master/lib/guardian.rb#L296

Again this is a link to a specific line, line 296 of the guardian file. This is the line the researcher wanted to inspect, because it is the one that answers "may this user export this type of data?".

The check only verifies that the requested entity type is not "admin". That looked wrong for two reasons.

First, the entity type "admin" does not exist at all. The export job has a fixed list of types it can produce, and "admin" is not one of them. So the comparison can never reject a legitimate export type: whatever real type a user asks for, it is by definition not "admin", and the check passes.

Second, the check says nothing about who the user is or what they are allowed to export. It does not ask "is this person a moderator?" or "is this person allowed to see other people's email addresses?". It only compares a string.

The researcher concluded that once a day a user can export any of the entity types in the job. That is a rate limit, a rule about how often something may be done, rather than an authorisation decision, a rule about who may do it. The two are very different: a rate limit slows an attacker down, but it does not stop them.

Exploitation

Step 1: Identify the reachable export types

The researcher listed the entity types handled by the ExportCsvFile job:

Text
https://github.com/discourse/discourse/blob/master/app/jobs/regular/export_csv_file.rb

This link points to the job's source file. Reading it shows every kind of export the job can produce, because each type has to be handled somewhere in that file. The point of this step is to know what is on the menu: if the permission check lets everything through, then everything in this file is available to any logged-in user.

Because the guardian check only excludes the non-existent "admin" type, every type listed in that job is reachable by any authenticated user, once per day. The report names two of them explicitly:

  1. A full user list export (names, email addresses, admin status, etc).
  2. Staff actions.

"Staff actions" is one of the export types the report names. Both of these contain information that an ordinary member of a forum should not be able to pull down.

Step 2: Request the user list export

As a proof of concept, the researcher downloaded a full list of users on https://try.discourse.org. A proof of concept is a small, safe demonstration that a problem is real rather than theoretical: instead of only arguing from the code, you show the actual result. The report does not include the request itself, only the result.

Step 3: Inspect the downloaded file

The downloaded export contained the full user list. The two screenshots below show the result.

Screen_Shot_2017-05-14_at_6.04.04_PM.png
Screen_Shot_2017-05-14_at_6.04.04_PM.png From the original on HackerOne
Screen_Shot_2017-05-14_at_6.06.00_PM.png
Screen_Shot_2017-05-14_at_6.06.00_PM.png

Root cause

The root cause is the underlying reason the bug exists, as opposed to its symptoms. Here, the authorisation check in the guardian is ineffective: it tests the entity type against a value ("admin") that is not a valid export type, so it never denies a real request. A check that can never say no is not a check at all.

The only remaining constraint is the once-per-day limit on exports. That is a throttling control, something that limits speed or frequency, not an access control, something that limits who may do what. The controller therefore starts the ExportCsvFile job for any authenticated user, and the job happily produces exports that contain data the user should not see, such as other users' email addresses and admin status.

Impact

Impact means what harm the bug can actually cause. Any authenticated user can, once per day, export the full user list of the instance, including names, email addresses and admin status, as well as staff actions and the other entity types supported by the job. On the public instance https://try.discourse.org the researcher downloaded a full list of users. The report does not discuss what an attacker would do with the data beyond obtaining it.

Fix

The report does not describe the fix that was applied. In everyday terms, the guard at the door should check your name against the guest list, not check whether the word on your ticket is a word that never appears on any ticket.

Variants to test

Once you understand a bug like this, it is worth asking where else the same pattern might appear. These are starting points for further testing, not things the report says were found.

  1. Enumerate every entity type accepted by the export job and request each one as a low-privileged user. A positive result is a CSV containing data the user's role should not grant access to.
  2. Look for other controllers that delegate permission decisions to a guardian method whose comparison value is not a real enum member. An enum is a fixed list of allowed values; if the code compares against something outside that list, the comparison is dead. A positive result is a method that always returns true for valid inputs.
  3. Check whether the once-per-day limit can be bypassed by changing the entity type, a second account, or a different parameter, which would turn a throttled leak into a repeatable one.
  4. Test the same export endpoint on instances with different plugin or version configurations, since the set of entity types handled by the job may differ. A plugin is an add-on that changes what the software can do, and different versions of the software may have different lists.

Hunting notes

This kind of bug hides in authorisation helpers that compare a user-supplied value against a constant that is never actually used, so the check is dead code. Dead code is code that runs but can never change the outcome.

During recon, short for reconnaissance, the phase where you look around before attacking anything, look for export, report and download endpoints that accept a type or format parameter. An endpoint is a specific address on a server that does something when you send a request to it. Read the guardian or policy method that gates them. If the method only excludes a value that does not appear in the job or model that handles the request, the gate is likely ineffective.

The researcher downloaded a full list of users on https://try.discourse.org. That is the difference between saying "this code looks wrong" and saying "here is the file I downloaded".

Glossary

  • API: a defined way for one program to talk to another over the network, usually by sending requests to specific addresses and getting structured answers back.
  • Authenticated user: someone who has proved who they are, normally by logging in with an account.
  • Authorisation: the decision about whether a particular user is allowed to perform a particular action.
  • Background job: work the server performs out of sight after accepting a request, rather than during the request itself.
  • Controller: the part of a web application that receives a request and decides how to handle it.
  • CSV: comma-separated values, a plain text file format where each line is a row and commas separate the columns.
  • Dead code: code that runs but can never change the outcome, for example a comparison that is always true.
  • Endpoint: a specific address on a server that performs an action when a request is sent to it.
  • Entity type: in this report, which kind of data an export should contain, such as the user list or staff actions.
  • Enum: a fixed list of allowed values that a field may take.
  • Guardian: Discourse's helper object that answers permission questions about a user.
  • Impact: the harm a vulnerability can actually cause.
  • Plugin: an add-on that changes or extends what a piece of software can do.
  • Proof of concept: a small, safe demonstration that a problem is real rather than theoretical.
  • Rate limit: a rule limiting how often an action may be performed, as opposed to who may perform it.
  • Recon: reconnaissance, the phase of looking around a target before testing it.
  • Root cause: the underlying reason a bug exists, as opposed to its visible symptoms.
  • Staff actions: the recorded actions taken by moderators and administrators, such as edits, deletions and suspensions.
  • Throttling: deliberately slowing or limiting how frequently something can happen.
  • Vulnerability class: a category of security bug, here a privacy violation, meaning data is exposed to someone who should not see it.

More by arkadiyt

View all

1 more disclosed report, best first.

More from Discourse

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.