rest-assured/src/main/java/io/restassured/authentication/FormAuthConfig.java
public FormAuthConfig withAutoDetectionOfCsrf() {
        if (hasCsrfFieldName()) {
            throw new IllegalStateException(format("Cannot use auto-detection of CSRF field name since a CSRF field name was already defined as '%s'", csrfFieldName));
        }
        return new FormAuthConfig(formAction, userInputTagName, passwordInputTagName, logDetail, logConfig, csrfFieldName, true, sendCsrfTokenAsFormParam, additionalInputFieldNames);
    }
public FormAuthConfig withAutoDetectionOfCsrf() {
        if (hasCsrfFieldName()) {
            throw new IllegalStateException(format("Cannot use auto-detection of CSRF field name since a CSRF field name was already defined as '%s'", csrfFieldName));
        }
        return new FormAuthConfig(formAction, userInputTagName, passwordInputTagName, logDetail, logConfig, csrfFieldName, true, sendCsrfTokenAsFormParam, additionalInputFieldNames);
    }
public FormAuthConfig withAutoDetectionOfCsrf ( ) { if ( hasCsrfFieldName ( ) ) { throw new IllegalStateException ( format ( "Cannot use auto-detection of CSRF field name since a CSRF field name was already defined as '%s'" , csrfFieldName ) ) ; } return new FormAuthConfig ( formAction , userInputTagName , passwordInputTagName , logDetail , logConfig , csrfFieldName , true , sendCsrfTokenAsFormParam , additionalInputFieldNames ) ; }
Enable Cross-site request forgery (csrf) support when using form authentication by automatically trying to find the name and value of the csrf input field.
For example if the login page looks like this:
<pre>
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Login&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form action=&quot;j_spring_security_check_with_csrf&quot; method=&quot;POST&quot;&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;User:&amp;nbsp;&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;j_username&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Password:&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;password&quot; name=&quot;j_password&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td colspan=&quot;2&quot;&gt;&lt;input name=&quot;submit&quot; type=&quot;submit&quot;/&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;input type=&quot;hidden&quot; name=&quot;_csrf&quot; value=&quot;8adf2ea1-b246-40aa-8e13-a85fb7914341&quot;/&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
The csrf field name is called <code>_csrf</code> and REST Assured will autodetect its name since the field name is the only <code>hidden</code> field on this page.
If auto-detection fails you can consider using {@link #withCsrfFieldName(String)}.
<p/>
<b>Important:</b> When enabling csrf support then REST Assured <b>must always</b> make an additional request to the server in order to
be able to include in the csrf value which will slow down the tests.

@return A new FormAuthConfig instance.
@see #withCsrfFieldName(String)
Enable Cross - site request forgery ( csrf ) support when using form authentication by automatically trying to find the name and value of the csrf input field . For example if the login page looks like this : <pre > &lt ; html&gt ; &lt ; head&gt ; &lt ; title&gt ; Login&lt ; / title&gt ; &lt ; / head&gt ; &lt ; body&gt ; &lt ; form action = &quot ; j_spring_security_check_with_csrf&quot ; method = &quot ; POST&quot ; &gt ; &lt ; table&gt ; &lt ; tr&gt ; &lt ; td&gt ; User : &amp ; nbsp ; &lt ; / td&gt ; &lt ; td&gt ; &lt ; input type = &quot ; text&quot ; name = &quot ; j_username&quot ; &gt ; &lt ; / td&gt ; &lt ; / tr&gt ; &lt ; tr&gt ; &lt ; td&gt ; Password : &lt ; / td&gt ; &lt ; td&gt ; &lt ; input type = &quot ; password&quot ; name = &quot ; j_password&quot ; &gt ; &lt ; / td&gt ; &lt ; / tr&gt ; &lt ; tr&gt ; &lt ; td colspan = &quot ; 2&quot ; &gt ; &lt ; input name = &quot ; submit&quot ; type = &quot ; submit&quot ; / &gt ; &lt ; / td&gt ; &lt ; / tr&gt ; &lt ; / table&gt ; &lt ; input type = &quot ; hidden&quot ; name = &quot ; _csrf&quot ; value = &quot ; 8adf2ea1 - b246 - 40aa - 8e13 - a85fb7914341&quot ; / &gt ; &lt ; / form&gt ; &lt ; / body&gt ; &lt ; / html&gt ; < / pre > The csrf field name is called <code > _csrf< / code > and REST Assured will autodetect its name since the field name is the only <code > hidden< / code > field on this page . If auto - detection fails you can consider using { @link #withCsrfFieldName ( String ) } . <p / > <b > Important : < / b > When enabling csrf support then REST Assured <b > must always< / b > make an additional request to the server in order to be able to include in the csrf value which will slow down the tests .