Skip to content
Access control Disclosed report Intermediate

Gaining access to private topics using quoting feature

The onebox preview feature that renders a small preview of a linked Discourse topic checked access using a user-supplied source topic id. By supplying the victim topic's own id as that parameter, the category comparison always matched, letting a low-privileged user read staff-only topic content.

mishre Follow

Originally disclosed on HackerOne

Bounty$256 High View original
  • Triaged in 3 days
  • Fixed in 9 days
  • Paid in 9 days
  • Disclosed after 40 days

Description

Some topics have limited access to certain groups and users, and while there exists a validation for access on this topic, it can be bypassed by abusing a vulnerability in the "onebox" quoting feature. When pasting a link in a reply, if this link happens to be a link to another topic on Discourse a small preview is shown which includes the topic content or the post content where the link is pointing to. Also there are some protections in place to make sure that the user can view the linked content, the said protections can be bypassed by adding a query string parameter to the link containing the value

?source_topic_id={victim-topic-id}

Steps to reproduce

  1. Login as an administrator to Discourse and create a topic which can only be viewed by the staff.
  2. Copy the topic's id from the topic's page. the topic id can be found by browsing the topic and then copying the number in the end of the url (http://localhost:4000/t/{topic-name}/{topic-id})
  3. Login with a non-admin user.
  4. Go to any topic you have access to, and type in the following reply:
http://localhost:80/t/blablabla/?source_topic_id=29

please note that the port should 80 or 443 even if the url of your local installation is a different (probably some software bug) 5. Wait for the preview to load and see that you can see topic's content.

Root cause

The following piece of code determines if the logged-in user is capable of viewing the post/topic :

        def can_see_post?(post, source_topic)
          return false if post.nil? || post.hidden || post.trashed? || post.topic.nil?
          Guardian.new.can_see_post?(post) || same_category?(post.topic.category, source_topic)
        end

        def can_see_topic?(topic, source_topic)
          return false if topic.nil? || topic.trashed? || topic.private_message?
          Guardian.new.can_see_topic?(topic) || same_category?(topic.category, source_topic)
        end

as can be seen here: https://github.com/discourse/discourse/blob/master/lib/onebox/engine/discourse_local_onebox.rb#L113

However, the source_topic parameter is controlled directly by user input:

source_topic_id = @url[/[&?]source_topic_id=(\d+)/, 1].to_i

as can be seen here: https://github.com/discourse/discourse/blob/master/lib/onebox/engine/discourse_local_onebox.rb#L47 So if we pass in the same topic id as the one we are trying to view, basically the function same_category will always return true, effectively bypassing any protection in place.

Impact

An attacker will be able to access all private topics and posts on Discourse.

The original report as published on HackerOne, by mishre. 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. 5 min read.

Context

Discourse is a forum platform where topics can be restricted to particular groups and users. A topic that is visible only to staff is a normal configuration, and the platform is expected to enforce that restriction everywhere the topic's content can surface.

One of the places content surfaces is the "onebox" feature. When a user pastes a link into a reply, Discourse fetches the target and renders a small preview inline, including the title and a snippet of the linked content. For links that point to another topic on the same Discourse instance, a local onebox engine handles the preview. Because that preview can display content from a private topic, the engine contains checks intended to confirm that the user composing the reply is allowed to see the linked post or topic.

The report describes a bypass of those checks: by appending a query string parameter to the pasted link, a user without access to a private topic can make the onebox render that topic's content.

Setup

The reproduction uses a local Discourse installation reachable at http://localhost:4000, with two accounts:

  1. An administrator account, used to create a staff-only topic.
  2. A non-admin user account, used to attempt the bypass.

No special tooling is required beyond a browser and the ability to post a reply. The only precondition is that the victim topic exists and is restricted to a group the attacker does not belong to.

Finding it

The researcher's observation is that the local onebox engine does perform an access check before rendering a preview, but that the check depends on a value taken from the URL the user supplies. The engine reads a source_topic_id parameter out of the pasted link and uses it to decide whether the linked content is in the same category as the topic the reply is being written in. If the two are considered to be in the same category, the preview is rendered even when the normal permission check fails.

Since the parameter is attacker-controlled, the attacker can set it to the id of the very topic they are trying to read. The comparison then succeeds trivially, and the preview is produced.

Exploitation

Step 1: create a restricted topic

Logged in as an administrator, create a topic that only staff can view. This is the victim content.

Step 2: obtain the topic id

Browse to the topic and read the id from the end of its URL. The report gives the URL shape as:

Text
http://localhost:4000/t/{topic-name}/{topic-id}

In the reproduction the victim topic id is 29.

Step 3: switch to a low-privileged account

Log in as a non-admin user who has no access to the staff-only topic.

Step 4: post a reply containing a crafted link

Go to any topic the low-privileged user can access and type the following into a reply:

Text
http://localhost:80/t/blablabla/?source_topic_id=29

The parameter value 29 is the victim topic id, which is what defeats the same-category comparison. The report notes that the port in the URL should be 80 or 443 even when the local installation runs on a different port, which the researcher attributes to a software bug.

Step 5: observe the preview

Wait for the onebox preview to load. The preview displays the content of the private topic, which the low-privileged user should not be able to read.

Root cause

The access decision lives in lib/onebox/engine/discourse_local_onebox.rb. Two methods gate the preview:

Text
        def can_see_post?(post, source_topic)
          return false if post.nil? || post.hidden || post.trashed? || post.topic.nil?
          Guardian.new.can_see_post?(post) || same_category?(post.topic.category, source_topic)
        end

        def can_see_topic?(topic, source_topic)
          return false if topic.nil? || topic.trashed? || topic.private_message?
          Guardian.new.can_see_topic?(topic) || same_category?(topic.category, source_topic)
        end

Each method first rejects obviously invalid targets, then accepts the target if either the normal guardian check passes or the target is in the same category as source_topic. The source_topic value is not derived from the reply's actual topic; it is parsed straight out of the user-supplied URL:

Text
source_topic_id = @url[/[&?]source_topic_id=(\d+)/, 1].to_i

Because the attacker chooses source_topic_id, they can set it to the id of the private topic itself. The same_category? comparison then compares the private topic's category with itself and always returns true, so the guardian check is never needed. The intended protection is present but its input is under attacker control, which makes the fallback branch a complete bypass rather than a convenience for legitimate same-category links.

Impact

An attacker can access all private topics and posts on a Discourse instance through the onebox preview, without belonging to the groups those topics are restricted to. The report states this broadly.

Fix

The report does not describe a patch. The defect is that source_topic_id is trusted from the URL; the value should be derived from the topic the reply is actually being composed in, or the same-category fallback should be removed, so that the guardian check is the only path to rendering a preview.

Variants to test

  1. Other onebox engines that render local content and take a context parameter from the URL. A positive result is a preview of content the requesting account cannot open directly.
  2. Parameters other than source_topic_id that influence access decisions in preview or embed code. A positive result is a private title or snippet appearing in the rendered preview.
  3. Category-scoped previews where the attacker can choose a category id belonging to a category they can see. A positive result is a preview of a topic in a category they cannot see.
  4. Private messages referenced through the same preview path. A positive result is message content rendered to a user who is not a participant.

Hunting notes

This class of bug tends to hide in features that fetch and render content on behalf of the user: link previews, embeds, oEmbed handlers and unfurlers. The signal during recon is a preview feature that shows a snippet of a linked resource, combined with any URL parameter that appears to carry context such as a source topic, category or channel id. If the parameter is echoed into an authorisation comparison, try setting it to the id of the resource you are trying to read.

The report demonstrates impact with a minimal, reproducible sequence: a staff-only topic, a low-privileged account, one crafted link and a visible preview of the private content. That direct demonstration of unauthorised content disclosure is what makes the issue concrete for the program.

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. 10 min read.

What happened, in plain words

Discourse is a piece of software for running online discussion forums. Think of it as the engine behind a message board: people create accounts, start topics (threads), and reply to them. Some topics can be locked down so that only certain groups of people can read them, for example only the forum's staff. The whole point of that setting is that nobody outside the allowed group should ever see the content.

One of Discourse's conveniences is called "onebox". When you paste a web address (a link) into a reply, Discourse fetches whatever is at the other end and shows a small preview card inline, with the title and a bit of the content. It saves people a click. If the link points to another topic on the same forum, a special internal component, the "local onebox engine", builds that preview.

Because a preview can show content, the engine is supposed to check whether the person writing the reply is allowed to see the linked topic. The researcher found that this check can be fooled. By adding an extra piece of text to the end of the pasted link, a user who is not allowed to read a private topic can make the preview show that topic's content anyway. The report rates this as high severity and it was disclosed in March 2018.

Context

On a forum, a topic that only staff can see is a completely normal setup. The platform is expected to enforce that restriction everywhere the topic's content could appear, not just on the topic's own page.

One of the places content appears is the onebox preview. When you paste a link into a reply, Discourse fetches the target and renders a small preview inline, including the title and a snippet of the linked content. For links that point to another topic on the same Discourse instance, a local onebox engine handles the preview. Because that preview can display content from a private topic, the engine contains checks intended to confirm that the user composing the reply is allowed to see the linked post or topic.

The report describes a bypass of those checks: by appending a query string parameter to the pasted link, a user without access to a private topic can make the onebox render that topic's content.

A "query string parameter" is the part of a web address that comes after a question mark, made of name and value pairs. In ?source_topic_id=29, the parameter name is source_topic_id and its value is 29. Websites use these to pass extra information along with a request, and a user can usually type them by hand.

Setup

The reproduction uses a local Discourse installation reachable at http://localhost:4000, with two accounts:

  1. An administrator account, used to create a staff-only topic.
  2. A non-admin user account, used to attempt the bypass.

"Localhost" means the same computer you are working on; the number after the colon is the port, the door through which the web server listens. So this is a test forum running on the researcher's own machine, not a live public site.

No special tooling is required beyond a browser and the ability to post a reply. The only precondition is that the victim topic exists and is restricted to a group the attacker does not belong to.

Finding it

The researcher's observation is that the local onebox engine does perform an access check before rendering a preview, but that the check depends on a value taken from the URL the user supplies. The engine reads a source_topic_id parameter out of the pasted link and uses it to decide whether the linked content is in the same category as the topic the reply is being written in. If the two are considered to be in the same category, the preview is rendered even when the normal permission check fails.

A "category" on a forum is a grouping of topics, like folders. The engine's logic says, roughly: show the preview if the user is allowed to see the target, or if the target sits in the same category as the topic being replied to.

Since the parameter is attacker-controlled, the attacker can set it to the id of the very topic they are trying to read. The comparison then succeeds trivially, and the preview is produced. In other words, the engine asks "is this topic in the same category as itself?", which is always yes.

Exploitation

Step 1: create a restricted topic

Logged in as an administrator, create a topic that only staff can view. This is the victim content.

Step 2: obtain the topic id

Browse to the topic and read the id from the end of its URL. The report gives the URL shape as:

Text
http://localhost:4000/t/{topic-name}/{topic-id}

Every topic has one, and it appears at the end of its address.

In the reproduction the victim topic id is 29.

Step 3: switch to a low-privileged account

Log in as a non-admin user who has no access to the staff-only topic. This is the attacker's position: an ordinary forum member.

Step 4: post a reply containing a crafted link

Go to any topic the low-privileged user can access and type the following into a reply:

Text
http://localhost:80/t/blablabla/?source_topic_id=29

The parameter value 29 is the victim topic id, which is what defeats the same-category comparison. The report notes that the port in the URL should be 80 or 443 even when the local installation runs on a different port, which the researcher attributes to a software bug.

Reading the link piece by piece: http:// is the scheme, localhost is the machine, :80 is the port (80 is the default for plain web traffic, 443 for encrypted traffic), /t/blablabla/ is a path that does not need to be meaningful, and ?source_topic_id=29 is the parameter that carries the victim's topic id.

Step 5: observe the preview

Wait for the onebox preview to load. The preview displays the content of the private topic, which the low-privileged user should not be able to read.

Root cause

The access decision lives in lib/onebox/engine/discourse_local_onebox.rb. That is a file in Discourse's source code; the path tells you it belongs to the local onebox engine. Two methods gate the preview:

Text
        def can_see_post?(post, source_topic)
          return false if post.nil? || post.hidden || post.trashed? || post.topic.nil?
          Guardian.new.can_see_post?(post) || same_category?(post.topic.category, source_topic)
        end

        def can_see_topic?(topic, source_topic)
          return false if topic.nil? || topic.trashed? || topic.private_message?
          Guardian.new.can_see_topic?(topic) || same_category?(topic.category, source_topic)
        end

A "method" is a named block of code that does one job. can_see_post? decides about a single post, can_see_topic? about a whole topic. Line by line:

  • def can_see_post?(post, source_topic) starts the method; it receives the post being linked and the source topic taken from the URL.
  • return false if post.nil? || post.hidden || post.trashed? || post.topic.nil? says no if the post does not exist (nil means nothing), is hidden, is in the bin (trashed?), or has no parent topic. These are sanity checks.
  • Guardian.new.can_see_post?(post) || same_category?(post.topic.category, source_topic) is the real decision. Guardian is Discourse's permission checker. If it says yes, the preview is allowed. The || means "or": if the guardian says no, the code still allows the preview when same_category? says the post's category matches the source topic's category.
  • end closes the method.
  • def can_see_topic?(topic, source_topic) starts the topic version, with the same shape.
  • return false if topic.nil? || topic.trashed? || topic.private_message? rejects a missing topic, a trashed one, or a private message.
  • Guardian.new.can_see_topic?(topic) || same_category?(topic.category, source_topic) again allows the preview if the guardian agrees, or if the categories match.
  • end closes it.

Each method first rejects obviously invalid targets, then accepts the target if either the normal guardian check passes or the target is in the same category as source_topic. The source_topic value is not derived from the reply's actual topic; it is parsed straight out of the user-supplied URL:

Text
source_topic_id = @url[/[&?]source_topic_id=(\d+)/, 1].to_i

This single line is where the flaw lives. @url is the link the user pasted. The part in slashes is a pattern that searches the link for source_topic_id= preceded by ? or &, captures the digits after it, and to_i turns those digits into a number. So the value used in the permission comparison comes from whatever the attacker typed, not from the reply's real context.

Because the attacker chooses source_topic_id, they can set it to the id of the private topic itself. The same_category? comparison then compares the private topic's category with itself and always returns true, so the guardian check is never needed. The intended protection is present but its input is under attacker control, which makes the fallback branch a complete bypass rather than a convenience for legitimate same-category links.

Impact

An attacker can access all private topics and posts on a Discourse instance through the onebox preview, without belonging to the groups those topics are restricted to. The report states this broadly.

Fix

The report does not describe a patch. The defect is that source_topic_id is trusted from the URL; the value should be derived from the topic the reply is actually being composed in, or the same-category fallback should be removed, so that the guardian check is the only path to rendering a preview.

Variants to test

  1. Other onebox engines that render local content and take a context parameter from the URL. A positive result is a preview of content the requesting account cannot open directly.
  2. Parameters other than source_topic_id that influence access decisions in preview or embed code. A positive result is a private title or snippet appearing in the rendered preview.
  3. Category-scoped previews where the attacker can choose a category id belonging to a category they can see. A positive result is a preview of a topic in a category they cannot see.
  4. Private messages referenced through the same preview path. A positive result is message content rendered to a user who is not a participant.

Hunting notes

This class of bug tends to hide in features that fetch and render content on behalf of the user: link previews, embeds, oEmbed handlers and unfurlers. An "embed" is when one site pulls another site's content into its own page; an "unfurler" is the general name for the code that turns a bare link into a rich preview card. The signal during recon is a preview feature that shows a snippet of a linked resource, combined with any URL parameter that appears to carry context such as a source topic, category or channel id. If the parameter is echoed into an authorisation comparison, try setting it to the id of the resource you are trying to read.

The report demonstrates impact with a minimal, reproducible sequence: a staff-only topic, a low-privileged account, one crafted link and a visible preview of the private content. That direct demonstration of unauthorised content disclosure is what makes the issue concrete for the program.

Glossary

  • Discourse: forum software used to run online discussion boards, where users create topics and post replies.
  • Topic: a discussion thread on a forum, made up of an opening post and replies.
  • Post: a single message inside a topic.
  • Category: a grouping of topics on a forum, similar to a folder.
  • Staff-only topic: a topic restricted so that only administrators and moderators can read it.
  • Onebox: Discourse's feature that turns a pasted link into an inline preview card showing the linked content.
  • Local onebox engine: the part of Discourse that builds previews for links pointing to topics on the same forum.
  • Query string parameter: a name and value pair after the ? in a URL, such as source_topic_id=29, used to pass extra information with a request.
  • URL: the address of a resource on the web, such as http://localhost:4000/t/name/29.
  • Port: the numbered door a web server listens on; 80 is the default for plain HTTP and 443 for HTTPS.
  • localhost: the name for the computer you are currently using, used when running software locally.
  • Topic id: the number Discourse uses internally to identify a topic, visible at the end of its URL.
  • Method: a named block of code that performs one task.
  • nil: a programming value meaning "nothing" or "no object".
  • Guardian: Discourse's internal permission checker that decides whether a user may see a post or topic.
  • Access control: the rules that decide who is allowed to see or do what.
  • Bypass: getting past a security check without satisfying it.
  • Attacker-controlled input: any value a user can supply, such as a URL parameter, which must never be trusted for security decisions.
  • Root cause: the underlying coding mistake that makes the vulnerability possible.
  • Impact: the real-world harm an attacker can cause by exploiting the flaw.
  • Severity: a rating of how serious a vulnerability is; this report is rated high.
  • Embed: pulling content from one site into another site's page.
  • Unfurler: code that fetches a link and builds a preview card from it.
  • oEmbed: a standard way for sites to provide embeddable previews of their content.
  • Recon: the research phase where you look for features and parameters worth testing.
  • Variant: a related version of the same bug worth checking elsewhere.

More by mishre

View all

9 more disclosed reports, 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.