Clean Code that Works.

http://blog.idm.fr/2010/09/spring-security-redirecting-to-faviconico.html

만약 스프링 시큐리티를 사용하여 웹사이트 전체를 로그인 폼과 함께 보안적용할 경우, 로그인 인증하는 중에 사용자가 "/favicon.ico"로 리다이렉트 되는 이슈가 발생할 수도 있다. 스프링 시큐리티 문서에서는 아래와 같이 설명되어 있다.

ExceptionTranslationFilter는 사용자가 요청한 원본 요청을 캐쉬 하고 있다. 사용자가 인증 되었을 경우, request handler는 캐쉬된 요청을으로 부터 원본 url 을 얻어서 그쪽으로 redirect한다. 원본 요청은 재 작성 되고 대안으로 사용된다.
이 이슈는 브라우저 캐쉬가 비어있고, 사용자가 이쪽으로 들어 온다면 다음과 같은 일이 발생한다.
  • 사용자가 "/" URL을 요청하고, 이 URL은 캐쉬 된다
  • 브라우저는 "/favicon.ico"에 요청을 한다. 이 URL은 인승시 redirect될 새로운 URL이 된다.
  • 사용자가 로그인 요청을 통해 로그인 한 후 "/favicon.ico"로 리다이렉트 된다.
이것을 수정 하기 위해서는 "/favicon.ico"를 인증을 안하는 resource로 변경을 해야 한다.

<intercept-url pattern="/favicon.ico" access="ROLE_ANONYMOUS" />



If you are using Spring Security to secure an entire website with form login, you might encounter an issue where users are redirected to "/favicon.ico" upon athentication. A note in the Spring Security documentation explains this:

The ExceptionTranslationFilter caches the original request a user makes. When the user authenticates, the request handler makes use of this cached request to obtain the original URL and redirect to it. The original request is then rebuilt and used as an alternative.
The issue is, when the browser cache is empty and a user comes in, here is what happens:
  • the user requests URL "/". This URL is cached.
  • the browser makes a requests to "/favicon.ico". This URL becomes the new URL where to redirect to upon authentication.
  • the user posts the login form and is redirected to "/favicon.ico".
To fix this, you need to set "/favicon.ico" as being a non-secured resources:

<intercept-url pattern="/favicon.ico" access="ROLE_ANONYMOUS" />