1

How can we have persistent token value(or Form Key) during the valid session in struts2? When <s:token/> is in the forms, after submitting the form, the token's value gets changed. It causes this problem that users can not open 2 browser tab and work with them(Only one tab is active due to the tokens' unique value per form). how can I solve this with struts2 and have durable token value per session(Not per form)?

I think overriding the interceptor can solve the problem, but i wanna to consider other options

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Amin Sh
  • 2,684
  • 2
  • 27
  • 42

2 Answers2

0

Don't use token at all

If you require something per session, use the session itself. Token is meant to prevent request replay attacks. So just having one per session doesn't make sense.

coding_idiot
  • 13,526
  • 10
  • 65
  • 116
  • Please look at this link: http://stackoverflow.com/questions/10466241/new-csrf-token-per-request-or-not and this chat: http://chat.stackoverflow.com/rooms/10926/discussion-between-laurencei-and-zerkms ---- Conclusion: Per session tokens, prevent CSRF attacks. Isn't it right? – Amin Sh Oct 03 '13 at 12:57
  • @AminSh This answer doesn't have a sense, may be it has a sense of humor but no more. OWASP has nothing against the per session token, but this token can't be used to prevent double submission. – Roman C Oct 03 '13 at 16:49
  • The token per session can be an prevent CSRF and it must be something other than session id http://security.stackexchange.com/questions/22903/why-refresh-csrf-token-per-form-request , although the struts token seems to be best for double submission it can also be used as CSRF preventer. – Alireza Fattahi Jan 25 '16 at 07:30
0

I also had same problem, in my functionality there is preview which opens in new tab. User can preview multiple times, so it was throwing a token exception. I got one code as at start of function I wrote :

String downloadTokenName = TokenHelper.getTokenName();
String downloadToken = TokenHelper.getToken(downloadTokenName);

At end of function in finally I reassign token value as :

TokenHelper.setSessionToken(downloadTokenName, downloadToken);

It solved my problem.

Paul Roub
  • 36,322
  • 27
  • 84
  • 93
Komal
  • 200
  • 2
  • 5