Append XSRF token to a Script Fragment Link?

John Hastings-Kimball December 16, 2020

Our dev team is tired of copying data from a parent item to a sub-task every time they create one. I have introduced a new transiton that creates the subtask and copies a set of data elements in the process. This works well but, of course, the transiton button appears in the available transition list. The team would like this transition to appear in the More actions dropdown - specifically, it should replace the normal Create sub-task option in the operations-subtask area.

I have added a scriptrunner fragment that removes the native create sub-task option and a second one to introduce the new option. This custom web item fragment has a "Do What" option of "Navigate to Link". The Link is set to 

/secure/WorkflowUIDispatcher.jspa?id=${issue.id}&action=901

where 901 is the new transition that I'd like run. 

This all works well with the exception of a missing XSRF security token error. If i append &atl_token=mysecuritytoken into the link, the operation works perfectly. 

Is there any option to append the user's token in the above link string?  

2 answers

1 accepted

0 votes
Answer accepted
John Hastings-Kimball December 17, 2020

The support desk at Adaptavist give me this link to the Form Token Handling article on Atlassian's site.

Appending &atl_token=${atl_token} to my above link worked perfectly and was exactly what i was looking for. 

One caveat if you are calling transitions this way is that any screens you may have will not appear in a modal but rather full screen. A minor difference that isnt a deal breaker for me. 

0 votes
Radek Dostál
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 16, 2020

XSRF token is typically in cookies as part of http requests - haven't had a need to generate one myself with Java API yet but this looks promising https://docs.atlassian.com/software/jira/docs/api/8.5.8/com/atlassian/jira/security/xsrf/SimpleXsrfTokenGenerator.html

Radek Dostál
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 16, 2020

What comes to mind is..

 - either generate a new token and use it (if it will be valid and work)

 - get the user's xsrf token from the HttpRequest when they open the issue view

 - disable the xsrf token check altogether (via a header passed in the http request)

Suggest an answer

Log in or Sign up to answer