mercure icon indicating copy to clipboard operation
mercure copied to clipboard

feat: Add token-level control for public updates

Open MHNassar opened this issue 10 months ago • 5 comments

Problem Currently, publishers can choose between private and public updates by setting the private parameter in their request. However, this presents a security risk in frontend applications where a malicious user could modify requests to remove the private flag, potentially exposing sensitive information to unauthorized subscribers.

Solution

This PR introduces a new JWT claim allow_public_updates that can be set to false to restrict tokens to private-only updates. When this claim is present and set to false, any attempt to publish a public update will be rejected with a 401 Unauthorized response, regardless of what's in the request. This provides a server-enforced security boundary that cannot be bypassed by manipulating requests on the client side.

Implementation

Added a new canDispatchPublic function that checks for the presence of the claim Integrated this check into the PublishHandler flow Added tests to verify the functionality Maintains backward compatibility by defaulting to allowing public updates when the claim is not present

Use Case

This feature is particularly useful for collaborative editing applications where you want to ensure that document updates are only visible to authorized collaborators, regardless of how the frontend code behaves.

MHNassar avatar Feb 26 '25 23:02 MHNassar

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Feb 26 '25 23:02 CLAassistant

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 27 '25 23:04 stale[bot]

We need to patch the spec first. Maybe can we find something more idiomatic claim name?

dunglas avatar Apr 28 '25 12:04 dunglas

Maybe private_only to set to true?

dunglas avatar May 13 '25 14:05 dunglas

Yes, it looks good and more descriptive

MHNassar avatar May 13 '25 14:05 MHNassar

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 18 '25 22:07 stale[bot]