Require a token on a web trigger
Make a web trigger reject every call that doesn't carry your secret token, so only the systems you trust can run it.
Applies to: Script Master for Jira and Script Master for Confluence Β· Cloud
A web trigger URL has no sign-in. Anyone who has the URL can call it, and the script runs as the app. The check below is the only thing that stops an unknown caller, so put it at the very start of the script.
Before you beginβ
- Jira or Confluence permission: Jira admin (the Administer Jira global permission) or Confluence admin.
- App permission: an active Script Master license.
- A long random token, for example one from a password generator. The calling system sends it with every call.
Add the token checkβ
-
On the Web Triggers tab, open the web trigger.
-
At the top of Backend JavaScript, add the check below and replace
<your-access-token>with your token.const EXPECTED_TOKEN = 'Bearer <your-access-token>';if (request.headers['authorization']?.[0] !== EXPECTED_TOKEN) {console.warn('Call rejected: missing or wrong token');return { statusCode: 401, statusText: 'Unauthorized' };}// The rest of your script runs only for callers with the tokenreturn { statusCode: 200, statusText: 'OK' }; -
Select Save.
-
In the calling system, send the header
Authorization: Bearer <your-access-token>with every call.
Result: Calls without the header, or with another token, get 401 and change nothing.
A rejected call counts as a successful call in History, so at most one every 5 minutes is kept. To keep every rejected call, log it with console.error instead: calls that log an error are always recorded, and show in red. See Run history.
| Placeholder | Description |
|---|---|
<your-access-token> | Your secret token. Use the same value in the script and in the caller. |
Header names reach the script in lowercase, so read request.headers['authorization'], whatever case the caller uses.
Test the checkβ
- Under the editor, turn on Test this Web Trigger.
- Select Generate request example > GET request example, then select Test. Result shows
401. - Add
"authorization": ["Bearer <your-access-token>"]toheadersin the request, then select Test again. Result shows200.
Keep the token safeβ
- The token is part of the script. Everyone who can open Script Master on your site can read it, and so can anyone who sees an export of the web trigger.
- Don't put the token in the URL. URLs end up in logs and browser history more often than headers do.
- To change the token, update the script and the calling system together. Calls with the old token fail as soon as you save.
Relatedβ
- Web trigger request and response: headers, query parameters and status codes.
- Call a web trigger from Jira Automation: send the token from a Jira Automation flow.
- Show Jira work item statuses on a Confluence page: a token check for calls from a browser.