Collection Permissions
additional roles. Even when there is a reason to grant a permission to more roles, you should only grant it to the roles that need it.
- Read - Admin
- Create - Anyone
- Update - Admin
- Delete - Admin
- Read - Anyone
- Create - Admin
- Update - Admin
- Delete - Admin
- Read - Anyone
- Create - Site member
- Update - Site member author
- Delete - Site member author
if you don't expose that collection functionality in your site.
- If your site does not contain a form for users to create content for a specific collection, you may think you can safely grant the create permission for that collection to be Anyone. That is not the case. Even though there is no form for a user to create content in the collection, a malicious user can still inject data into your collection. However, your collection will be protected if you restrict the create permission to only the Admin role.
- If you have a collection for internal use that you don't use on any of your site's pages, you may think you can safely grant the read permission for that collection to be Anyone. That is not the case. Even though there is no page that uses the collection, a malicious user can still read data from your collection. However, your collection will be protected if you restrict the read permission to only the Admin role.
collection will not work in such cases because doing so exposes the
collection data to all users of with the permitted role all the time. Instead, you can set the collection permissions as appropriate for most situations. When you need a user with a different role to access the collection in some manner, you can perform that operation in Backend code.
wix-data
functions from the backend, you can use a WixDataOptions
object to suppress the permissions check when running the operation. So, even though your collection permissions are restricted to the Admin role, you can perform whatever operation you need, even though the current user's role hasn't been granted permissions for that operation. However, keep in mind that exported backend code can be called by anyone, as described below. Code Visibility
information there. However, keep in mind that even though malicious
visitors can't see what exported backend functions do, they can still see they exist, call them with any arguments they want, and examine their return values.
export function validateButton_click(event) {
wixUsers.currentUser.getEmail()
.then(userEmail => {
if (userEmail === "[email protected]") {
// show secret key
$w("#secretText").text = "43ne5gfou94tfe";
} else {
// show denial message
$w("#secretText").text = "Access denied!";
}
} );
}
- The security check is revealed to all site visitors. Anyone can see that the correct email address is [email protected].
- Sensitive information is revealed to all site visitors. Anyone can see that the secret code is 43ne5gfou94tfe.
// In backend file: secureModule.jsw
import wixUsers from 'wix-users-backend';
import {getSecret} from 'wix-secrets-backend';
export async function secureCheck() {
try {
const currentUser = wixUsers.currentUser;
const currentUserEmail = await currentUser.getEmail();
const secretEmail = await getSecret("secretEmail"); // "[email protected]"
if(currentUserEmail === secretEmail) {
const secretValue = await getSecret("secretValue"); // "43ne5gfou94tfe"
return secretValue;
}
else {
return "Access denied!";
}
}
catch(err) {
console.error(err);
return "An error occured";
}
}
information by doing so since no sensitive information has been revealed. You can call this function safely from Page code as follows:
import {secureCheck} from 'backend/secureModule';
export function secretButton_click(event) {
secureCheck()
.then( (message) => {
$w("#secretText").text = message;
} );
}
information to malicious users.
Storing Personal Information in a Collection
provided that you set the collection permissions so that only the Site member author can read, update, or delete content.