Comments on private articles are read without authorization, and the permissions should be blocked at the list level or the detail level.
Private post comments were accessed without authorization, mostly because permissions were only checked at the detail level and not at the list level. This is mentioned in the official security fix for WordPress 7.1.3: Unauthenticated disclosure of comments on private & unpublished posts. The lesson is that both the list and detail levels need to be blocked, and附属 resources are most likely to be overlooked.
Why are附属 resources most likely to be overlooked?
An article set to private, the main object itself is protected by permissions, and direct access will be blocked. But comments, attachments, and messages, which are 'hung below the main object', often have their own independent query entry points. Developers are easily default to protecting the subsets when adding permissions to the main object, but in fact, the visibility of the main object does not automatically pass down.
The attack path becomes simple: don't touch the article, directly request its comment list. If the comment interface only filters by 'article ID' and doesn't include 'whether the current user has the right to read this article' in the conditions, the comments of private articles can be read anonymously.附属 resources are the most often ignored layer in this model.
What kind of hole will be left if the permission is judged only at the detail level?
Judging the permission only at the detail level is equivalent to assuming that all visits will first fall on the detail page. But in the world of interfaces, list, search, batch, and embedded endpoints are all entry points that bypass the detail. As long as there is an unjudged entry, the privacy of the main object leaks through that crack.
| Interception location | Consequences of using alone |
|---|---|
| Judged only in the detail layer | Entries such as list, search can be directly called, bypassing details to obtain subset data |
| Judged only in the list layer | If the detail page uses a separate query, it may still return content that should not be given |
| Judged at both layers and defaults to reject | No matter which entry is used, the permission must be confirmed again |
The stable approach is to set the default behavior to reject: if there is no explicit authorization, return empty instead of default allowing and relying on individual pages for补救。Default rejection for unauthorized access issues is more stable than relying on individual interface supplement whitelist。“
What conditions should the list layer filtering take
The key to the list interface is to add the status of the main object and the current user's permissions to the query conditions, rather than just retrieve the subset by parent ID. Specifically, it needs to include three types of conditions: the visibility status of the main object to which this附属 resource belongs, the access rights of the current caller to the main object, and the publication status of the resource itself. All three conditions must be met before returning.
In other words, the comment list cannot simply ask 'What comments are under this article', but also ask 'Is this user qualified to read this article? If so, continue listing.' Integrating permission judgment into the query filtering rather than retrieving all and then reducing it in the display layer can prevent data from being seen during transmission or caching.
How do in-site permission groups and document states coordinate?
AnQiCMS uses two orthogonal lines to define the visible range: one is user management and VIP grouping, setting different access permissions for different user groups, determining what content the caller can see when the interface returns; the other is the document status - formal document, draft, pending publication, and recycling station. Drafts can have a preview tag for preview, but it does not mean it is open to everyone; deleting a formal document is moving it to the recycling station rather than a physical deletion, and the visible range also follows the status.
The two lines need to cooperate: when the interface returns subsets such as comments and attachments, first check whether the document status is visible to the public in the formal state, and then see if the user group of the caller has the right to access. If one condition is missing, it will not return. The identity layer is guarded by the built-in JWT authentication, first confirming who the caller is, and then discussing whether they can read. In this way, the main object and the附属 resources go through the same set of judgments, and there will be no misalignment such as 'the article is blocked, and the comments are missed.'
Common questions
What is the reason why comments are leaked separately when the article is already private?\nAnswer: Comments have an independent query entry, the visibility of the main object does not automatically pass to the subset, and the list interface needs to rejudge the permissions.
Is it enough to add permission judgment only on the detail page?\nAnswer: Not enough. The list, search, and batch entry can bypass the detail, and both levels should be judged and defaults should be rejected.
What should be paid attention to when setting the draft preview link?\nAnswer: The preview range should be defined separately, don't let it become readable to everyone, and the user group permissions should still take effect.
What is the most stable way to converge unauthorized access?\nAnswer: Write the status and the object's permission together into the query filter, and use default deny instead of a whitelist for each one.