There was an unexpected error (type=Forbidden, status=403).

Myung A Lee·2023년 6월 7일
0

ERROR

목록 보기
2/2
post-thumbnail

Error

There was an unexpected error (type=Forbidden, status=403).
This generated password is for development use only.
Your security configuration must be updated before running your application in production.

Sring Security는 CSRF 토큰 기능을 가지고 있다. CSRF 공격(Cross Site Request Forgery)은 웹 어플리케이션 취약점 중 하나로 인터넷 사용자(희생자)가 자신의 의지와는 무관하게 공격자가 의도한 행위(수정, 삭제, 등록 등)를 특정 웹사이트에 요청하게 만드는 공격이다. 이것을 방지하기 위해 CSRF 토큰을 발행해 변조된 페이지 인지 확인하게 된다.

현재 나는 암호만 해쉬코드로 변경하는 간단한 작업을 하고 있기 때문에 CSRF 토큰 자체를 생성하지 않았고 당연히 확인하려고 하면 토큰이 없기 때문에 403 권한 에러가 발생한다.

따라서 config에 SecurityConfig.java(@Configuration 등록한 파일)에 등록된 SecurityFilterChain에 csrf기능을 disanle로 바꿔줘야 한다.

기존 코드

@Bean
	public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
		return http.httpBasic().disable().build();
	}

변경 코드

@Bean
	public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
		return http.httpBasic().disable().csrf().disable().build();
	}

0개의 댓글