Security in Scripts¶
Scripts can read and change data that the users of a process cannot see. This page explains which scripts can be trusted, where permission checks belong, and how to handle credentials and user input.
Where Scripts Run¶
| Script | Runs on | Can be changed by the user |
|---|---|---|
| Form scripts and form rules | The user's browser | Yes |
| Prework, postwork and other workflow scripts | The server | No |
| Module functions called from a form | The server | The arguments, yes |
A user can change or skip code that runs in the browser, and can send any value to the server. Form rules improve the experience of filling a form, but they do not protect data. Repeat every check that matters in a server script; see Checking Data.
Server Scripts Are Not Limited by User Permissions¶
Server scripts are not limited by the permissions of the user who completed the task. Work item scripts run in a background job of the domain, and services such as $Database and $Documents do not check the user's access rights. A script can read documents and data rows that the user cannot open.
Therefore, a script that returns or copies data on behalf of a user must decide itself whether the user may see that data. Return only what the user needs, not whole records.
Checking the Caller of a Module Function¶
A script module function can be called from a form. The caller chooses the arguments, so treat them as untrusted input. Check the user with $ActiveUser and $Domain.HasPermission before returning or changing data:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | |
$ActiveUser is available when the module function is called on behalf of a user. It is not guaranteed in workflow scripts; use the work item and instance objects there.
Keeping Credentials out of Scripts¶
Scripts are part of the process definition. Everyone who can edit or export the process can read them. Do not write passwords, API keys, tokens or connection strings in scripts.
- For REST services, configure the credentials as an integrated service and refer to it by name; see Calling REST Services.
- For SOAP services, configure the service authentication of the web service.
- For external databases, use a connection defined in the domain settings with
$Database.ExecuteQuery.
Do not write credentials or personal data to console, error messages or process data. Diagnostic output and errors can be read by administrators; see Debugging Scripts.
Using Input Safely¶
Pass values from users or external systems as parameters, not as part of a query or a URL:
- With
$Database.ExecuteQuery, use the parameter syntax of the database, such as@Department, and pass the values in theparametersobject. - With
$Database.Get, put values in theValueof a criterion. - With
$Rest, fill URL segments withAddUrlParameterand query string values withAddQueryParameter, which encode the values.
1 2 3 | |