Summary
An authorization logic flaw in Discourse's directory items endpoint allows arbitrary user field IDs to be queried without proper visibility checks.
As a result, any user—including anonymous visitors—can retrieve values of private custom user fields for all users in the directory, enabling bulk exfiltration of sensitive profile data under specific configuration conditions.
Affected context
This vulnerability exists in Discourse deployments that:
- Have the user directory enabled (
enable_user_directoryset to true), and - Use custom user fields, some of which are configured as private (not shown on profile or user card), and
- Rely on standard visibility controls (
show_on_profile,show_on_user_card) to protect sensitive user attributes.
It specifically affects the DirectoryItemsController#index endpoint when the user_field_ids query parameter is used to include custom field data in directory listings.
Exploit preconditions
- Attack surface: Public HTTP API endpoint
GET /directory_items.json. - Required access: None; anonymous access to the Discourse site is sufficient if the user directory is enabled.
- Trigger point: Supplying one or more private custom user field IDs via the
user_field_idsquery parameter, e.g.GET /directory_items.json?period=all&user_field_ids=<id>. - Why exploitation is possible: The controller accepts arbitrary
user_field_idswithout enforcing the same authorization / visibility checks that other paths use (e.g.,Guardian#allowed_user_field_ids). Private fields are therefore included in the directory response regardless of their intended visibility settings.
Why this happens
The underlying issue is an authorization logic bypass (CWE-863) in the API responsible for building directory items.
While other parts of the application consistently filter custom user fields through a permission-aware mechanism (such as Guardian#allowed_user_field_ids and the UserField.public_fields scope), the DirectoryItemsController#index action directly trusts the user_field_ids parameter. This creates a divergence between the intended access control policy (private fields hidden from regular users) and the implemented behavior for this endpoint.
Conceptually, the bug stems from:
- Treating client-supplied identifiers (user field IDs) as implicitly authorized, and
- Failing to apply the centralized visibility / authorization checks to every code path that exposes user fields.
This pattern leads to a situation where users can see data they should not be allowed to access, not by bypassing authentication, but by exploiting missing checks in a specific API route.
Potential impact
- Bulk retrieval of private contact data (e.g., phone numbers, addresses) stored in hidden custom user fields.
- Exposure of internal identifiers or classification fields that admins assumed were non-public.
- Privacy violations affecting all users listed in the directory, potentially conflicting with regulatory or organizational policies.
- Enumeration and correlation of sensitive attributes across the entire user base, enabling targeted phishing or social engineering campaigns.
- Loss of user trust due to unintended public disclosure of information configured as private.
General mitigation guidance
Effective mitigation focuses on consistent, centralized authorization checks and defensive handling of client-controlled parameters:
- Enforce field-level authorization: Ensure that every endpoint that exposes user fields uses a common, permission-aware mechanism to determine which fields are visible to the current user. Avoid duplicating or re-implementing visibility logic per controller.
- Treat identifiers as untrusted input: Do not assume that a client-supplied ID (such as
user_field_ids) represents a field the caller is authorized to see. Always filter such IDs against an allowlist derived from the current user's permissions and the field configuration.
- Align API responses with UI visibility rules: If the UI hides certain fields based on settings like
show_on_profileorshow_on_user_card, ensure all relevant API endpoints respect those same rules so there are no "backdoor" data paths.
- Minimize sensitive data in optional fields: Where possible, discourage or avoid storing highly sensitive information in custom fields that may be exposed in aggregate APIs. Prefer dedicated, tightly controlled storage mechanisms for such data.
- Apply least privilege to directory features: Restrict directory access or limit which user attributes may appear in directory responses by default, especially for anonymous or untrusted users.
How teams detect issues like this
Organizations can use a mix of code-centric and behavior-centric strategies to identify similar flaws:
- Static analysis and code review:
- Flag controller actions that accept lists of field IDs, column names, or attribute selectors directly from query parameters.
- Look for API endpoints that serialize user profile or custom field data without passing through centralized authorization helpers.
- Verify that all paths to user field serialization invoke the same visibility-checking components or policies.
- Access control policy verification:
- Define explicit policies for which attributes can be exposed to each user role, and test whether API responses conform to these policies.
- Use automated tests to compare what a user can see via the UI versus what they can retrieve via JSON endpoints.
- Runtime monitoring and logging:
- Log access to endpoints that return lists of users or profile information, including query parameters like
user_field_ids. - Monitor for unusual patterns, such as anonymous or low-privilege clients requesting large sets of custom field data.
- Automated security testing:
- Incorporate API security testing tools or custom scripts into CI/CD to probe for IDOR / authorization bypass issues by varying query parameters and object IDs.

