0

I'm creating a webpage with a login/logout option, since I'm using spring, and I want it to be secure, I use Csrf as described here.

What works in regular html:

<form method="post">
  <input type="submit" value="Log out" />
  <input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}"/>
</form>

The only difference is I am trying to put it inside a react component, in the render function, it would look like this:

<form method="post">
  <input type="submit" value="Log out" />
  <input type="hidden" thName={_csrf.parameterName} thValue={_csrf.token}/>
</form>

But for some reason that doesn't work.

Another thing might work but I'm not sure if it's good practice or not is:

<form method="post">
  <input type="submit" value="Log out" />
  <input type="hidden" thName={this.getCsrfName} thValue={this.getCsrfToken}/>
</form>

I'm using thyme-leaf by the way.

Is there any way to access the token and the name inside react without it being bad practice? Also if my second try is the correct one, how would I write the getCsrfName() or getCsrfToken() functions?

0 Answers0