About Elevation

Some Velo API methods are restricted based on the identities and roles authorized to call them. Elevation is a mechanism that allows you to call these restricted methods even when the calling identity lacks the necessary authorization. This process creates a temporary elevated version of a method by calling the elevate() method, enabling you to bypass the usual authentication checks that might otherwise restrict access.

For example:

Copy

Methods that may require elevation

Methods can be restricted based on user identity or roles and permissions.

Identity restriction example

An example of a method restricted by identity is the assignBadge() method. This method can only be called by Wix users because site members should not be able to assign badges to themselves.

This means that assignBadge() can only be called without elevation in a published dashboard page, where the caller will have the Wix user identity. In all other cases, if you need to call assignBadge(), you must elevate it first.

For example, you might want to automatically assign a badge to users who take some specific action or reach a predetermined milestone. Since the site members who earned the badge don’t have rights to assign it to themselves. In this case, you need to use elevation to assign the badge.

Roles and permissions restriction example

An example of a method restricted based on roles and permissions is the confirmBooking() method. This method can only be called by admin members with an administrative bookings role because users creating bookings should not be allowed to confirm their own bookings.

If you need to call confirmBooking() on behalf of a user who does not have an administrative Bookings role, you must elevate it first.

For example, you might have a specific service that you want to confirm automatically once a site visitor books it. Since site visitors who book the service don’t have permissions to confirm it themselves, you need to use elevation to confirm the booking.

Security considerations

Due to potential security risks, you can only elevate methods in backend code. While elevation offers flexibility, it’s crucial to consider how and when elevation is triggered. Web methods and HTTP functions are particularly vulnerable if not properly managed due to their open nature. Elevation in backend events or code only triggered from scheduled jobs presents less risk but should still be handled cautiously.

Example

To demonstrate how to properly handle elevation, consider a site that rewards frequent visitors with a special badge. To do so, the code needs to track recent member visits and call assignBadge() using elevation when a member has visited frequently enough. (Note that the code samples below have been simplified, removing error handling and other non-essential code.)

Here is an example of an insecure approach to writing this code:

Copy

There are several problems with the assignBadge() web method used in this approach:

  • It is open for anyone to call, even though only members can receive badges.
  • It doesn’t ensure that it will only assign the intended badge.
  • It doesn’t ensure that it will assign a badge to the currently logged in member.

Because of these issues, this method can be called by a malicious user to assign any badge to any member.

You can easily remedy these issues by being more careful about where you use elevation and how you expose it to be called.

For example:

Copy

In this approach, the following makes sure the elevation is not exploited by malicious users:

  • The ID of the badge to assign is specified in backend code.
  • The current user ID is retrieved in backend code.
  • The web method used to trigger the badge assignment has permissions set so it can only be called by site members.

See more

Did this help?