Use client parameters with caution. Please make sure to read the Security consideration section below.
Usage
Client parameters are defined when instantiating the PowerSync database, within the options of PowerSync’sconnect()
method:
request.parameters
(alongside the already supported request.user_id
).
In this example, only ‘posts’ from the user’s current page are synced:
Security consideration
An important consideration with client parameters is that a client can pass any value, and sync data accordingly. Hence, client parameters should always be treated with care, and should not be used for access control purposes. Where permissions are required, use token parameters (request.jwt()
) instead, or use token parameters in combination with client parameters.
The following examples show secure vs. insecure ways of using client and token parameters:
Secure (using a token parameter only):
Insecure (using a client parameter only):
Secure (using a token parameter combined with a client parameter):
Warning on potentially dangerous queries
Based on the above security consideration, the PowerSync Dashboard will warn developers when client parameters are being used in sync rules in an insecure way (i.e. where the query does not also include a parameter fromrequest.jwt()
).
The below sync rules will display the warning:
Potentially dangerous query based on parameters set by the client. The client can send any value for these parameters so it’s not a good place to do authorization.
accept_potentially_dangerous_queries: true
in the bucket definition: