8000 feat: Add token-level control for public updates by MHNassar · Pull Request #1017 · dunglas/mercure · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: Add token-level control for public updates #1017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

MHNassar
Copy link

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.

Introduce allow_public_updates claim to restrict tokens to private-only
updates when set to false, preventing client-side request manipulation.
@CLAassistant
Copy link
CLAassistant commented Feb 26, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
stale bot commented Apr 27, 2025

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 stale bot added the wontfix This will not be worked on label Apr 27, 2025
@dunglas dunglas removed the wontfix This will not be worked on label Apr 28, 2025
@dunglas
Copy link
Owner
dunglas commented Apr 28, 2025

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

@dunglas
Copy link
Owner
dunglas commented May 13, 2025

Maybe private_only to set to true?

@MHNassar
Copy link
Author

Yes, it looks good and more descriptive

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0