Skip to content

Provide debug logs if http-method (POST) rejected with 401 when CSRF (default) enabled #7473

@dopsun

Description

@dopsun

Summary

By default, Spring Boot web application with CSRF enabled, unless doing http.csrf().disabled() explicitly. HTTP POST to RESTful API with basic authentication, will be rejected as 401 UNAUTHORIZED. And server side, no specific logging even after enabling debug output.

Propose to provide debug logs in CsrfFilter after matches in Line 196 failed.

Actual Behavior

Client side receives 401 status code, and server side no specific logs.

Expected Behavior

Server side provides debug log "POST is not supported while CSRF enabled" or alike, to help developers trouble shoot.

Configuration

See Sample.

Version

5.1.6.RELEASE

Sample

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests()
            .anyRequest().authenticated()
            .and().httpBasic();

    // http.csrf().disable();  // comment this line, client POST failed with 401
}

Metadata

Metadata

Labels

in: webAn issue in web modules (web, webmvc)status: invalidAn issue that we don't feel is valid

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions